Steppingstones R7 v100
Steppingstones R7 v100
Steppingstones R7 v100
1/192
2/192
Reference Documentation .................................................................................. 11 2 3 4 Abbreviations................................................................................................. 12 Definitions ..................................................................................................... 14 Release 6: the standard evolution ................................................................ 15
4.1.1 4.1.2 4.1.3 4.1.4 UICC UICC UICC UICC physical/logical characteristics......................................................................................................15 OTA ............................................................................................................................................16 Toolkit.........................................................................................................................................17 JAVA Card ...................................................................................................................................18
5 6
6.4
6.5
Mapped files...................................................................................................... 27
NFC Device Identification ................................................................................. 29 Overview of Mobile NFC .................................................................................... 29 Data Transmission Rates .................................................................................. 30 Communication between NFC-terminal and UICC ............................................ 30 SWP Stack Overview ......................................................................................... 31 Structure of a SWP Frame and of an HCI packet .............................................. 33 HCI Message Fragmentation............................................................................. 33 HCI Hosts, Gates and Pipes............................................................................ 34 Indication of SWP support ............................................................................. 35
UICC....................................................................................................................................................35 Mobile..................................................................................................................................................35
7.11.1 7.11.2
3/192
7.12
7.12.1 7.12.2 7.12.3 7.12.4
7.13
7.13.1 7.13.2
7.14
8.4
8.4.1 Summary of Java Card Language Limitations ........................................................................................42 Summary of Java Card VM Constraints.................................................................................................................42
8.5
8.5.1 8.5.2
8.6
8.7
8.8
Managing Memory and Objects......................................................................... 51 Java Card Technology Compatibility Kit......................................................... 51 Overview of Versions needed for basic interoperability................................. 52
8.9.1
4/192
9.6
10
10.1 10.2
10.2.1 10.2.2
10.3 10.4
10.4.1 Envelope management .........................................................................................................................60 10.4.2 EnvelopeResponseHandler management for the event EVENT_FORMATTED_SMS_PP_ENV ....................61 10.4.3 EnvelopeResponseHandler management for the events EVENT_CALL_CONTROL_BY_NAA or EVENT_MO_SHORT_MESSAGE_ CONTROL_BY_NAA_SMS_PP_ENV ......................................................................61 10.4.4 Details .................................................................................................................................................62
10.5
10.5.1 10.5.2 10.5.3
10.6
10.6.1 10.6.2 10.6.3
10.7
10.7.1 10.7.2 10.7.3 10.7.4
10.8
10.8.1 10.8.2 10.8.3 10.8.4 10.8.5 10.8.6
Short Messages and their handling with the USIM API ................................. 78
Single SMS-PP......................................................................................................................................78 Concatenated SMS PP ..........................................................................................................................79 TLV structure for Update Record...........................................................................................................81 Methods to retrieve UDL.......................................................................................................................82 Structure of Short Message Cell Broadcast ............................................................................................82 Concatenated SMS-CB ..........................................................................................................................83
10.9 10.10
11
11.1 11.2
11.2.1 11.2.2 11.2.3 11.2.4 11.2.5
An example of phonebook content ................................................................ 87 Global and local phonebooks ......................................................................... 87 Link with the GSM SIM phonebook ................................................................ 88 Phonebook synchronization ........................................................................... 88
12
12.1
5/192
Secret codes................................................................................................... 89 Mapping of CHV1............................................................................................ 89 Mapping of CHV2............................................................................................ 89 Mapping of Local PINs ................................................................................... 90 Mapping of administrative PINs..................................................................... 90 Access condition ............................................................................................ 90 Access to file system for 2G / 3G applets....................................................... 90
Definitions ...........................................................................................................................................90 Accessibility table .................................................................................................................................90
12.9 12.10
12.10.1 12.10.2 12.10.3 12.10.4
Activation of SIM and USIM applications ....................................................... 90 SIM and USIM APIs interworking ............................................................... 90
Terminal Profile ................................................................................................................................91 Triggering and Registration...............................................................................................................91 System handlers and proactive commands ........................................................................................91 Behaviours of SIM API used in a 3G mode.........................................................................................91
12.11
13
14
14.1
Toolkit Application Reference ........................................................................ 98 Counter Field and Management ..................................................................... 98 PCNTR ............................................................................................................ 99 Secured Data.................................................................................................. 99
15
15.1
15.2
15.2.1 15.2.2 15.2.3 15.2.4 15.2.5
16
16.1 16.2
16.2.1 16.2.2 16.2.3 16.2.4 16.2.5 16.2.6 16.2.7
6/192
16.3
16.3.1 16.3.2 16.3.3 16.3.4
Java-API for BIP .......................................................................................... 123 Reliability and Security using BIP ................................................................ 125 Applet Developer tips................................................................................... 125
17
SCWS......................................................................................................... 126
Scope ........................................................................................................... 126 Overview of SCWS........................................................................................ 126 Specifications............................................................................................... 126 Architecture of the SCWS solution ............................................................... 127 SCWS Local Content..................................................................................... 128 SCWS HTTP commands for local content ..................................................... 128 Access Control and Security ......................................................................... 129 HTTP Authentication .................................................................................... 129 Access Control Policy Enforcer ..................................................................... 129 SCWS remote Administration .................................................................... 130
SCWS administrative commands .....................................................................................................130 The Full Administration Protocol......................................................................................................130 The lightweight protocol .................................................................................................................131
17.1 17.2 17.3 17.4 17.5 17.6 17.7 17.8 17.9 17.10
17.10.1 17.10.2 17.10.3
17.11
17.11.1 17.11.2
18
18.5
18.5.1 18.5.2 18.5.3 18.5.4 18.5.5 18.5.6
18.6
18.6.1 18.6.2 18.6.3
19
7/192
19.1
19.1.1 19.1.2 19.1.3 19.1.4 19.1.5
03 Unable to process script chaining (e.g. no resources to store chaining context)............................................................................................................. 149 20 Remote File Management Architecture .................................................... 149
Remote File Access for UICC ........................................................................ 149 Remote File Access for ADF.......................................................................... 149 RFM and expanded format using script chaining TLV command.................. 150 Remote File Application Parameters ............................................................ 150 Remote File Management AID and TAR ....................................................... 151
RFM Commands .................................................................................................................................151
21
21.1
21.2
21.2.1 21.2.2 21.2.3 21.2.4 21.2.5 21.2.6 21.2.7
22
22.1
22.2
22.2.1 22.2.2 22.2.3
22.3
22.3.1 22.3.2
A
A.1 A.2 A.3 A.4 A.5 A.6 A.7
8/192
UICC API package version management ........................................................ 171 USIM API for Java Cards package version management ................................ 172 Java Card API Packages ............................................................................... 172
B
B.1 B.2 B.3 B.4 B.5 B.6
C
C.1 C.2 C.3
D
D.1 D.2 D.3
9/192
Figure index
Figure 1 - The UICC Architecture.................................................................................................................................21 Figure 2 - NFC system architecture..............................................................................................................................30 Figure 3 - The JCRE Context........................................................................................................................................40 Figure 4 - Converting a CAP file...................................................................................................................................43 Figure 5 - RMI communications ...................................................................................................................................49 Figure 6 - File system structure in the UICC .................................................................................................................74 Figure 7 - The USAT Envelope Handler content in case of Formatted SM ......................................................................81 Figure 8 - USAT Envelope Handler in case of formatted CB ..........................................................................................83 Figure 9 - USAT Envelope Handler in case of unformatted CB.......................................................................................84 Figure 10 - A good example of a Phonebook................................................................................................................87 Figure 11 - Formatted SM structure ...........................................................................................................................101 Figure 12 - The UDH in an SM-PP ..............................................................................................................................101 Figure 13 - The UDH structure ..................................................................................................................................103 Figure 14 - Response packet structure.......................................................................................................................105 Figure 15 - The User Data Header in C-SM PP............................................................................................................106 Figure 16 - The CBS pages ........................................................................................................................................114 Figure 17 - CBS structure with Secured Data .............................................................................................................116 Figure 18 - BIP Protocol stack ...................................................................................................................................117 Figure 19 - Overview CAT_TP protocol layer with associated layers in OTA platform, UE & UICC environment .............134 Figure 20 - Illustration Data Exchange in PUSH mode ................................................................................................135 Figure 21 - CAT_TP Segmentation mechanism including ETSI TS 102 225 Security .....................................................136 Figure 22 - Window in CAT_TP Flow Control ..............................................................................................................138 Figure 23 - Expanded Remote Format .......................................................................................................................143 Figure 24 - Format of a Command Session TLV..........................................................................................................143 Figure 25 - The ways of accessing an ADF.................................................................................................................150 Figure 26 - Remote Application Management Architecture..........................................................................................153 Figure 27 - Loading and installing an application........................................................................................................154 Figure 28 - SAT and USAT toolkit install parameters...................................................................................................156 Figure 29 - Security Domains in non-OTA communications .........................................................................................164 Figure 30 - Structure of an AID .................................................................................................................................168
10/192
1 Introduction
In today's telecom environment, innovative services must be launched not only within the shortest timeframe, but also with greater flexibility for future upgrades and easy service maintenance. During the years, Java Card has proved itself as the key technology in service deployment. The Java Card 2.1 standard was released by the Java Card Forum in early 1999. At the same time, ETSI endorsed the use of Java Card in SIM cards and defined the GSM SIM API for Java Cards. Since them, Java Card technology and ETSI specifications have been continuously evolving to face new services and new potentiality, up to the 3G telecommunication world, finalized in the Release 7 of ETSI specifications and in Java Card 2.2.1. At the same times, interoperability between smart cards improved due to the field experience and also due to the Interoperability Stepping Stones, intended to address and solve all different interpretations of the specifications that could lead to different implementations. Completing ETSI's work of releasing specifications and test suites, the purpose of this guide is to provide developers with information concerning Java Card SIM constraints and a common interpretation of the standards for the members of the SIM Alliance that contributed to this document. The target audience of this guide is Network Operators, Wireless Service Providers and anyone interested in interoperable Java Card applet development. Used in conjunction with the Java Card Applet Developer's Guide from SUN Microsystems, this guide aims to allow interoperable Java Card applications to be developed, thereby providing: Interoperable behaviors of the Java Cards A common implementation of the standard APIs
This was achieved following a detailed gap analysis of all the Java Cards on the market, the result of which clarify and explain the following standards: Java Card (JCRE, API) Toolkit APIs Toolkit security Remote Management (Application Loading, File Management)
1.1 Acknowledgements
The document has been edited and maintained in the years by the SIM Alliance Java Card Interoperability WG. A lot of people have been contributing the document for years, but a special thank goes to the people active in the JIWG or that have been very active in the past, including: Cecile Assiet Le Doujet, Franck Barbet, Laurence Bringer, Pierre Fargues, Virginie Galindo, Guillaume Nave, Hung Ju Wang (Gemalto), Carsten Fischer, Thomas John, Wladimir Pauls, Jens Siebert, Detlef Kohelers (Sagem Orga), Khalid Hadj, Thierry Simon, Sebastian Sohier, Mehdi Soumhi (Oberthur), Giancarlo Celentano, Amedeo Veneroso (ST Incard), Daniel Daksiewicz, Dr. Stephan Miculcy, Ulrich Huber, Michael Schnellinger, Thorsten Urhahn, Nils Nitsch (G&D).
11/192
Reference Documentation
Entity ETSI (www.etsi.org) TS 102 127 Release 6 TS 102 221 Release 7 TS 102 222 Release 7 TS 102 223 Release 7 TS 102 225 Release 7 TS 102 226 Release 7 TS 102 267 Release 7 TS 102 241 Release / TS 102 483 Release 7 TS 102 588 Release 7 TS 102 600 Release 7 TS 102 613 Release 7 TS 102 622 Release 7 3GPP (www.3gpp.org) TS 31.102 Release 7 TS 31.103 Release 7 TS 31.111 Release 7 TS 31.115 Release 7 TS 31.116 Release 7 TS 31.130 Release 7 TR 31.900 Release 7 TR 31.919 Release 7 GlobalPlatform (www.globalplatform.org) Characteristics of the USIM application Characteristics of the ISIM application Universal Subscriber Identity Module Application Toolkit (USAT) Secured packet structure for (Universal) Subscriber Identity Module (U)SIM Toolkit applications Remote APDU Structure for (Universal) Subscriber Identity Module (U)SIM Toolkit applications (U)SIM Application Programming Interface (API); (U)SIM API for Java Card SIM/USIM internal and external interworking aspects 2G/3G Java Card Application Programming Interface (API) based applet interworking Global Open Platform Card Specification, Version 2.1.1 (plus Amendment A check by all) TS 31.101 Release 7 Transport protocol for CAT applications UICC-Terminal interface; Physical and logical characteristics Administrative commands for telecommunications applications Card Application Toolkit (CAT) Secured packet structure for UICC based applications Remote APDU structure for UICC based applications Connection Oriented Service API for the Java Card platform Java Card API for the UICC Internet Protocol connectivity between UICC and terminal Application Programming Interface (API) by a UICC webserver for Java Card platform Characteristics of the USB interface UICC - Contactless Front-end (CLF) Interface;Part 1: Physical and data link layer characteristics UICC - Contactless Front-end (CLF) Interface;Host Controller Interface (HCI) UICC-terminal interface; Physical and logical characteristics Reference TS 101 220 Release 8 Title ETSI Numbering System for Telecommunications; Application Providers (AID)
Java Card 2.2.2 Runtime Environment (JCRE) Specification Java Card 2.2.2 Application Programming Interface Java Card Applet Developer's Guide, Java Card Version 2.2.2 ISO ISO 8825-5: 2004 Information technology - ASN.1 encoding rules: Mapping W3C XML schema definitions into ASN.1
12/192
2 Abbreviations
2G 3G 3GPP ADF AID AM_DO APDU API APN ATR AuC BER BIP CAP CAT CAT_TP CC CHV CLA CNTR CSD DAP DEK DES DF DO DS EF ETSI EXP FCP FDN FID GGSN GP GPRS GSM HLR HSCSD ICC INS IP IrDA ISD JC JDK K Ki KIc KID Lc Le LND ME MF 2nd Generation Network 3rd Generation Network 3rd Generation Partnership Project Application Dedicated File Application Identifier Access Management Data Object Application Protocol Data Unit Application Programming Interface Access Point Name Answer To Reset Authentication Center Basic Encoding Rules Bearer Independent Protocol Converted Applet Package Card Application Toolkit CAT Transmission Protocol Cryptographic Checksum Card Holder Verification Class byte of the APDU Counter Circuit Switched Data Data Authentication Pattern Data Encryption Key Data Encryption Standard Dedicated File Data Object Digital Signature Elementary File European Telecommunications Standards Institute Export File File Control Parameters Fixed Dialing Numbers File Identifier Gateway GPRS Node Global Platform General Packet Radio Service Global System for Mobile communications Home Location Register High Speed Circuit Switched Data Integrated Circuit Card Instruction byte of the APDU Internet Protocol Infrared Data Association Issuer Security Domain Java Card Java Development Kit Secret Key in 3G Secret Key in 2G Key and algorithm Identifier for ciphering Key and algorithm Identifier for RC/CC/DS Length of the Command data sent by the application layer Length Expected Last Number Dialed Mobile Equipment Master File
13/192
14/192
3 Definitions
The GlobalPlatform API provides services to Applications (e.g. cardholder verification, personalization, or security services). Integrated Circuit Card The most general term for a smart card is ICC. It is always a physical and logical entity either a SIM or a UICC. Issuer Security Domain The representative entity of the card issuer. It provides support for control, security and communication requirements of the card issuer. Over-The-Air Technology which uses the mobile network features to download data to the UICC. Remote Application Remote Application Management applications are OTA interfaces to the Issuer Management Security Domain and other Security Domains. Smart Card Web Server A standard HTTP 1.1 web server embedded in a card allowing the communication with a HTTP client on the handset e.g. a web browser. Security Domain A special application that supports a secure communication between an Application Providers application and off-card entities during its personalization phase and runtime. Subscriber Identity Module SIM is the term that defines the ICC for a 2G card, there is no distinction between the physical and logical entity and the application itself. In a UICC, the SIM is an application. If it is active, the UICC is functionally identical to a 2G card. Toolkit Application Unique identification for Toolkit applications when using Over-The-Air functionality. Reference Universal Integrated Circuit The UICC is the physical and logical platform for the USIM. It can, at least, contain Card one USIM application and may additionally embed a SIM application. Universal Subscriber The USIM is not a physical entity. It is a purely logical application on a UICC. It Identity Module does only accept 3G commands and therefore it is not compatible with a 2G ME. The USIM may provide mechanisms to support 2G authentication and key agreement to allow a 3G ME to access to a 2G network. (see 3GPP TS 31 102) Global Platform API
15/192
ETSI TS 102 221 : Smart cards UICC/Terminal interface - Physical and logical characteristics
ETSI TS 102 222 : Integrated Circuit Cards (ICC) - Administrative commands for telecommunications applications USIM 3GPP TS 31.102 : Characteristics of the USIM application SIM 3GPP TS 51.011 R5: Specification of the Subscriber Identity Module - Mobile Equipment (SIM - ME) Interface
16/192
Card platform applications 3GPP Card platform GSM11.11 SIM (up to R99) 31.102 USIM 31.101 102 221 Physical, electrical, and commands description
ETSI TS 102 226 : Smart cards, Remote APDU structure for UICC based applications (U)SIM 3GPP TS 23.040:Technical realization of the Short Message Service (SMS)
3GPP TS 31.115:Secured packet structure for (U)SIM Toolkit applications (SMS-PP and SMS-CB)
3GPP TS 31.116:Remote APDU Structure for (U)SIM Toolkit applications (RFM and RAM)
17/192
R5 GSM03.48 R6 23.048
3GPP 51.014 R5 : Specification of the SIM Application Toolkit for the SIM - ME interface
18/192
51.014 SAT
31.111
USAT SIM
ETSI TS 102 241 : Smart cards, UICC Application Programming Interface (UICC API) for Java Card
(U)SIM 3GPP TS 31.130 : (U)SIM Application Programming Interface,((U)SIM API) for Java Card This API allows developing a (U)SAT application running together with a (U)SIM application and using GSM/3G network features.
uicc.access
Access to the UICC file system
uicc.access.fileadministration
Administrate the UICC file system
uicc.system
Utility package allows creating objects that are implementing TLV handler interfaces
uicc.toolkit
Register to the events of (CAT) framework, Handle of TLV information; send proactive commands according to TS 102 223. 31.130 packages
uicc.usim.access
Access to the files defined in the USIM, SIM.
uicc.usim.toolkit
Register to the events defined in the USAT and STK, handle of TLV information and send proactive command according to 3GPP TS 31.111 and 3GPP TS 51.014. Evolution of standards can be represented as followed:
19/192
20/192
21/192
22/192
To have more applications selected on the UICC at the same time, the mechanism of the Logical Channels is present. On each Logical Channel a different application can be selected; moreover, files can be selected on each Logical Channel (see ISO/IEC 7816-4). This allows concurrent accesses to different files and also concurrent accesses to the same file.
Elementary Files can be addressed by File Identifier (FID), a two-bytes ID, or by Short File Identifier (SFI). The SFI can be used in file system access APDUs to implicitly select the file without sending an explicit SELECT FILE APDU.
Each operation applicable to a file (except its selection) is protected by one or more Security Conditions, identifying the prerequisites of the operation. The UICC checks, in order to allow a file operation, the Security Condition related to the relevant Access Mode to verify if the security related procedures (e.g. user PIN verification) are satisfied. The default security condition associated to an operation is NEVER. This means that the security condition for an operation whose SC_DO object can not be found is set to NEVER. The Security Attributes can be specified, for each file, in several formats: Compact format Expanded format Access rule referencing The different formats have different limitations: the Compact Format is less flexible than the Expanded format, and the Expanded format is less flexible than the Access Rules Referencing format. Though in the UICC there are three different ways to code security attributes, in the USIM all Security Attributes are coded in Access Rules Referencing format (EFARR) according to 3GPP TS 31.102; as a consequence, we consider Compact format and Expanded format out of the scope of the present document.
23/192
for an EF, if the EFARR file with the file ID indicated in tag '8B' cannot be found in the current DF, the parent DF shall be searched for EFARR. This process shall continue until the EFARR is found or until an ADF or the MF is reached; for a DF, if the EFARR file with the file ID indicated in tag '8B' cannot be found in the parent DF, the grandparent DF shall be searched for EFARR. This process shall continue until the EFARR is found or until an ADF or the MF is reached; for the MF or an ADF, the EFARR file with the file ID indicated in tag '8B' shall be searched under the MF. The structure of the access rule referencing DO is as follows. Tag Length Value '8B' '03' File ID, record number '8B' '02' + n x '02' File ID, SE IDn1, Record number X, SE IDn2, Record number Y, etc.
24/192
Only the INCREASE command or the RESIZE command can be stored in the TLV; so its not possible to code more operations in this AM_DO TLV.
Only the RESIZE command can be stored in the TLV; so its not possible to code more operations in this AM_DO TLV. Interoperability issue The RESIZE command may not be supported for a DF.
A PIN SC_DO
Its also possible to define more PIN SC_DOs for the same operation, both in AND (all conditions are required to be fulfilled) / OR (just one condition must be fulfilled) mode: TAG A0 LEN SC-DO TLV #1 SC-DO TLV #2 xx Two SC_DOs in OR TAG AF LEN SC-DO TLV #1 SC-DO TLV #2 xx Two SC_DOs in AND
25/192
Application PIN An application PIN is a PIN that allows access to any file on the UICC where it is referenced in the access rules. It is uniquely identified by the Key Reference number that is in the set 01 08 Local PIN A local PIN is a PIN that uses a local key reference which is only valid within the ADF/DF where it is indicated in the FCP. Key reference numbers for Local PIN are in the set 81 88; two different ADFs can use the same local key reference number with different PIN value and different status (enabled, disabled, verified, blocked), one for each ADF. Universal PIN The Universal PIN is a PIN that is used in a multi-application environment to allow several applications to share one common PIN. The Universal PIN is a global access condition that has been assigned a key reference value '11'. Administrative PIN Up to 10 administrative PINs may be available. They are usually dedicated to the operator. They are uniquely identified by the Key Reference number that is in the global set 0A 0E and the local set 8A 8E. Interoperable issue: It's not guaranteed by all SIM Alliance members that the Local PIN may be defined under DFs that are different from the ADF; usage of local PIN defined under the ADF is guaranteed. Interoperability Issue SIM Alliance Members can not guarantee that the uses of the administrative PINs are fully interoperable especially concerning the range 0x8A 0x8E.
The current SE depends on the state of the Application PIN of the current application; if the Application PIN of the current application is disabled with Usage Qualifier set to Use Universal PIN, the current SE is the SE 00; in the other cases, the current SE is the SE 01. Developer tip: Toolkit applet access conditions consider the active Security Environment as the SE 01; they do not care Universal PIN.
26/192
FCP template for EF: Description File Descriptor File Identifier Proprietary information Life Cycle Status Integer Security attributes File size Total file size Short File Identifier (SFI) M: Mandatory. O: Optional. C1: Exactly one shall be present. TLV description: File Descriptor: specifies the file accessibility, the file type and structure. It indicates if a file is an EF or a DF, if it is record based or transparent, and so on. File Identifier: The File Identifier is a two bytes data unique for each DF identifying the file. DF Name (or AID): is a string of bytes which is used to uniquely identify an application dedicated file in the card. Proprietary Information: is a Constructed TLV (i.e., a TLV containing Simple TLVs), containing some TLV specified by the standard and also some TLV specified from singular SIM Vendors. Developer Tip The proprietary TLV contained in this Constructed TLV may vary among card vendors and among different card versions. Concerning the Security Attributes only the tag '8B' is managed. The other ways of coding (tags '8C' or AB) are out of the scope of this document. See chapter Security architecture. Life Cycle Status Information (LCSI): is a TLV indicating file status respect to its activation status (i.e. Activated / Deactivated) and its administrative status (just created, initialized, and so on). Security Attributes: contains information about the security related procedures required to allow file operations. (See 6.3.1). Developer Tip Only the tag '8B' is managed. The other ways of coding (tags '8C' or AB) are out of the scope of this document. PIN Status template DO: contains a list of all the PINs available in that (A)DF or MF and their activation status (enabled / disabled). File Size: indicates the size of the BODY of the EF. Total file size: indicates the size occupied on the card by the file (including structural information) Short File Identifier (SFI): if the SFI is indicated, it can be used as defined in 6.3. Tag '82' '83' 'A5' '8A' '8B', '8C' or 'AB' '80' '81' '88' Status M M O M C1 M O O
27/192
Interoperability Warning SIM Alliance members do not guarantee that transitions between the above states can be done in an interoperable way SIM Alliance members do not guarantee that any of the above states is reachable on the different smartcard products, especially concerning the non-operational states.
28/192
29/192
30/192
Figure 2 - NFC system architecture A Mobile NFC system consists of a Mobile phone including a NFC-Controller (also called Contactless Frontend, CLF) and a Contactless Reader. The CLF is connected to the UICC on its free PIN C6 using a single wire connection for bidirectional data transfer. The protocol on this interface is called Single Wire Protocol (SWP), standardized in ETSI TS 102 613. In the UICC the SWP-interface is an independent interface additional to the standard contact based interfaces like ETSI TS 102 221 (ISO) interface or ETSI TS 102 600 (USB) interface. The CLF can communicate directly with the UICC without using those interfaces (see figure 1). The interface between the application layer of the UICC and the SWP layer is provided by the Host Controller Interface (HCI). This interface is defined by ETSI TS 102 622. An HCI Exchange command allows to exchange data between two Hosts using a standardized APDU as defined by ETSI TS 102 221. Therefore the UICC can handle an incoming APDU from the SWP-interface in the same way as if it comes from the contact based interface. The High Level architecture of the SWP communication stack is shown in figure 3.
31/192
When the communication between the terminal and the mobile is finished the terminal sends a HLT or DESELECT command via NFC which results in a DEACTIVATED state.
SIM
CLF
Anticollision
NFC Terminal
X times
Response Response (I-blocks) HLT / DESELECT Deactivated state
Interoperability Issue It depends on the card implementation which ISO Protocols the UICC enables. E.g. it is not specified in Release 7 how an Application tells the Operating system if it wants to communicate with Type A or Type B.
Interoperability Issue It is not standardized for the UICC where to store the card individual Unique-ID (UID) or Pseudo-Unique Proximity Card Identifier (PUPI) values, so it is manufacturer dependent (similar to the above issue of protocol subscription).
32/192
33/192
Link Layer
ACT control ACT Payload (max 3 bytes) 1 byte ready, power or sync ACT_DATA, ACT_INF CLT head./command Payload 1 byte [ 010 | CMD ] (max 29 bytes) command type command SHDLC control 1 byte I-, S-, or U-frame SHDLC Payload (max 29 bytes)
HCP packet Header HCP packet Data 1 byte (max 28 bytes) chaining bit | Pipe identifier
HCP message Data contains HCI parameter, for command, event or response (max 27 bytes)
Figure 4 - Structure of the communication items in the protocol layers of the SWP stack Description of the different layers shown in Figure 4: MAC Layer: A received SWP Frame will be evaluated by the Medium Access Control Layer, which detects the SOF, EOF and checks the CRC Checksum. The Link Layer evaluates the LLC-Control byte to determine if the message type is either ACT (mandatory): handles the activation Protocol during SWP activation, or CLT (optional): Contactless Tunneling, used for proprietary transport mechanisms, or SHDLC (mandatory): Simplified High Level Data Link Control, used for regular data exchange)
Link Layer:
HCP Packet Layer: In a regular SHDLC Payload the Header-Byte will indicate Chaining and the Pipe-ID. HCP message Layer: The HCP message Header contains the message type (command, event or response) and the corresponding HCI Instruction/Event. The Parameters will follow in the Data part.
34/192
Due to the fact that the Payload of an HCP Message has a maximum size of 27 bytes, it is necessary that longer messages are fragmented into several frames. Following diagram shows a message with length = L and its fragmentation using two frames. The fragmentation is indicated in the Chaining Bit (CB) of the HCP Packet Header. Only the last frame of a fragmented message will have the Chaining Bit set to value 1. Non-fragmented messages will have the Chaining Bit always set to 1. The HCP-message header only appears in the first frame of the fragmented message. Frame 1:
SOF
SHDLC Header
CRC / LRC
EOF
SOF
SHDLC Header
CRC / LRC
EOF
When exchanging APDUs via SWP, each APDU is mapped to one HCI Exchange command, so a fragmented HCP message belongs to one APDU only.
Host Mobile
Host USIM
static Pipe 0
static Pipe 0
static Pipe 1
static Pipe 1
35/192
A Host in the HCI Infrastructure is identified by the Host-ID (1 byte). Beside several Hosts the system contains always one Host-Controller, which is the Contactless Frontend in the Mobile-NFC. A Gate is an entry point to a service that is operated inside a Host, identified by a Gate-ID (1 byte). Management Gates are needed for the management of the Host Network, Generic gates are just generally defined by HCI and may extend the access to the Hosts services. For simplicity the figure does not include Identity Management and Loop-Back Gate (one for each Host). A pipe is a logical communication channel between two gates, identified by a Pipe-ID (1 byte). - Static Pipes have fixed Pipe-IDs and are always available, they do not need to be created and cannot be deleted. - Dynamic Pipes have Pipe-IDs allocated by the Host-Controller, they can be created and deleted. The state can either be open or closed and it stays persistent if the Host is powered down and up again.
Gate:
Pipe:
7.11.1 UICC
ATR According to ETSI TS 102 221 V7.10.0 the UICC-CLF support is coded in the optional Global Interface bytes, which are present after the T=15 indication in the ATR. The content of the first Tbi (i>2) after T=15 is defined as: b8 1 b7 b6 1 b5 b4 b3 b2 b1 Meaning UICC-CLF interface is supported as defined in ETSI TS 102 613
SELECT MF response If the UICC needs to know the TERMINAL Capabilities regarding CLF support, the UICC may request the Terminal-Capabilities command from the Mobile in the UICCs Proprietary Information Template (Tag A5), which is responded by the selection of the MF. There the tag 87 for Supported System Commands has to indicate to the Phone: b8 b7 b6 b5 b4 b3 b2 b1 1 0 Meaning TERMINAL CAPABILITY is supported TERMINAL CAPABILITY is not supported
7.11.2 Mobile
When the UICC has indicated the request for a TERMINAL CAPABILITY command (see above), the mobile shall send the APDU command TERMINAL CAPABILITY to the UICC. Within its template tag A9 the mobile indicates an Additional Interface Support with tag 82, coded as: b8 b7 b6 b5 b4 b3 b2 b1 1 0 Meaning UICC-CLF interface according to ETSI TS 102 613 supported UICC-CLF interface according to ETSI TS 102 613 not supported
36/192
To develop interoperable and future proof contactless applications it is advised that an applet developer only uses standardized contactless APIs. The usage of the JavaCard 2.2.2 Contacless API is described in the following chapter.
import javacard.framework.APDU; class MyApplet extends javacard.framework.Applet { // ... public void process(APDU apdu) { // ... byte[] buffer = apdu.getBuffer(); byte cla = buffer[ISO7816.OFFSET_CLA]; byte ins = buffer[ISO7816.OFFSET_INS]; // Determine protocol type... byte protolcol = apdu.getProtocol(); if ((protocol == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A) || (protocol == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_B)) { // Special contactless processing... } else { // Normal behaviour... } //... } }
Developer Tip: To provide more convenience to the user of a contactless application (e.g. presentation of results of a contactless communication), a developer might want to use proactive commands from the UICC toolkit. Therefore it is required that the applet registers to the toolkit event PROACTIVE_HANDLER_AVAILABLE (e.g. during the execution of the applets process() method during contactless communication). The applet is then triggered after the contactless communication of the application has finished and a further command is executed on the ETSI TS 102 221 interface. This approach has the advantage that the applet is deregistered from the event after it has been triggered. This mechanism can be replaced by using the HCI-Connectivity mechanism as mentioned in section 5.4, once it is available as an API.
37/192
than a few hundred milliseconds. Therefore it is not advised to perform time-critical operations during a contactless communication. Availability of Contactless Interface Another issue of contactless application development is information reliability. Because of the contactless connection between the NFC terminal and the CLF, it is possible that the user exits the electrical field of the NFC-terminal and the connection drops. If this happens during the processing of a contactless application, it may lead to data corruption or application interruptions. To prevent data corruption, it is advised to perform contactless operations inside an applet using Javacard transactions. Using this approach the applet developer can ensure the consistency of the data processed during applet runtime. However it must be considered that using Javacard Transactions has a major impact on runtime of an applet which is contrary to the timing issue mentioned above. The applet developer is in charge to find the right balance of performance and security.
From the Applet Developer view the first of the above items is very useful, because it allows the USIM to immediately proceed with a Proactive Command even if an Applet was triggered by its process() method (which is usually the case in Card Emulation Mode, where the Applet is selected by its AID and APDUs are sent by the SWP interface to the Applet). Currently no standard API is existing for the Applet Developer to trigger the Connectivity Mechanism.
Applet Developer Tip Currently the only interoperable way for an Applet to get triggered by the Mobile is to request a POLLINTERVAL(x seconds) and register to an EVENT_PROACTIVE_HANDLER_AVAILABLE. For the user-experience it might be an issue, that there is a gap between ending of the SWP communication and the succeeding command on the ISO-Interface which triggers the Applet with the mentioned event.
38/192
Developer tip: SIM Alliance Members agree that in case a message is received on one interface while the other is executing, the message is not lost but its execution can be delayed until the completion of the execution on the other interface. Interoperability Issue: On some cards, it is possible to grant a higher priority to the SWP interface in order to respect some timing constraints. However this is not considered as an interoperable solution as it is not supported to configure priority on all cards from SIM Alliance members. Interoperability Issue: Concurrency when the card acts in the Reader mode is out of scope and is not guaranteed to be interoperable.
only supported with Link-Layer in CLT-Mode and proprietary higher Layer (note 1) full support by SHDLC and HCI full support by SHDLC and HCI only supported with Link-Layer in CLT-Mode and proprietary higher Layer full support by SHDLC and HCI
note 1: The MIFARETM Protocol is a proprietary protocol using hardware based stream-cipher for very fast processing. Due to the overall encryption of the full communication and the strong timing requirements, the MIFARETM messages have to be tunnelled through the CLF using the CLT-Mode on the Link-Layer. As there is currently no API for the CLT-Mode available, a further evaluation is out of scope of this document.
39/192
40/192
Figure 3 - The JCRE Context A basic example of using a shareable interface object is as follows. Step 1: defining a shareable interface.
package com.simalliance.serverappletpackage; import javacard.framework.Shareable; public interface ServerInterface extends Shareable { public void myMethod (short myParameter); }
Step 2: the server applet must implement the interface containing the method to be called from a client applet (in this case, myMethod), the parameters to be processed (myParameter) and an implementation of the getShareableInterfaceObject method (this is to override the method implementation of the javacard.framework.applet class which returns null by default).
package com.simalliance.serverappletpackage; import javacard.framework.*; public class ServerApplet extends Applet implements ServerInterface { short myParameter; public void myMethod(short increment) { myParameter = (short) (myParameter + increment); } public Shareable getShareableInterfaceObject(AID clientAID, byte anyParameter){ // anyParameter may be used to authenticate the client applet return this; } }
41/192
Step 3: the client applet must retrieve the AID of the shareable interface object (sio) from the JCRE. With this, it can call the method to obtain the sio from the server applet.
package com.simalliance.clientappletpackage; import javacard.framework.*; import com.simalliance.serverappletpackage; private short thisParameter = ANY_NUMBER; static final short SW_SERVER_APPLET_NOT_EXIST = (short) 0x6F01; // Server AID has to be coded in the client applet or assigned in the personalisation private byte[] server_aid_bytes = SERVER_AID_BYTES; public class ClientApplet extends Applet { private void addParameterViaSio() { // obtain the server AID object AID server_aid = JCSystem.lookupAID(server_aid_bytes, (short)0, (byte)server_aid_bytes.length); if (server_aid == null) ISOException.throwIt(SW_SERVER_APPLET_NOT_EXIST); //request sio from server applet ServerInterface sio = (ServerInterface) (JCSystem.getAppletShareableInterfaceObject(server_aid, ANY_PARAMETER)); //execute myMethod of the server applet sio.myMethod(thisParameter); } }
42/192
Keywords
native, synchronized, transient, volatile, strictfp are not supported.
Types
There is no support for char, double, float, and long, or for multidimensional arrays. Support for int is optional.
Exceptions
Some Exception and Error subclasses are omitted because the exceptions and errors they encapsulate cannot arise in the Java Card platform.
A fully qualified package name is limited to 255 bytes. Note that the character size depends on the character encoding.
Classes
A class can directly or indirectly implement up to 15 interfaces.
A package can have up to 256 static methods if it contains applets (an applet package), or 255 if it is a library package.
A class can implement up to 128 public or protected instance methods, and up to 128 with package visibility.
43/192
Figure 4 - Converting a CAP file Concerning the converter, it is recommended to use the one included in CJDK 2.2.2. The version of this converter is 1.3.
8.5.2 Verifier
The verifier is a powerful tool that performs security checks to the CAP file. Actually, the converter checks only if the Java files are compatible with the Java Card language limitations; the verifier enforces security verifying the CAP file structure and that operations are well typed to avoid reference forgery. The set of conformances checks guarantees that such files do not attempt to compromise the integrity of a Java Card virtual machine and hence other applets.
java.io
java.io defines one exception class, the base IOException class, to complete the RMI exception hierarchy. Exceptions IOException: A Java Card runtime environment-owned instance of IOException is thrown to signal that an I/O exception of some sort has occurred.
java.lang Java.lang defines Object and Throwable classes. It also defines a number of exception classes: the Exception base class, various runtime exceptions, and CardException. Classes Object: Class Object is the root of the Java Card platform class hierarchy. Throwable: The Throwable class is the superclass of all errors and exceptions in the Java Card
platforms subset of the Java programming language.
44/192
Exceptions ArithmeticException: A Java Card runtime environment-owned instance of ArithmeticException is thrown when an exceptional arithmetic condition has occurred. ArrayIndexOutOfBoundsException: A Java Card runtime environment-owned instance of ArrayIndexOutOfBoundsException is thrown to indicate that an array has been accessed with an
illegal index.
ArrayStoreException: A Java Card runtime environment-owned instance of ArrayStoreException is thrown to indicate that an attempt has been made to store the wrong type
of object into an array of objects. ClassCastException: A Java Card runtime environment-owned instance of ClassCastException is thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. Exception: The class Exception and its subclasses are a form of Throwable that indicate conditions that a reasonable applet might want to catch. IndexOutOfBoundsException: A Java Card runtime environment-owned instance of IndexOutOfBoundsException is thrown to indicate that an index of some sort (such as an array) is out of range. NegativeArraySizeException: A Java Card runtime environment-owned instance of NegativeArraySizeException is thrown if an applet tries to create an array with negative size. NullPointerException: A Java Card runtime environment-owned instance of NullPointerException is thrown when an applet attempts to use null in a case where an object is required. RuntimeException: It is the superclass of those exceptions that can be thrown during the normal operation of the Java Card Virtual Machine. SecurityException: A Java Card runtime environment-owned instance of SecurityException is thrown by the Java Card Virtual Machine to indicate a security violation.
javacard.framework javacard.framework defines the interfaces, classes, and exceptions that compose the core Java Card Framework. It defines important concepts such as the Application Protocol Data Unit (APDU), the Java Card applet (Applet), the Java Card System (JCSystem), the Personal Identification Number (PIN), and a utility class. It also defines various
ISO7816 constants and various Java Card-specific exceptions.
Interfaces ISO7816: defines constants related to ISO 7816-3 and ISO 7816-4.
MultiSelectable: identifies applets that can support concurrent selections. PIN: represents a personal identification number used for security (authentication) purposes. Shareable: identifies a shared object. Objects that must be available through the applet firewall must implement this
interface.
Classes AID: defines an ISO7816-5-conforming Application Identifier associated with an application provider; a mandatory
attribute of an applet.
APDU: defines an ISO7816-4-conforming Application Protocol Data Unit, which is the communication format used
between the applet (on-card) and the host application (off-card).
Applet: defines a Java Card application. All applets must extend this abstract class. JCSystem: provides methods to control the applet life-cycle, resource and transaction management, and inter-applet
object sharing and object deletion.
45/192
Util: provides utility methods for manipulation of arrays and shorts, including arrayCompare(), arrayCopy(), arrayCopyNonAtomic(), arrayFillNonAtomic(), getShort(), makeShort(), setShort().
Exceptions
Various Java Card VM exception classes are defined:
Developer tip: The OwnerPIN class can be used by Java Card applets to define additional PINs but it does not offer interface to handle PINs defined by network access applications.
javacard.framework.service javacard.framework.service defines the interfaces, classes, and exceptions for services, including RMI
services.
RemoteService: is a generic Service that gives remote processes access to services on the card. SecurityService: extends the Service base interface, and provides methods to query the current security status, including isAuthenticated(), isChannelSecure(), and isCommandSecure().
Classes BasicService: is a default implementation of a Service; it provides helper methods to handle APDUs and service
collaboration.
Dispatcher: maintains a registry of services. Use a dispatcher if you want to delegate the processing of an APDU to several services. A dispatcher can process an APDU completely with the process() method, or dispatch it for processing by several services with the dispatch() method. CardRemoteObject: base class to enable or disable remote access to an object from outside the card. RMIService: this class extends BasicService and implements RemoteService to process RMI requests
Exceptions ServiceException: a service-related exception.
javacard.security javacard.security defines the classes and interfaces for the Java Card security framework. The Java Card
specification defines a robust security API that includes various types of private and public keys and algorithms, methods to compute cyclic redundancy checks (CRCs), message digests, and signatures:
Interfaces
Generic base interfaces Key, PrivateKey, PublicKey, and SecretKey, and subinterfaces that represent various types of security keys and algorithms: AESKey, DESKey, DSAKey, DSAPrivateKey,
DSAPublicKey, ECKey, ECPrivateKey, ECPublicKey, RSAPrivateCrtKey, RSAPrivateKey, RSAPublicKey, KoreanSEEDKey, HMACKey SignatureMessageRecovery: an interface that shall be implemented by a subclass of Signature in order to
46/192
KeyAgreement: base class for key-agreement algorithms KeyBuilder: key-object factory KeyPair: a container to hold a pair of keys, one private, one public MessageDigest: base class for hashing algorithms. Since JC2.2.2, the method getInitializedMessageDigestInstance(byte, boolean) can be used to retrieve an instance of the InitializedMessageDigest class. InitializedMessageDigest: a subclass of MessageDigest which provides the possibility to initialize the
starting hash value. This can be used by the programmer to calculate partial message digests for a subset of the complete data.
RandomData: base class for random-number generators Signature: base abstract class for signature algorithms Exceptions CryptoException: encryption-related exceptions such as unsupported algorithm or un-initialized key.
Developer Tips: Not every algorithm is supported by each card (RSA, Elliptic Curves). If an unsupported algorithm is used, a CryptoException with the specific reason: NO_SUCH_ALGORITHM is thrown.
javacardx.crypto
This extension package that defines the interface KeyEncryption and the class Cipher, each in its own package for easier export control.
Interfaces Classes
KeyEncryption: Generic bas interface used to decrypt an input key used by encryption algorithms Cipher: base abstract class that all ciphers must implement
java.rmi java.rmi defines the Remote interface and the RemoteException class.
Interfaces Remote: The Remote interface serves to identify interfaces whose methods may be invoked from a CAD
client application.
47/192
Improved Logical Channels support - The Javacard API now supports up to 20 logical channels on any I/O interface (contacted/contactless). It is not mandatory, however, for a card to support the full range of 20 channels. External Memory access An optional extension package offers access to external memory subsystems on both contact and contactless deviced. Optional extension framework packages Additional packages simplify and quicken applet development. State of the art cryptographic engines - Provides more security options by supporting the following additional algorithms:
o o o
SHA-256, SHA-384, SHA-512 ISO9796-2 with message recovery, HMAC, Korean SEED MAC NOPAD Korean SEED NOPAD
48/192
o o o o o
Manipulate arrays and primitives of byte, short and int type Perform calculations with BCD (Binary Coded Decimals) Compute parity bits for DES keys Managing BER-TLV structures Utility functions for the int primitive type
If the package is implemented, all of the contained sub-packages util, math and tlv shall be included. If the card supports the int primitive type, the package javacard.framework.util.intx shall be available.
49/192
Compared to an applet using APDU, the Java Card applet does not have to analyze the APDU buffer. In the JCRMI model, APDUs are formatted by the RMI services that directly invoke the addressed methods of the server applet by using Global Array for this buffer. A unique ID (stub) is assigned to the remote methods, during the compilation.
Applet Selection:
First, it is needed to get the initial object reference from the server applet through the SELECT FILE command (see ISO 7816-4). The answer to this command is a constructed TLV that include:
The INS byte which is going to be used for the next commands (invocation). The remote object identifier and information to identify the associated class.
Developer tip: The command needs to have the following options: Direct Selection by DF name, also used to select an applet by its AID Return File Control Information (FCI): this option is used to retrieve FCI information from the applet.
Method Invocation:
Concerning the second step, it consists to invoke a remote method. For example, the client application (CAD application) wants to retrieve some information. It is needed to provide some parameters: The INS byte: it has been sent by the server in the Select Answer.
50/192
The remote object identifier: it is the reference on the remote object that has been sent, by the smart card, during the applet selection. The invoked method identifier: it permits to retrieve which remote methods is to be execute. The parameters values of the remote method: it is needed to indicate the length of the argument followed by its value (seems to be in the same order). The server answers by returning the retrieved information (value, arrays ). The return values are always followed by a good completion status code 0x9000. In case an error occurs, the remote method throws an exception.
Functional limitation
Parameters of a remote method must be any supported data types or any single dimension array of supported data types. Returned values of a remote method must only be one of the following type: Any supported data type or any single dimension array of supported data type (transmitted by value) A void return Any remote interface (transmitted by reference using a remote object reference descriptor) CAD remote objects can not be passed as arguments to remote methods Applets can not invoke remote methods on the CAD client Method argument data and returned values must not be higher than the size constraint of an APDU.
CardExceptionSubclass, CardRuntimeExceptionSubclass, CryptoExceptionSubclass, ISOExceptionSubclass, PINExceptionSubclass, PINException, ServiceExceptionSubclass, SystemExceptionSubclass, TransactionExceptionSubclass, and UserExceptionSubclass. javacard.framework defines a number of Java Card exceptions that can be re-thrown on the client: APDUException, CardException, CardRuntimeException, ISOException, PINException, SystemException, TransactionException, and UserException. javacard.framework.service defines the ServiceException, which represents an
exception related to the service framework.
51/192
static byte[] makeTransientByteArray(short length, byte event), static byte[] makeTransientBooleanArray(short length, byte event), static Object makeTransientObjectArray(short length, byte event), static short[] makeTransientShortArray(short length, byte event), static byte isTransient(java.lang.Object theObj).
A transient array of primitive data types or Objects references can be created. A transient array exists as long as references to it remain. The contents of a transient array get reset to the field's default value (zero, false, or null) when an event such as a card reset or applet deselection occurs depending on the transient type (CLEAR_ON_RESET and CLEAR_ON_DESELECT).
Developer Tips For toolkit applets, the use of COD is prohibited. In a Java Card environment, arrays and primitive types should be declared at object declaration, and you should minimize object instantiation in favor of object reuse. Instantiate objects only once during the applet lifetime. It is recommended to allocate memory in the install() method as it is invoked only once and the applet is ensured that all the reserved memory is available for all the applet lifetime. In order to avoid resource wasting, a global array has been defined as a buffer that can be used by any applet (see uicc.system).
52/192
53/192
54/192
This is done by the CAT Runtime Environment using the system proactive commands SET UP MENU, SET UP EVENT LIST and POLL INTERVAL. The list depends on the requirements of the toolkit applets installed on the card. During a CAT session the card shall inform the ME and send the system proactive commands SET UP MENU, SET UP EVENT LIST, POLL INTERVAL and POLLING OFF when a change occurs (e.g. change in the menu list, change of the menu title - an update of the content of EFSUME, change in the event list, change in the polling interval).
55/192
56/192
package as the SIM Toolkit Applets. But there are additional features a USAT Toolkit Applet can handle compared to a SIM Toolkit Applet.
A Toolkit Applet is a Java Card applet with the following additional capabilities: It provides an additional entry point: the processToolkit() method It may register to some toolkit events such as the menu selection or the reception of a SMS. When such an event occurs the CAT Runtime Environment triggers the applet through its processToolkit() method. When triggered, it may request the CAT Runtime Environment to send a proactive command and analyze the mobile response.
57/192
In fact a Toolkit Applet derives from javacard.framework.Applet and provides the same entry points. But it also provides an object implementing the uicc.toolkit.ToolkitInterface interface. This object shall implement the method processToolkit(). This method is called by the Triggering Entity of the CAT Runtime Environment to process the current event if the applet is register on this event. This object might be the applet itself or another object owned by the applet.
10.2.2.2
The loading and the installation of a Toolkit Applet as well as its life cycle complies with the ETSI TS 102 226 and does not differ from a Java Card applet with the exception that the installation command shall include toolkit parameters as specified in the ETSI TS 102 226 (UICC Toolkit Application specific parameters field) to initialize the toolkit registry of this applet the applet shall first register to the JCRE as defined in the "Java Card 2.2.2 Runtime Environment (JCRE) Specification" by calling one of the Applet.register() methods. Then it shall register to the CAT Runtime Environment by calling the ToolkitRegistrySystem.getEntry() method and it gets a reference to its registry entry (object implementing the ToolkitRegistry interface). Developer tips The ToolkitRegistrySystem.getEntry() method has to be invoked after the invocation of the Applet.register() method. Usually the invocation of the installation method includes the invocation of the register() method, the invocation of the ToolkitRegistrySystem.getEntry() method and then the toolkit registry configuration (menu creation and configuration, event registration). The applet installation is considered successful when the call to register() completes without any exception. The installation is considered unsuccessful if an exception is thrown prior to the call to a register() method, or if the call to the register() method results in an exception. If the installation is unsuccessful, the Java Card Runtime Environment performs all the necessary clean up to reclaim all the allocated resources. So it is recommended to allocate all the resources such as objects and arrays allocation before calling the register() method. But the toolkit registry entry has to be retrieved after the register() method so the toolkit resources are reclaimed only when the applet is explicitly deleted using a DELETE command. Once installed and registered to the Toolkit Registry, the Toolkit Applet can register to the different toolkit events and manage its menu entries if any. The Toolkit Registry updates are available during all the applet life time and are not affected by the current applet life cycle state (selectable or not). All the methods relative to the Toolkit Registry updates are available in the ToolkitRegistry interface. (U)SAT applet template package example; import uicc.toolkit.* ; import uicc.access.* ; import javacard.framework.*; /** * ETSI TS 102 241 Toolkit Applet Example */ public class AppletExample extends javacard.framework.Applet implements ToolkitInterface, ToolkitConstants { /** * Toolkit Registry object. */ public ToolkitRegistry toolkitRegistry ; private byte[] menuEntry = {(byte)'1',(byte)'0',(byte)'2',(byte)' ',(byte)'A',(byte)'p',(byte)'p',(byte)'l',(byte)'e',(byte)'t'}; private byte itemId; /** * Applet constructor */ public AppletExample () { // Register to the JCRE register() ; ',(byte)'2',(byte)'4',(byte)'1',(byte)'
58/192
// Retrieve the Toolkit Registry object toolkitRegistry = ToolkitRegistrySystem.getEntry(); // Create a menu itemId = toolkitRegistry.initMenuEntry(menuEntry, (short)0, (short)menuEntry.length, (byte)0, false, (byte)0, (short)0) ; } /** * Method called by the JCRE at the installation of the applet */ public static void install(byte bArray[], short bOffset, byte bLength) { AppletExample thisApplet = new AppletExample(); } public Shareable getShareableInterfaceObject(AID aid, byte p) { if (aid == null && p == (byte)1) { return this ; } return null ; }
/** * Called by the JCRE to process an incoming APDU command. An applet is * expected to perform the action requested and return response data if * any to the terminal.<p> */ public void process(APDU apdu) throws ISOException { }
/** * Method called by the CAT Runtime Environment. */ public void processToolkit (short event) { // process Toolkit events switch (event) { ... } } }
10.2.2.3
When receiving an incoming APDU a Translator converts it into the corresponding Event. The Triggering Entity asks the Toolkit Registry which Toolkit Applets are registered to this Event and then triggers all registered Toolkit Applets by calling the processToolkit() method of the ToolkitInterface Object. A Toolkit Applet is only triggered if it is in the selectable state. The difference between a Java Card applet and a Toolkit Applet is that the Toolkit Applet does not handle APDUs directly, the select() method is also not launched since the Toolkit Applet itself is not selected. Developer tip As a consequence a Toolkit Applet can not use the Transient CLEAR_ON_DESELECT objects defined in Java Card 2.2.2 Runtime Environment (JCRE) Specification".
59/192
In fact, the CAT Runtime Environment uses the Shareable Interface feature specified in "Java Card 2.2.2 Runtime Environment (JCRE) Specification" as the processToolkit() method is a method of the ToolkitInterface shareable interface object provided by the Toolkit Applet: The CAT Runtime Environment invokes the getShareableInterfaceObject() method of the Toolkit Applet to retrieve the reference of its ToolkitInterface object. This method is invoked before the first triggering of the Toolkit Applet. The AID parameter of the getShareableInterfaceObject() method is set to null. The byte parameter of the getShareableInterfaceObject() method is set to one (i.e. 01). The CAT Runtime Environment invokes the processToolkit() method of the ToolkitInterface object to trigger the Toolkit Applet. As a consequence all the rules defined in the "Java Card 2.2.2 Runtime Environment (JCRE) Specification" apply: the JCRE performs a context switch, etc. Example: /** * Process toolkit events. */ public void processToolkit(short event) throws ToolkitException { if (event == EVENT_MENU_SELECTION) { // put the applet behavior on menu selection } } When triggered, a Toolkit Applet can get details about the event by using the EnvelopeHandler if available. It can request the CAT Runtime Environment to send several proactive commands using the ProactiveHandler if available and then analyze the response of the UE (TERMINAL RESPONSE) by using the ProactiveResponse Handler. For some specific events the EnvelopeResponseHandler is also available to transmit the response of the applet to the command sent by the terminal (e.g. Envelope). The handler availability for the different events is defined in the ETSI TS 102 241 and the 3GPP TS 31.130 specification.
10.2.2.4
Multi-triggering
Depending on the event there might be more than one applet registered. The CAT Runtime Environment triggers the different Toolkit Applets consecutively according to their priority level assigned at the installation time (see the priority level parameter in the UICC Toolkit application specific parameters field of the install (for install) command). If several Toolkit Applets have the same priority level, except for the internal event EVENT_PROACTIVE_HANDLER_AVAILABLE, the applets are triggered according to their installation time (i.e. the last installed is triggered first). An applet that has the proactive handler may register for EVENT_PROACTIVE_HANDLER_AVAILABLE before returning to allow implementing a simple co-operative "task switching" mechanism based on priorities. Applets with the same priority level may implement "task switching" in a cyclic fashion. If several applets have registered to EVENT_PROACTIVE_HANDLER_AVAILABLE and an applet returns from this event, the sequence of triggering shall be determined as follows: The list of registered applets shall be re-evaluated. If there is an applet with a higher priority level than the applet that returned, the applet with the highest priority shall be triggered. Else if there are one or more applet(s) with the same priority level as the applet that returned, all applets with this priority level shall be triggered in a cyclic fashion: As long as there is at least one applet with the same priority level and older installation date, the next older applet shall be triggered. If there is no older one, the applet with newest installation date shall be triggered. Developer tip: When an applet has an expected long process of proactive commands sequence to be executed, it is recommended to check the proactive handler availability. If the proactive handler is available and there are not any other applets with higher or the same priority registered to EVENT_PROACTIVE_HANDLER_AVAILABLE (by calling isPrioritizedProactiveHandlerAvailableEventSet()), the proactive commands can be sent immediately; Otherwise the applet should register to the event EVENT_PROACTIVE_HANDLER_AVAILABLE and exit. As soon as the proactive handler becomes available the applet will be triggered and will be able to send the proactive commands.
60/192
10.2.2.5
Re-entrance
Re-entrance refers to the case whereby a proactive session (initiated by an APPLICATION A) execution is interrupted, and a second APPLICATION B (which can be the same one) is triggered. The application A is then in a suspended mode, and the nested APPLICATION B (in other words, the application triggered while another application is suspended) has its own file and access conditions context. After APPLICATION B has been finished, and no additional event occurs before the terminal response is received, control is returned to the first application, so that its own execution can be finished. Interoperable re-entrancy is supported at least for the following events: EVENT_CALL_CONTROL EVENT_SMS_MO_CONTROL EVENT_STATUS_COMMAND EVENT_PROFILE_DOWNLOAD.
Even if only four re-entrant events are supported by all SIM Alliance members cards, all members guarantee that no data is lost from a card point of view. All SIM Alliance members agree that the re-entrance list is highly configurable depending on customers need. System handler availability: SIM Alliance member guaranty at least more than one system handler is available. We strongly recommend applet developer to verify the handler availability with exception mechanism. As a consequence, the ProactiveHandler may be not available for applets triggered in re-entrance; to overcome this issue, i.e. to perform proactive commands, the re-entrance applet may register itself to the EVENT_PROACTIVE_HANDLER_AVAILABLE in order to be triggered again when the proactive handler is available. The applet shall save the content of the EnvelopeHandler if needed as it will not be available when triggered on the
EVENT_PROACTIVE_HANDLER_AVAILABLE.
10.2.2.6
Exception handling
All exceptions thrown by the application are caught by the CAT Runtime Environment. The exceptions are not propagated to the terminal except if the applet is the only one triggered by the current processed event and the exception is an ISOException with the reason code REPLY_BUSY (9300). But the ETSI TS 102 241 recommends to use an ISOException with reason code 9300 only for events where reply busy is allowed as defined in the ETSI TS 102 241 and 3GPP TS 31.130.
61/192
For
Toolkit Applets using the (U)SIM API, the USATEnvelopeHandler is also available. The USATEnvelopeHandler is mainly useful when managing the events relative to the SMS_PP and SMS_CB. It provides additional methods to handle the different fields of the SMS message or Cell Broadcast message: methods to get the length, offset and content of the message. The Toolkit Applet retrieves the USATEnvelopeHandler by using the uicc.usim.toolkit. USATEnvelopeHandlerSystem.getTheHandler() method The EnvelopeHandler and the USATEnvelopeHandler are two distinct object instances but their content (TLV data objects) is exactly the same. The USATEnvelopeHandler availability is the same as the EnvelopeHandler including all the events defined in the ETEI TS 102 241 specification. For example the Toolkit Applet can use the USATEnvelopeHandler also for the event EVENT_EXTERNAL_FILE_UPDATE. The Toolkit Applet can post a response to some specific ENVELOPE commands by using the EnvelopeResponse Handler. The EnvelopeResponseHandler is available only for the following events: EVENT_FORMATTED_SMS_PP_ENV, EVENT_UNFORMATTED_SMS_PP_ENV, EVENT_CALL_CONTROL_BY_NAA, EVENT_MO_SHORT_MESSAGE_CONTROL_BY_NAA and EVENT_UNRECOGNIZED_ENVELOPE. The Toolkit Applet retrieves the EnvelopeResponseHandler by using the EnvelopeResponseHandlerSystem.getTheHandler() method. If the handler is not available, a ToolkitException with the reason code HANDLER_NOT_AVAILABLE is thrown. The Toolkit Applet fills the EnvelopeResponseHandler and then posts the response by using the EnvelopeResponseHandler.post() or the EnvelopeResponseHandler.postAsBERTLV() method. The applet can continue its processing after the call to one of these methods.
management
for
the
event
The Toolkit Applet fills the EnvelopeResponseHandler by using the methods inherited from the EditHandler. Then, the applet posts the response using the EnvelopeResponseHandler.post(value) method, value is a Boolean. When the PoR is sent using the SMS_DELIVER_REPORT mechanism, the value is used to indicate if the PoR is sent in a RP-ACK message (value set to true) or if the PoR is sent using a RP-ERROR (value set to false). When the PoR is sent using the SMS_SUBMIT mechanism, the value is not used. The content of the EnvelopeResponseHandler is used to set the applet response to the OTA request. It is inserted by the CAT Runtime Environment in the Additional Response Data of the PoR according to the 3GPP TS 31.115. This content will be transmitted back to the OTA server.
The Toolkit Applet uses the EnvelopeResponseHandler to set the response to the ENVELOPE (CALL CONTROL) APDU command or to the ENVELOPE (MO_SHORT_MESSAGE_CONTROL) APDU command. The Toolkit Applet may fill the EnvelopeResponseHandler by using the method inherited from the EditHandler to define the content of the different data object (Address, etc). See the structure of the ENVELOPE response defined in the 3GPP TS 31.111. Then, the applet posts the response by using the EnvelopeResponseHandler.postAsBERTLV(value, tag) method. The value is ignored by the CAT Runtime Environment. The tag shall be set according to the applet response 00 for Allowed, no modification, 01 for Not allowed and 03 for Allowed with modifications. The CAT Runtime Environment uses the tag as the Call control result or the MO short message control result of the response. Developer tip The CAT Runtime Environment sends the response to the ENVELOPE before the emission of the next proactive command or when all the Toolkit Applets triggered by the event have finished their processing. If the applet want to send a specific response, it shall post it before any invocation of the ProactiveHandler.send() method.
62/192
10.4.4 Details
The EnvelopeHandler, EnvelopeResponseHandler and USATEnvelopeHandler are Temporary JCRE Entry Point Objects. When the corresponding getTheHandler() method is called or a method of the handler is called, a system handler is considered available if a ToolkitException with the reason code HANDLER_NOT_AVAILABLE is not thrown.
EnvelopeHandler and USATEnvelopeHandler: When available, the EnvelopeHandler remains available and its content remains unchanged from the invocation to the termination of the processToolkit() method. The EnvelopeHandler and USATEnvelopeHandler TLV lists are filled with the simple TLV data objects of the ENVELOPE APDU command. The simple TLV data objects are provided in the order given in the ENVELOPE command data if they result of a ENVELOPE command sent by the ME otherwise the order is undefined (for exemple when built by the CAT Runtime Environment for the event EVENT_EXTERNAL_FILE_UPDATE). Developer tip The order of the different TLV data objects is not specified so it is recommended to use the ViewHandler.findTLV() methods to get each COMPREHENSION TLV. EnvelopeResponseHandler: The EnvelopeResponseHandler is available (as specified in the ETSI TS 102 241 or the 3GPP TS 31.130 specifications) for all triggered Toolkit Applets, until a Toolkit Applet has posted an envelope response or sent a proactive command. After a call to the post() method the handler is no longer available. After the first invocation of the ProactiveHandler.send() method the EnvelopeResponseHandler is no more available. At the processToolkit() method invocation the TLV-List is cleared.
63/192
The CAT Runtime Environment allows only one Toolkit Applet to be registered to some limited events such as the event EVENT_CALL_CONTROL_BY_NAA or the event EVENT_MO_SHORT_MESSAGE_CONTROL_BY_NAA. The ToolkitRegistry.setEvent() method throws the ToolkitException with the reason code EVENT_ALREADY_REGISTERED if an applet is already registered to an limited event another applet wants to register to. The CAT Runtime Environment can reject also an event registration, for example if the event registration requests a TAR and the applet has not at least one TAR value assigned. The ToolkitRegistry.setEvent() method does not throw any exception if the applet registers more than once on the same event. The ToolkitRegistry.setEventList() method is also available to register to several events. Developer tip This method is atomic: if the registration to one of the event is rejected, then the applet is not registered to any of the events.
1 19 -1 7 8 2 3 4 5 6 24 121 122
Handle the formatted USSD message sent by the network Handle the unformatted USSD message sent by the network Use the timer capabilities of the handset Control the outgoing calls and the outgoing SMs
11 9 10
12 13 14 15 16 17
Track changes of the location status or location information Track the user activity Get triggered when the mobile screen becomes available.
64/192
Used when multiple cards are available on the handset Track changes of the currently used language Track the handset browser termination Handle the BIP protocol
18 20 21 22 23 25 26 27
_ NETWORK_SEARCH_MODE_CHANGE _BROWSING_STATUS _IWLAN_ACCESS_STATUS UICC related events EVENT_PROACTIVE_HANDLER_AVAILABLE EVENT_EXTERNAL_FILE_UPDATE EVENT_APPLICATION_DESELECT EVENT_FIRST_COMMAND_AFTER_ATR
Track changes in the access technology (GSM, UTRAN, etc) Track changes of the display parameters (number of characters, text wrapping, etc) Track the incoming connection request on a local bearer using a service previously declared by the UICC Track changes in the network search mode (manual or automatic) Track the error code sent by the network and received by the browser Track the iWLAN coverage availability Get informed when the proactive handler becomes available Track the updates done by the handset on the specified files Get informed that an application (NAA) is no more selected Get triggered just after the card reset.
(1) This event is defined in the 3GPP TS 31.130 specification (2) This event is linked to the Bearer Independent Protocol (OPEN CHANNEL, CLOSE CHANNEL, SEND DATA, RECEIVE DATA and GET CHANNEL STATUS proactive commands) (3) This event is linked to the DECLARE SERVICE proactive command Developer tip The range of values [-2; -128] is reserved for proprietary events. A card can manage proprietary events but if an applet uses one of these events, it will not be working properly on another card that may not handle this event. In order to be interoperable, applets should not use these events.
65/192
triggered by the event EVENT_MENU_SELECTION_HELP_REQUEST only if help is supported for the corresponding Menu entry. A Toolkit Applet registers to these events using the ToolkitRegistry.initMenuEntry method. no method to un-register to these events but the applet can use the ToolkitRegistry.disableMenuEntry to disable the menu entry. If a menu entry is disabled, it appear on the toolkit menu of the terminal and the applet will not be triggered. The ToolkitRegistry.enableMenuEntry enables the menu again. There is method does not method
The maximum number of menu entries available for a Toolkit Applet is defined during the installation phase in the UICC toolkit parameters field of the install(for install) command. The maximum length of a menu string is also defined. The ToolkitRegistry.initMenuEntry method throws an exception if all the menu entries available for the applet are already initialized or if the length of the menu entry string exceeds the length defined during the installation phase. Once initialized the different properties of a menu entry can be updated using the ToolkitRegistry.changeMenuEntry method. Developer tip The ToolkitRegistry.initMenuEntry method shall be called by the applet in the same order as the order of the item parameters defined at the applet installation if the applet has several menu entries. It is recommended that an applet initialize its menu entries during its installation. Example: public class AppletExample extends javacard.framework.Applet implements ToolkitInterface, ToolkitConstants { public ToolkitRegistry toolkitRegistry ; private byte[] menuEntry1 = {(byte)'M',(byte)'y',(byte)' ',(byte)'M',(byte)'e',(byte)'n',(byte)'u',(byte)' ',(byte)'1'}; private byte[] menuEntry2 = {(byte)'M',(byte)'y',(byte)' ',(byte)'M',(byte)'e',(byte)'n',(byte)'u',(byte)' ',(byte)'2'}; private byte menuId1, menuId2; /** * Applet constructor */ public AppletExample () { // Register to the JCRE register() ; // Retrieve the Toolkit Registry object toolkitRegistry = ToolkitRegistrySystem.getEntry(); // Create the menus menuId1 = toolkitRegistry.initMenuEntry(menuEntry1, (short)0, (short)menuEntry1.length, (byte)0, false, (byte)0, (short)0) ; menuId2 = toolkitRegistry.initMenuEntry(menuEntry2, (short)0, (short)menuEntry2.length, (byte)0, false, (byte)0, (short)0) ; } ... /** * Process Toolkit events */ public void processToolkit (short event) { if (event == EVENT_MENU_SELECTION) { EnvelopeHandler theEnv = EnvelopeHandlerSystem.getTheHandler() ; byte menuId = theEnv.getItemIdentifier() ; if (menuId == menuId1) { // Insert Menu1 process } else if (menuId == menuId2) { // Insert Menu2 process } }
66/192
EVENT_TIMER_EXPIRATION Upon reception of an ENVELOPE (TIMER EXPIRATION) APDU command, the CAT Runtime Environment only triggers the Toolkit Applet registered to this event with the associated timer identifier. A Toolkit Applet registers to this event using the method ToolkitRegistry.allocateTimer, the CAT Runtime Environment will then allocate a timer resource to the applet. The applet may un-register invoking the ToolkitRegistry.releaseTimer method. Once the applet has allocated a timer, it shall send the proactive command TIMER_MANAGEMENT to start the timer, configure the timer duration or stop the timer. Developer tip The method ToolkitRegistry.allocateTimer throws an exception if all the available timers are already allocated or if the maximum number of timer available for this applet is reached. The timer remains allocated to the applet until it explicitly releases it using the method ToolkitRegistry.releaseTimer. The maximum number of timers available on a UICC is 8 timers. The maximum number of timers available for a given Toolkit Applet is defined in the UICC Toolkit application specific parameter of the install(for install) command see ETSI TS 102 226. Example: ToolkitRegistry reg; byte bTimerId; final byte[] timerValue = {(byte)0x00, (byte)0x01, (byte)0x00}; /* Timer allocation */ reg = ToolkitRegistrySystem.getEntry(); bTimerId= reg.allocateTimer(); /* Send the proactive command to start the timer */ ProactiveHandler proHdlr = ProactiveHandlerSystem.getTheHandler() ; proHdlr.init(PRO_CMD_TIMER_MANAGEMENT, (byte)0x00, (byte)DEV_ID_TERMINAL); proHdlr.appendTLV(TAG_TIMER_IDENTIFIER, bTimerId); proHdlr.appendTLV(TAG_TIMER_VALUE, timerValue, (short)0x00, (short)timerValue.length); proHdlr.send(); EVENT_STATUS_COMMAND Upon reception of an STATUS APDU command the CAT Runtime Environment shall trigger all the Toolkit Applet(s) registered to this event. The applet registers to this event by calling the method ToolkitRegistry.requestPollInterval with the indication of the requested duration negotiated with the mobile for the Proactive Polling procedure (STATUS command regularly sent by the terminal according to the ETSI TS 102 221 and ETSI TS 102 223 specifications). The ToolkitRegistry.requestPollInterval method can be used each time the applet wants to adjust a new duration. If the duration is set to POLL_NO_DURATION, the applet deregisters from the event EVENT_STATUS_COMMAND. Several applets can register on this event and can request a different duration so the CAT Runtime Environment may adjust the duration. The terminal can also adjust the duration to the one it can offer. Developer tip
67/192
The ETSI TS 102 223 specification recommends that applets should not request short time intervals for an extended period, as this will have an adverse effect on battery life, and should not use this command for time management purposes. EVENT_FORMATTED_SMS_PP_ENV1 Upon reception of a formatted Short Message Point to Point via the ENVELOPE(SMS-PP DOWNLOAD) APDU command, the CAT Runtime Environment verifies the security of the Short Message according to the 3GPP TS 31.115 specification and then triggers the applet registered to this event and having the corresponding TAR value. The toolkit can retrieve the message using the uicc.usim.toolkit.USATEnvelopeHandler defined in the 3GPP TS 31.130. The data is provided deciphered. The Toolkit Applet can post a response using the EnvelopeResponseHandler.post method. The CAT Runtime Environment will insert the data in the additional data field of the Response Packet, compute the security as defined in the 3GPP TS 31.115 and send the response packet using the SMS_DELIVER_REPORT or the SMS_SUBMIT. When a SMS is received as a concatenated SMS as defined in the 3GPP TS 23.040, the CAT Runtime Environment links the different single SMS to re-assemble the original message and fills the USATEnvelopeHandler with the original message (the concatenation headers are not present and the TP_elements and TS_ServiceCenterAddress fields are the ones of the last received SMS). See the 3GPP TS 31.130 for details. A Toolkit Applet registers to this event by using the ToolkitRegistry.setEvent method with the event value set to EVENT_FORMATTED_SMS_PP_ENV. This method throws an exception if no TAR value is defined for the applet. The TAR value associated to a Toolkit Applet is defined during the applet installation phase: the UICC toolkit parameters field of the install (for install) command can include a list of TAR values to which the applet wants to subscribe to, otherwise the TAR is taken from the AID. Developer tip The applet is triggered only if the security according to the 3GPP TS 31.115 specification has been successfully verified by the CAT Runtime Environment and if the security level used complies with the minimum security level required by the applet (parameter defined during the applet installation phase). Interoperability issue The CAT Runtime Environment may reply busy and not trigger the Toolkit Applet if e.g. a PoR using SMS SUBMIT is required in the incoming message and a proactive session is ongoing. EVENT_FORMATTED_SMS_PP_UPD1 Upon reception of a formatted Short Message Point to Point via an UPDATE_RECORD EFSMS, the CAT Runtime Environment updates the EFSMS file, converts the UPDATE_RECORD EFSMS to emulate an ENVELOPE (SMS-PP DOWNLOAD) and fills the uicc.usim.toolkit.USATEnvelopeHandler. Then it verifies the security of the SMS according to the 3GPP TS 31.115 and triggers the applet registered to this event and having the corresponding TAR. The details of the construction of the USATEnvelopeHandler TLV from the elements of the UPDATE_RECORD EFSMS are described in the 3GPP TS 31.130 specification. The Toolkit Applet can retrieve the message using the USATEnvelopeHandler defined in the 3GPP TS 31.130. The data is provided deciphered.
68/192
When a SMS is received as a concatenated SMS as defined in the 3GPP TS 23.040, the CAT Runtime Environment links the different single SMS to re-assemble the original message and fills the USATEnvelopeHandler with the original message. Developer tip The order of the TLVs given in the USATEnvelopeHandler is not specified so it is recommended to use the ViewHandler.findTLV() methods to get each COMPREHENSION TLV. The EnvelopeResponseHandler is not available. The applet is triggered only if the security according to the 3GPP TS 31.115 specification has been successfully verified by the CAT Runtime Environment. Even if the EnvelopeHandler is available for these events and contains the same data, the usage of the USATEnvelopeHandler is recommended as it provides methods distinguished to handle SMS functionality. EVENT_UNFORMATTED_SMS_PP_ENV2 Upon reception of an unformatted Short Message Point to Point (Single or Concatenated) via the ENVELOPE(SMS-PP DOWNLOAD) APDU command, the CAT Runtime Environment triggers all the Toolkit Applets registered to this event. The applet can get the message using the USATEnvelopeHandler. The Toolkit Applet can post a response using the EnvelopeResponseHandler.post method. Developer tip According to the EnvelopeResponseHandler availability rules only the first triggered applet is guaranteed to be able to send back a response. EVENT_UNFORMATTED_SMS_PP_UPD2 Upon reception of an unformatted Short Message Point to Point (Single or Concatenated) via an UPDATE_RECORD EFSMS, the CAT Runtime Environment updates the EFSMS file, converts the UPDATE_RECORD EFSMS to emulate an ENVELOPE (SMS-PP DOWNLOAD) and fills in the uicc.usim.toolkit.USATEnvelopeHandler, and triggers all the Toolkit Applets registered to this event. Developer tips The order of the TLVs given in the USATEnvelopeHandler is not specified so it is recommended to use the ViewHandler.findTLV methods to get each COMPREHENSION TLV. The EnvelopeResponseHandler is not available. The content of EFSMS may have been modified by a previously triggered Toolkit Applet. EVENT_FORMATTED_SMS_CB2 Upon reception of a formatted Cell Broadcast message via the ENVELOPE (CELL BROADCAST DOWNLOAD) APDU command, the CAT Runtime Environment verifies the security of the Short Message according to the 3GPP TS 31.115 and then triggers the applet registered to this event and having the corresponding TAR. The toolkit can retrieve the message using the uicc.usim.toolkit.USATEnvelopeHandler defined in the 3GPP TS 31.130. The data are provided deciphered. When a Cell Broadcast Message is received as multiple pages as defined in the 3GPP TS 23.041 specification, the CAT Runtime Environment links the different single pages to re-assemble the original message and fills the USATEnvelopeHandler with the original message as a one Cell Broadcast page TLV (the concatenation headers are not present and the TP_elements and TS_ServiceCenterAddress fields are the ones of the last received SMS). EVENT_UNFORMATTED_SMS_CB2
69/192
Upon reception of an unformatted Cell Broadcast message via the ENVELOPE (CELL BROADCAST DOWNLOAD) APDU command, the CAT Runtime Environment triggers all the Toolkit Applets registered to this event. EVENT_CALL_CONTROL_BY_NAA EVENT_MO_SHORT_MESSAGE_CONTROL_BY_NAA2 Upon reception of the ENVELOPE (CALL CONTROL) APDU command or the ENVELOPE (MO_SHORT_MESSAGE_ CONTROL) APDU command the CAT Runtime Environment triggers the Toolkit Applet registered to this event. Regardless of the Toolkit Applet state the CAT Runtime Environment does not allow more than one Toolkit Applet to be registered to this event at a time. In particular, if a Toolkit Applet is registered to this event but not in selectable state the CAT Runtime Environment must not allow another Toolkit Applet to register to this event. When triggered on this event, this applet can define which response shall be sent to the terminal in response to the ENVELOPE (CALL CONTROL) command in order to allow the call, to reject the call or to allow the call but with modification. This is done by the applet using the EnvelopeResponseHandler.post() method or the EnvelopeResponseHandler.postAsBERTLV() method. Developer tip The Call Control resource is shared between the (U)SAT API and the (SAT) API. So - If an applet is registered to Call Control with (U)SIM API, an applet using SIM API can not register to Call Control and vice versa. EVENT_EVENT_DOWNLOAD_MT_CALL EVENT_EVENT_DOWNLOAD_CALL_CONNECTED EVENT_EVENT_DOWNLOAD_CALL_DISCONNECTED EVENT_EVENT_DOWNLOAD_LOCATION_STATUS EVENT_EVENT_DOWNLOAD_USER_ACTIVITY EVENT_EVENT_DOWNLOAD_IDLE_SCREEN_AVAILABLE EVENT_EVENT_DOWNLOAD_CARD_READER_STATUS EVENT_EVENT_DOWNLOAD_LANGUAGE_SELECTION EVENT_EVENT_DOWNLOAD_BROWSER_TERMINATION EVENT_EVENT_DOWNLOAD_NETWORK_SEARCH EVENT_EVENT_DOWNLOAD_BROWSING_STATUS EVENT_EVENT_DOWNLOAD_ACCESS_TECHNOLOGY_CHANGE EVENT_EVENT_DOWNLOAD_DISPLAY_PARAMETER_CHANGED Upon reception of the corresponding ENVELOPE (Event Download) APDU command, the CAT Runtime Environment triggers all the Toolkit Applets registered to the corresponding event. EVENT_EVENT_DOWNLOAD_DATA_AVAILABLE EVENT_EVENT_DOWNLOAD_CHANNEL_STATUS Upon reception of the corresponding ENVELOPE (Event Download) APDU command, the CAT Runtime Environment only triggers the Toolkit Applet registered to the corresponding event with the associated channel identifier. The applet registers to these events using the ToolkitRegistry.setEvent method but the registration is effective only once the Toolkit Applet has issued a successful OPEN CHANNEL proactive command, and is valid until the first successful CLOSE CHANNEL with the corresponding channel identifier, or the end of the card session. When a Toolkit Applet sends an OPEN CHANNEL proactive command and receives a TERMINAL RESPONSE with General Result = 0X, the framework assigns the channel identifier to the calling Toolkit Applet. When a Toolkit Applet sends a CLOSE CHANNEL proactive command and receives a TERMINAL RESPONSE with General Result =0X, the framework releases the corresponding channel identifier. Developer tip
70/192
In case of channel drop, we recommend to explicitly close the channel using the CLOSE CHANNEL command prior to open it again using the OPEN CHANNEL command. In this case, it is also recommended to catch the exception that can be thrown by the CAT Runtime Environment when the applet closes the channel. EVENT_EVENT_DOWNLOAD_LOCAL_CONNECTION Upon reception of an ENVELOPE (DOWNLOAD LOCAL CONNECTION) APDU command, the CAT Runtime Environment only triggers the Toolkit Applet registered to this event with the associated service identifier. The applet registers to the event by calling the method ToolkitRegistry.allocateServiceIdentifer. The applet can deregister by calling the method ToolkitRegistry.releaseServiceIdentifer. Once the applet has allocated a service, it issues the proactive command DECLARE SERVICE to add or delete a service to the mobile service database. The registration to this event is effective once the Toolkit Applet has issued a successful DECLARE SERVICE (add) proactive command, and is valid until the first successful DECLARE SERVICE (delete) with the corresponding service identifier, or the end of the card session. EVENT_PROACTIVE_HANDLER_AVAILABLE The CAT Runtime Environment triggers all the Toolkit Applets registered to this event when the ProactiveHandler is available and all the Toolkit Applets registered to the previous event have been triggered and have returned from the processToolkit invocation. When a Toolkit Applet is triggered, it is automatically deregistered from this event by the CAT Runtime Environment. Developer tip When the Toolkit Applet is triggered on this event, the EnvelopeHandler is not available. We advise that the Toolkit Applet stores the handler data before registering to this event. EVENT_APPLICATION_DESELECT When an application session is terminated, the CAT Runtime Environment triggers all the Toolkit Applets registered to this event. The AID of the deselected application is available to the Toolkit Applet in the EnvelopeHandler. Interoperability issue The SIM Alliance members agree that this event is triggered when a first level application including NAA is deselected and independently by the used logical channel. In case of card reset, the CAT Runtime Environment may not trigger the event. EVENT_FIRST_COMMAND_AFTER_ATR Upon reception of the first APDU after the ATR and before the Status Word of the processed command has been sent back by the UICC, the CAT Runtime Environment triggers all the Toolkit Applet(s) registered to this event. If the first APDU received is a Toolkit Applet triggering APDU (e.g. TERMINAL PROFILE), the Toolkit Applets registered to the event EVENT_FIRST_COMMAND_AFTER_ATR are triggered before the one registered to the event EVENT_TERMINAL_PROFILE if any. The ProactiveHandler is not available as the CAT session is not open. EVENT_UNRECOGNIZED_ENVELOPE Upon reception of an unrecognized ENVELOPE APDU command, the CAT Runtime Environment triggers all the Toolkit Applet(s) registered to this event. An ENVELOPE APDU command is considered as unrecognized by the CAT Runtime Environment if its BER-TLV tag is not defined in the ToolkitConstants interface. Only the first triggered Toolkit Applet is guaranteed to be able to post a response. EVENT_EXTERNAL_FILE_UPDATE Upon successful execution of an UPDATE BINARY or UPDATE RECORD or INCREASE APDU or SET DATA command (sent by the Terminal and received by the UICC on the I/O line), the CAT Runtime Environment triggers all the Toolkit Applets registered to this event with the associated updated file. An Applet is only triggered once per command. For BER TLV files, EVENT_EXTERNAL_FILE_UPDATE is generating after a successful update of a TLV inside the file. This is done by sending one or more SET DATA APDUs. If the APDUs are successful, the TLV is updated actually and the event is generated in the last SET DATA APDU.
The Toolkit Applet can get the details of the file update by reading the EnvelopeHandler. The details of the content of the EnvelopeHandler are defined in the ETSI TS 102 241 specification. The applet registers to this event using one of the ToolkitRegistry.registerFileEvent methods with the indication of the file or the file list that should be monitored.
71/192
The applet can deregister for a particular file using one of the ToolkitRegistry.deregisterFileEvent methods. A call to the ToolkitRegistry.clearEvent(EVENT_EXTERNAL_FILE_UPDATE) clears the registration to the event EVENT_EXTERNAL_FILE_UPDATE for all the registered files. Developer tip The order of the TLVs in the EnvelopeHandler is not specified so it is recommended to use the ViewHandler.findTLV() methods to get each COMPREHENSION TLV. The value of the File Update Information tag is 3B (BER-TLV tag for intra-UICC communication as defined in the ETSI TS 101 220 specification) When calling one of the methods ToolkitRegistry.registerFileEvent() or ToolkitRegistry.deregisterFileEvent(), the value of the fileEvent parameter should be set to EVENT_EXTERNAL_FILE_UPDATE (as it is the only standardized one at the moment). Interoperability issue It is not interoperable if the event EVENT_EXTERNAL_FILE_UPDATE is generated on a specific file also in case of updating of a file mapped with that file. Even if the uicc.access.bertlvfile package is not supported in the UICC, successful SET DATA APDU(s) update on BER-TLV file will trigger the event EVENT_EXTERNAL_FILE_UPDATE.
The send method may throw the exception COMMAND_NOT_ALLOWED if the Proactive command to be sent or one of its parameter is not allowed by the CAT Runtime Environment: The CAT Runtime Environment checks the content of ProactiveHandler:
72/192
The CAT Runtime Environment prevents the Toolkit Applet from sending the following system proactive commands: SET UP MENU, SET UP EVENT LIST, POLL INTERVAL, POLLING OFF. The CAT Runtime Environment prevents a Toolkit Applet from sending a TIMER MANAGEMENT proactive command using a timer identifier, which is not allocated to it. The CAT Runtime Environment prevents a Toolkit Applet from sending a DECLARE SERVICE (add, delete) proactive command using a service identifier, which is not allocated to it. The CAT Runtime Environment prevents a Toolkit Applet from sending a SEND DATA, RECEIVE DATA and CLOSE CHANNEL proactive commands using a channel identifier, which is not allocated to it. The CAT Runtime Environment prevents a Toolkit Applet from sending an OPEN CHANNEL proactive command if it exceeds the maximum number of channel allocated to this applet. All the proactive commands are sent to the terminal as constructed by the Toolkit Applet without any check by the CAT Runtime Environment. Developer tips Several methods are defined in the ProactiveHandler class to simplify the building of some proactive commands: initDisplayText(), initGetInkey(), initGetInput(), initCloseChannel() and initMoreTime(). At the send method invocation, a pending Toolkit Applet transaction is aborted. If an applet wants to use the SET UP IDLE MODE TEXT proactive command, the CAT Runtime Environment cannot guarantee that another Toolkit Applet will not overwrite this text later on. Example: byte[] String = {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o'} ; /** * Send a DISPLAY TEXT. */ ProactiveHandler proHdlr = ProactiveHandlerSystem.getTheHandler() ; proHdlr.initDisplayText( (byte)0, (byte)0x04, String, (short) 0, (short) String.length) ; proHdlr.send() ;
73/192
ProactiveResponseHandler content is updated after each successful call to ProactiveHandler.send() method and remains unchanged until the next successful call to the ProactiveHandler.send() method.
74/192
EF PL
DF TELECOM
EF ICCID
EF1
EF2
EFx
ADF2
ADF1
EF1
EF2
DF1
EFy
EF1
EF2
DF1
EFz
EF3
EF4
EF3
EF4
EF5
10.7.2.1
FileView objects
The access to the file system is handled using FileView objects, either a UICC FileView object or an ADF FileView object: The UICC FileView object allows accessing the MF and all the DFs and EFs that are located under the MF including DFTELECOM. The access to the DFs or EFs under any ADF is not allowed. The UICC FileView object can be retrieved using the method UICCSystem.getTheUICCView(). An ADF FileView object allows accessing only the DFs and EFs that are located under the ADF but not the DFs or EFs under the MF. An ADF FileView object can be retrieved using one of the methods UICCSystem.getTheFileView(...) by passing the full AID of the application owning the ADF as parameter (for example the full AID of the (U)SIM application). Developer tips The AIDs of the applications owning an ADF and available on a UICC are listed in the EFDIR file under the MF (see the ETSI TS 102 221 specification for the description of the EFDIR content). The only way to access the DF GSM is to use the UICC FileView object. The access to the SIM file system defined in the 3GPP TS 51.011 is available using the UICC FileView object. It is recommended to call the getTheFileView(...) or getTheUICCView() methods in the applet constructor, as they are memory consuming. Each time the getTheFileView(...) or getTheUICCView() methods are called, a new FileView object is created (as a permanent JCRE entry point object).
75/192
A separate and independent file context3 is associated to each FileView object: the operation performed on files in a given FileView object shall not affect the file context associated with any other FileView object. After the applet termination, the context (current selected file, etc) may remain depending on the object type and can be retrieved during the next applet execution. The context can be transient or persistent depending on what was required by the Applet during the creation of the FileView object (event parameter of the getTheFileView() or getTheUICCView() methods). The root of the context of a FileView object is the MF for the UICC FileView or the ADF for an ADF FileView. At the creation of a FileView object or when the transient context of a FileView is cleared, the current DF of the FileView's context is set to the root. The access control privileges associated with each FileView object is given by the Access Domain of the Toolkit Applet during its installation phase. The Access Domain of the Toolkit Applet is defined in the UICC Access Application specific parameter field of the install (for install) command (tag value 81). A Toolkit Applet can have an Access Domain relative to the access to the UICC file system part and an Access Domain for each ADF file system part. The access domain for the UICC file system part is associated to the UICC FileView objects; the access domain for an ADF file system part is associated to the ADF FileView objects relative to this ADF. Each time a method of the FileView object is invoked, the access control privilege of the FileView object is verified against the access rules of the given DF/EF as described in the ETSI TS 102 221.
10.7.2.2
FileView
operations
The different methods defined in the FileView interface are select(): selects a file or a directory using the file ID or the SFI. status(): returns the FCP of the current selected DF readBinary(): reads the content of the current transparent EF readRecord(): reads a record or a part of a record of the current linear fixed/cyclic EF updateBinary(): updates the content of the current transparent EF updateRecord(): updates a record or a part of a record of the current linear fixed/cyclic EF searchRecord(): searches a pattern in the current linear fixed/cyclic EF increase(): increases the current record of the current cyclic EF activateFile(): activates the currently selected EF deactivateFile(): deactivates the currently selected EF These methods implement in fact the same functionality as the SELECT, STATUS, READ BINARY, READ RECORD, UPDATE BINARY, UPDATE RECORD, SEARCH RECORD, INCREASE, ACTIVATE, DEACTIVATE commands defined in the ETSI TS 102 221 specifications. Developer tips When a non-shareable file is selected using one of the select() methods, this file is no more accessible by other applets, by the Remote File management application or by terminal operations. Furthermore when a non-shareable file is selected by the mobile, this file is no longer accessible for any other application. The file is accessible again when the application selects another file. If the FileView context is transient, the file becomes also accessible when the context is cleared. The reserved FID '7FFF' can be used as a FID for the ADF to select the root of an ADF FileView object When selecting a cyclic file the current record number is undefined.
The file context includes at least information about the current DF, the current EF and the current record (for linear fixed or cyclic files).
76/192
10.7.3.1
AdminFileView
objects
The administrative access to the file system is handled using AdminFileView objects. Two AdminFileView objects are available, one for the UICC file system administration and one for an ADF file system administration: The UICC AdminFileView object allows administrating the EFs and DFs under the MF. The UICC AdminFileView object can be retrieved using the method getTheUICCAdminFileView(...) defined in the AdminFileViewBuilder class. An ADF AdminFileView object allows administrating only the DFs and EFs that are located under the ADF. An ADF AdminFileView object can be retrieved using one of the methods getTheAdminFileView(...) with passing the full AID of the application owning the ADF as parameter (for example the full AID of the (U)SIM application). The getTheAdminFileView(...) methods are defined in the AdminFileViewBuilder class. The AdminFileView interface inherits of the FileView interface and the AdminFileView objects follows the behavior of the FileView objects: the associated context can be persistent or transient; the context initialization rules are the same, etc. The access control privileges associated to each AdminFileView object is given by the Administrative Access Domain of the Toolkit Applet during its installation phase. The Administrative Access Domain of the Toolkit Applet is defined in the UICC Administrative Access Application specific parameter field of the install (for install) command (tag value 82). A Toolkit Applet can have an Administrative Access Domain relative to the access to the UICC file system part and an Administrative Access Domain for each ADF file system part. The Administrative Access Domain for the UICC file system part is associated to the UICC AdminFileView objects; the Administrative Access Domain for an ADF file system part is associated to the ADF AdminFileView objects relative to this ADF. Each time a method of the AdminFileView object is invoked, the access control privilege of the AdminFileView object is verified against the access rules of the given DF/EF as described in the ETSI TS 102 221.
10.7.3.2
AdminFileView
operations
The different methods defined in the AdminFileView interface are createFile(): creates a new EF or a new DF under the current DF or ADF deleteFile(): deletes an EF under the current DF or deletes a DF with its complete sub-tree. resizeFile(): resize an EF DF under the current DF or ADF These methods implement in fact the same functionality as the CREATE, DELETE and RESIZE commands defined in the ETSI TS 102 222 specifications. The details of the different methods are defined in the ETSI TS 102 241. If EF or DF file already exists, or if memory is not available for creation, then an AdminException is thrown.
77/192
Developer tip The createFile() and resizeFile() methods uses a ViewHandler object to define a data field identical to the one used for the CREATE and RESIZE commands. The uicc.system.HandlerBuilder.buildTLVHandler() method is useful to create a ViewHandler object. The TLV content can be set either when creating the ViewHandler object or later on. In this case the handler can be cast to an EditHandler and then filled with the TLV content. To avoid memory allocation during lifecycle of the applet, it is recommended to invoke the buildTLVHandler() method in the constructor of the applet. The AdminFileView interface inherits of the FileView interface so all methods such as select(), readBinary() and so one are also available. When the deleteFile()method is invoked, SIM Alliance members agree that they all provide mechanisms to recover memory space but the implementation of this features can be different for the SIM Alliance members.
private byte [] fileDescriptor = { (byte)0x42,(byte)0x21,(byte)0x00,(byte)0x04}; // File Descriptor: EF linear fixed, record length 4 private short fileId = (short)0x8302; // File Id private byte LCSI = (byte)0x05; // LCSI activated private byte [] securityAttribute = { (byte)0xAC,(byte)0x00, // Security attribute (EF Arr) (byte)0x01,(byte)0x01, // Security attribute (SD 1, record nb) (byte)0x00,(byte)0x01}; // Security attribute (SD 0, record nb) private short fileSize = 0x0064; // File Size (25 rec * 4 bytes = 100) private byte [] sfiTLV = { (byte)0x88,(byte)0x00};
AdminFileView adminFileView= AdminFileViewBuilder.getTheUICCAdminFileView(JCSystem.CLEAR_ON_RESET) ; // Select the MF adminFileView.select((short)0x3F00); // Create EF AF80 createCmd = HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER, (short )255); createCmd.appendTLV((byte)0x82, fileDescriptor, (short)0x00, (short)fileDescriptor.length); createCmd.appendTLV((byte)0x83, fileId); createCmd.appendTLV((byte)0x8A, LCSI); createCmd.appendTLV((byte)0x8B, securityAttribute, (short)0x00, (short)securityAttribute.length); createCmd.appendTLV((byte)0x80, fileSize); createCmd.appendArray(sfiTLV, (short)0x00, (short) sfiTLV.length); adminFileView.createFile(createCmd);
10.7.4.1
BERTLVFileView
operations
78/192
The interface uicc.access.bertlvfile.BERTLVFileView extends the interface uicc.access.FileView, i.e. objects implementing the interface BERTLVFileView inherit FileView functionality. If BER TLV files functions are supported in the UICC, the getTheFileView() and getTheUICCView() methods defined in the UICCSystem class shall return the reference of an object implementing the BERTLVFileView interface. The methods defined in the AdminBERTLVFileView to access BER-TLV files are deleteData(): for deleting a data object in the current BER-TLV structure EF. getTAGList(): for getting the list of TAGs already allocated in the current BER-TLV structure EF. retrieveData(): for retrieving a part of a data object from the current BER-TLV structure EF. setData(): for setting a data object in the current BER-TLV structure EF.
10.7.4.2
AdminBERTLVFileView
operations
The AdminBERTLVFileView interface defines the administrative methods for administrating BER TLV files. If BER TLV files functions are supported in the UICC, the getAdminFileView() and getTheUICCAdminFileView() methods defined in the AdminFileViewBuilder class shall return the reference of an object implementing the AdminBERTLVFileView interface.
10.8 Short Messages and their handling with the USIM API
10.8.1 Single SMS-PP
There are two ways for card to receive a single Short Message Point to Point: through an ENVELOPE (SMS_PP_DOWNLOAD) APDU, or through an UPATE_RECORD EFSMS APDU. The received message can be: Formatted accordingly to identify explicitly a toolkit application (see chapter Structure of the Command Packet) Unformatted and send data to all registered toolkit application.
When receiving an envelope APDU containing an formatted SMS_DOWLOAD, the USIM Toolkit Framework: Verifies the security of the short message, Triggers the Toolkit Applet registered to EVENT_FORMATTED_SMS_PP_ENV, and with corresponding TAR, Takes the optional Application Data posted by the triggered toolkit application if present, Secures and sends response packet using SMS-DELIVER-REPORT or SMS-SUBMIT according the SPI byte 2 When the applet is triggered, the data of short message in the TLV structure are deciphered. When receiving an envelope APDU containing an Unformatted SMS_DATADOWNLOAD BER simple TLV, the USIM Toolkit Framework triggers all the toolkit applications registered to the EVENT_UNFORMATTED_SMS_PP_ENV.
79/192
TPUD Data
When receiving a formatted UPDATE RECORD EFSMS, the USIM Toolkit Framework: Updates the EFSMS file with the data received; it is then up to the receiving Toolkit Applet to change the SMS stored in the file, if the applet has the access right, Verifies the security of the Short Message, Triggers the Toolkit Applet registered to EVENT_FORMATTED_SMS_PP_UPD and with corresponding TAR. Converts the Update Record EFSMS into a TLV List:
In the Device Identities field, record number is absolute, so that the applet can update EFSMS in absolute mode (e.g. a readable text). In the TS-SCA field, the value of the TS-Service-Centre-Address is the one of the last Update Record EFSMS If the EFSMS file updated is under an ADF file, then an AID TLV can be added in the USAT EnvelopeHandler. The value of the AID TLV, is the AID of the ADF:
AID Tag AF Length XX Value ADF AID
The order of the TLV in the EnvelopeHandler is not specified. The USAT EnvelopeHandler, handlers by the Toolkit Applet returns The BTAG_SMS_PP_DOWNLOAD to the getEnvelopeTag method, the length of the TLV structure defined above to the getLength method. When receiving an Unformatted UPDATE RECORD EFSMS, the USIM Toolkit Framework: Updates the EFSMS file with the data received; Convert the UPDATE RECORD EFSMS APDU data into a TLV list as described for formatted Update Record, Trigger all toolkit applications registered to the EVENT_UNFORMATTED_SMS_PP_UPD.
As for single Short Message, it is possible for card to receive multiple short messages via an ENVELOPE (SMS_PP_DOWNLOAD) APDU, or via an UPATE_RECORD EFSMS APDU. The received message can be: Formatted accordingly to identify explicitly a toolkit application (see chapter Structure of the Command Packet) and send the data to it Unformatted and send data to all registered toolkit application.
10.8.2.2
When Short Message are received concatenated, the USIM Toolkit framework re-assembles the original message before any further processing, and places in one SMS TPDU TLV (with TP-UDL field coded on one byte) included in the USAT
80/192
EnvelopeHandler. The concatenation control headers used to re-assemble the short messages in the correct order are not present in the SMS TPDU.
The TP-elements of the SMS TPDU and the Address (TS-Service-Centre-Address) correspond to the ones in the last received Short Message (independently of the Sequence number of Information-Element-Data). The minimum requirement for the USIM Toolkit Framework is to process a concatenated short message with the following properties: The Information Element Identifier is equal to the 8-bit reference number. It contains uncompressed 8 bit data and additionally the DCS shall be set to Class 2.
81/192
Tag D1
Length XX Tag 82
3GPP-SMS TPDU (DELIVER) 3GPP TS 23.040 TPUDL 3GPP TS 31.115 TPUD Deciphered Data
TPUD First SMS UDHL IEIa (CPI) IEIDL a CPL CHL SPI Kic KID TAR CNTR PCNTR RC/CC/ DS SMS 1 SMS n Last SMS
10.8.2.3
After reassembles appropriately the different short message, the USIM toolkit framework trigger all applets registered to the event EVENT_UNFORMATTED_SMS_PP_ENV.
UDHL 00
SMS 1
SMS n
82/192
In the Device Identities field, Absolute Record Number and Record Status correspond to the last Update Record EFSMS APDU received. In the TS-SCA, fields correspond to the last Update Record EFSMS APDU received. An AID TLV can be present in the structure of the USAT, if EFSMS file is under an ADF. The value of AID TLV is the AID of the ADF. AID Tag AF Length XX Value ADF AID
When receiving an unformatted UPDATE RECORD EFSMS, the USIM Toolkit Framework: Updates the EFSMS file with the data received; Converts the UPDATE RECORD EFSMS APDU data into a TLV list as described for formatted Update Record, Triggers all toolkit applications registered to the EVENT_UNFORMATTED_SMS_PP_UPD.
10.8.5.1
When the card receives a formatted Short Message Cell Broadcast page, the Operating System: verifies the security of the message, triggers the Toolkit Applet registered to the event EVENT_FORMATTED_SMS_CB, with the corresponding TAR. Structure of the USATEnvelopeHandler:
83/192
Tag D2
Len Xx
10.8.5.2
When the card receives an unformatted Short Message Cell Broadcast page, the USIM Toolkit application triggers all Toolkit Applets registered to the event EVENT_UNFORMATTED_SMS_CB. Structure of the USATEnvelopeHandler:
Tag D2 Len Xx Device Identities Tag 82 Len 02 Src 83 Ds t 8 1 Tag 8C Len xx xx SN xx 1 0 Cell Broadcast Page MI 0 0 DCS 56 PP 00 data
10.8.6.1
When the card receives formatted multiple Short Message Cell Broadcast, the Operating System: verifies the security of the message, decrypts the message, triggers the Toolkit Applet registered to EVENT_FORMATTED_SMS_CB, with the corresponding TAR. Structure of the USATEnvelopeHandler:
Tag D2 Len Xx Device Identities Tag 82 Len 02 Src 83 Ds t 8 1 Tag 8C Len xx xx Cell Broadcast Page SN xx 1 0 MI 8 0 DCS 56 PP 2 2 CPL CHL 3GPP TS 31.115 SPI to RC/CC/DS Secured data Sm1 Sm n
First SM CB Last SM CB
10.8.6.2
When the card receives unformatted multiple Short Message Cell Broadcast, the Operating System triggers all Toolkit Applets registered to the event EVENT_UNFORMATTED_SMS_CB. Structure of the USAT Envelope Handler:
84/192
Tag D2
Len Xx
85/192
11 The phonebook
The aim of this chapter is to highlight some key features of the phonebook defined for the USIM application in 3GPP TS 31.102.
Alpha String
EFEXT1 Extension 1 Extension data for the main dialing number or for an additional number. Extension data are required: - If the coding of the dialing number is greater than the 20-digit capacity of EFADN or EFANR or if common digits are required to follow a dialing number of less than 20 digits (DTMF string). - To define a called party sub address. Network and bearer capabilities, and mobile equipment settings to establish the call (using the main dialing number or an additional number) Email address of the contact Second name of the contact List of groups to which the contact belongs Alpha strings of the different groups
Capability Configuration Parameters 1 Email Address Second Name Entry Grouping File Grouping Information Alpha String
The only mandatory file is the file EFADN. The other files used to define the different fields of a phonebook entry are optional. Their presence depends on the structure required for the phonebook. For example, it is possible to attach none, one or several email addresses, additional numbers or second names to a contact. In this case none, one or several files EFEMAIL, EFANR and EFSNE are defined. The different type of file linking
86/192
The number of records in a field file may be less than the number of records in the file EFADN. Several types of links are available to link all the field files to the EFADN. Three types of file links are defined: The file link type 1: the field file contains as many records as the master EFADN file. The file link type 2: the field file contains fewer records than the master EFADN file. The link is done using a pointer defined in the EFIAP administration file. The file link type 3: the record identifier of the field file is defined in the record of the master file. For example if an extension is required for a record in EFADN, the record identifier in the EFEXT1 file is defined in the record of EFADN itself. The different types of file linking allowed for a specific file are defined in the 3GPP TS 31.102 specification. According to the current version of the 3GPP TS 31.102 specification, only Type 3 files can contain records that can be shared between several contacts. How to retrieve the different fields of a contact? The configuration of the phonebook is defined in the EFPBR file. The entry point for a contact is the EFADN file. Once the record in EFADN is identified, the other fields are retrieved in the different files according to the type of linking: Directly by reading the same record number in the field file, if this file is linked with a Type 1 linking By reading the right pointer in the same record number of the EFIAP file, if this field file is linked with a Type 2 linking. The value of the pointer gives the record number in the field file. Directly by reading the record number of the field file in the record itself, if this file is linked with a Type 3 linking Creation/Deletion of information In order to avoid unlinked data to introduce fragmentation of the files containing the phonebook, a specific procedure shall be followed when creating a new entry in the phonebook or when deleting a complete or part of an entry. Refer to the chapter Phone book procedures of the 3GPP TS 31.102 specification for details.
87/192
smith@home
ADN 1
#152 SMITH 062233 #21 #2 #152 #25
IAP 1
#10 #10
EMAIL 1
smith@home #152
200 PBR
#2 #152 #3
200 100
EXT1 1
GRP 1
#1 #25 #5
ANR 1
049999 #152
5 CCP1 1
#21 #1 #3
200 GAS 1
business friend #5
30 AAS 1
HOME
20
10
88/192
89/192
90/192
sim.access
2G Yes
uicc.access
3G
uicc.access
3G
12.10
Its declared as not specified, and so it is not interoperable, applet behavior in case of usage of both SIM APIs and USIM APIs.
91/192
It is recommended to develop application by using USIM APIs also in case of 2G functionalities, in order to take advantage of all the enhanced features of the USIM APIs.
12.10.1
Terminal Profile
The terminal profile info provided by the ME are given to 2G applet in the MEProfile object and to the 3G applets in the TerminalProfile object. Both objects have the same content. As many features have been made mandatory for 3G ME, the relevant bits in the Terminal Profile are set to 1 in 102 223. When a 3G card is inserted in a 2G terminal, the bit verification of these features should be checked according to 51.014 also by 3G applets.
12.10.2
The 2G applets and the 3G applets are not triggered on the same Toolkit Interface. The SAT ones are triggered on sim.toolkit.ToolkitInterface. The USAT applets are triggered on uicc.toolkit.ToolkitInterface. The triggering order for applets will only depends on the priority level defined during the loading stage of the applet, independently of the applet type. When a USIM is the current application or when there is no application selected, the SIM Toolkit Framework generates events based on APDUs defined in TS 102 221 and TS 31.102 in order to trigger an applet. Example ENVELOPE (MENU SELECTION) defined in TS 102 223 with class byte 0x80 should trigger SAT applets registered to EVENT_SELECTION_MENU). 2G and 3G applets share the same card resources. Example As an example, if a USAT applet is registered to Call Control, an applet using SIM API can not be registered on Call Control. Moreover, if a Timer is allocated with a SIM API, it can not be allocated with a USIM API.
12.10.3
The EnvelopeResponseHandler is available for all triggered applets (SAT and USAT) when available for the event. An envelope response or a sent proactive command, using specific applet API, has to be posted by the applet. Also, the ProactiveHandler may not be available, for SAT and USAT applets, if a proactive command is pending (see TS 43.019, TS 102 241 and TS 31.130). Note The system proactive commands generated by the Toolkit Framework are independent of the current NAA. The only exception is identified for the SET UP MENU proactive command. In fact two EFSUME files can be created (one under DFGSM and one under DFTELECOM) and can be different (alpha and icon identifiers). The Toolkit Framework generates the same SET UP MENU proactive command if files are mapped (see Error! Reference source not found.)
12.10.4
Developer tip SAT Applets can access to the functions and data described in TS 51.011 and TS 11.14, if the current application is the SIM one. New features defined for proactive commands in TS 31.111 are not available for SAT applets. Moreover, new events introduced in UICC/USAT API are not available for SAT applets (e.g. EVENT_DOWNLOAD_DISPLAY_PARAMETER_CHANGE, EVENT_EXTERNAL_FILE_UPDATE).
92/192
93/192
Variable
If the SPI byte 2 of the incoming message indicates that RC, CC or DS is performed on Response Packet, the fields included are: TAR field, Counter field, Padding Counter field, Status Code field, Additional Response data field. RPI, RPL, RHI and RHL may be implemented for the signature computation. If the SPI byte 2 If If If If of the incoming message indicates that cipher is applied on Response Packet, the fields included are: Counter field, Padding Counter field, Status Code field, RC/CC/DS field computed, Additional Response data field.
ciphering is performed, first the RC/CC/DS is calculated, and then ciphering is applied. the SPI byte 2 of the incoming message indicates that a specific field is unused, then the content field is set to zero. the SPI byte 2 of the incoming message indicates that no RC; CC or DS is used, then the field is not present. the Padding Counter content is zero, this indicates no padding octets, or no padding is necessary.
13.1.2.1
The Toolkit Application Reference (TAR) is the same as the one defined in the incoming Formatted Message and is automatically provided by the framework.
13.1.2.2
Counter.
The Counter (CNTR) is the same as the one defined in the incoming formatted message and is automatically provided by the framework.
13.1.2.3
This information is automatically provided by the framework in the event of an error in the incoming Formatted Message. The value of this byte is defined in the following table.
94/192
Status Code 00 01 02 03 04 05 06 07
Meaning PoR correct. RC/CC/DS failed. CNTR low. CNTR high. CNTR blocked Encryption error. Unidentified security error. This code occurs when the receiving entity cannot correctly interpret the command header, and the response packet is sent unencrypted with no RC/CC/DS. Insufficient memory to process the incoming message. The meaning of this status code depends on the card manufacturer.
08
This more time status code should be used if the receiving entity/application needs more time to process the command packet due to time constraints. In this case, a later response packet should be returned to the sending entity once processing has been completed. TAR unknown Insufficient security level Actual response data to be sent using SMS-SUBMIT Actual response data to be sent using a ProcessUnstructuredSS-Request invoke component (i.e. using Send USSD proactive command). See section 15.1.2.4 Reserved for future use. Reserved for proprietary use. Reserved for future use.
95/192
0: No Ciphering 1: Ciphering 00: No counter available (note 1) 01: Counter available; no replay or sequence checking (note 2) 10: Process if and only if counter value is higher than the value in the RE (note 3) 11: Process if and only if counter value is one higher than the value in the RE (note 4) Reserved (set to zero and ignored by RE) NOTE 1: In this case the counter field is present in the message. NOTE 2: In this case the counter value is used for information purposes only, (e.g. date or time stamp). If the Command Packet was successfully unpacked, the counter value can be forwarded from the Receiving Entity to the Receiving Application. This depends on proprietary implementations and happens in an application dependent way. NOTE 3: The counter value is compared with the counter value of the last received Command Packet. This is tolerant to failures on the transport level (i.e. losses of Command Packets). A possible scenario is a global update. NOTE 4: This provides strict control in addition to security indicated in note 3.
96/192
No PoR reply to the Sending Entity (SE) PoR required to be sent to the SE PoR required only when an error has occurred Reserved No RC, CC or DS applied to PoR response to SE PoR response with simple RC applied to it PoR response with CC applied to it PoR response with DS applied to it
0: PoR response shall not be ciphered 1: PoR response shall be ciphered Reserved for 3GPP TS 31.115. Reserved (set to zero and ignored by RE) If RC, CC or DS is applied to the Command Packet i.e. SPI1.b2b1 is different from '00' and if RC, CC or DS is applied to the Response Packet i.e. SPI2.b4b3 is different from 00, then SPI2.b4b3 is set to the same value as SPI1.b2b1. Interoperability issue There is no definition, and so interoperability, about the Digital Signature functionality in the RC/CC/DS field. If the Security Parameter Indicator indicates that RC/CC/DS is performed, then the following Command Header fields are included in the calculation: SPI field, Kic field, KID field, TAR field, Counter field, Padding Counter field, Secured data field. If the Security Parameter Indicator indicates that ciphering is performed, then the following Command Header fields are included in the calculation: Counter field, Padding Counter field, RC/CC/DS field computed, Secured Data. If ciphering is performed, first the RC/CC/DS is calculated, and then ciphering is applied. If the Padding Counter content is zero, this indicates no padding octets, or no padding is necessary.
97/192
00: Algorithm known implicitly by both entities 01: DES 10: Reserved 11: proprietary Implementations If b2 b1 = 01 (DES), b4 b3 shall be coded as follows: 00: DES in CBC mode 01: Triple DES in outer-CBC mode using two different keys 10: Triple DES in outer-CBC mode using three different keys 11: DES in ECB mode If b2 b1 = 10, b4 and b3 coding is reserved. Indication of Keys to be used (keys implicitly agreed between both entities) DES is the algorithm specified as DEA in ISO 8731-1. DES in CBC mode is described in ISO/IEC 10116. Triple DES in outer-CBC mode is described in clause 15.2 of ISBN 0-471-12845-7. DES in ECB mode is described in ISO/IEC 10116. The initial chaining value for CBC modes shall be zero. For GlobalPlatform security architecture compliant cards see 22.
14.1.2.1
If b2b1= 10 (Cryptographic Checksum) in the first byte of SPI, KID is coded as following:
00: Algorithm known implicitly by both entities 01: DES 10: Reserved 11: proprietary Implementations If b2 b1 = 01 (DES), b4 b3 shall be coded as follows: 00: DES in CBC mode 01: Triple DES in outer-CBC mode using two different keys 10: Triple DES in outer-CBC mode using three different keys 11: Reserved If b2 b1 = 10, b4 and b3 coding is reserved. Indication of Keys to be used (keys implicitly agreed between both entities) DES is the algorithm specified as DEA in ISO 8731-1. DES in CBC mode is described in ISO/IEC 10116. Triple DES in outer-CBC mode is described in clause 15.2 of ISBN 0-471-12845-7. The initial chaining value for CBC modes shall be zero. If padding is required, the padding octets are coded hexadecimal '00'. These octets are not be included in the secured data.
14.1.2.2
If b2b1= 01 (Redundancy Check) in the first byte of SPI, KID is coded as follows:
98/192
00: Algorithm known implicitly by both entities 01: CRC 10: Reserved 11: proprietary Implementations If b2b1= 01 (CRC), b4b3 shall be coded as follows: 00: CRC 16 01: CRC 32 10 to 11: Reserved If b2b1 = 10, b4 and b3 coding is reserved. For Proprietary use or For GlobalPlatform security architecture compliant cards: indication of Keys to be used CRC algorithm is specified in ISO/IEC 10239. The generator polynomial used for CRC 16 is
x16 + x12 + x 5 + 1 .
The generator polynomial used for CRC 32 is
It is not mandatory for a second level application to have a TAR value assigned. In this case it is not possible to trigger such application with a formatted Short message. The TAR value for an application may be either assigned by using the AID or the TAR Value Field in the INSTALL [for install] command. Interoperability issue: It is not specified if the TAR inside the AID is assigned to an application if no toolkit parameter is specified for that application.
99/192
If in the first SPI byte b4b5 = 00 (No counter available) the five byte counter must be present in the command packet, but it is ignored by the RE and the RE does not update the counter. If b5 of the first SPI byte is equal to 1 then the following rules shall apply to counter management, with the goal of preventing replay and synchronization attacks: The SE sets the counter value. It is only incremented. The RE shall update the counter to its next value upon receipt of a Command Packet after the corresponding security checks (i.e. RC/CC/DS and CNTR verification) have been passed successfully. The next counter value is the one received in the incoming message. When the counter value reaches its maximum value the counter is blocked. If there is more than one SE, care has to be taken to ensure that the counter values remain synchronized between the SEs to what the RE is expecting, irrespective of the transport mechanism employed. The level of security is indicated via the proprietary interface between the Sending/Receiving Application and Sending/Receiving Entity. Application designers should be aware that if the Sending Application requests "No RC/CC/DS" or "Redundancy Check" and "No Counter Available" from the SE, no security is applied to the Application Message and therefore there is an increased threat of a malicious attack.
14.4 PCNTR
Indicates the number of padding octets used for ciphering at the end of the secured data.
100/192
15 Data Download
There are several standardized ways to download data to the UICC: Short Message Service Point-to-Point (SMS-PP) single and concatenated Short Message Service Cell Broadcast (SMS-CB) single and concatenated Card Application Toolkit Transport Protocol (CAT_TP) These mechanisms can be used to trigger a Toolkit Application or to manage the card remotely. As the bearers mentioned above are only used for transport purposes, it is recommended to use the security protocol defined in ETSI TS 102 225 on top of them In general each data download follows the structure described below:
APDU
Transport Protocol
Data
If security has to be applied to a data download, the data download is structured as described in the figure below:
APDU
Transport Protocol
Security
Data
The different portions of a data download are specified in the following specifications: APDU: ETSI TS 102 221 Card Application Toolkit: ETSI TS 102 223 and 3GPP TS 31.111 Transport Protocol: Depending on the bearer (please refer to the following chapters) Security: ETSI TS 102 225 and 3GPP TS 31.115.
101/192
Tag (1)
Length (1)
Source (1)
Destination (1)
Tag (1)
Length (1)
TON/NPI (1)
SCA (1 10)
Tag (1)
Length (1 or 2)
SMS TPDU
TON/NPI (1)
TP-PID (1)
TP-DCS (1)
TP-SCTS (7)
TP-UDL (1)
TP-UD
15.1.1.1 General structure of the User Data Header in a Secured Single Short Message Point to Point
If the incoming SMS PP is secured, the coding of the SMS_DELIVER (SC to MS), SMS_DELIVER_REPORT, SMS_SUBMIT (MS to SC), SMS_SUBMIT_REPORT header must indicate that: Secured data are binary (8 bits). For that the DCS (Data Coding Scheme) field should be set appropriately to 16 or to F6 (see for details 3GPP TS 23.038). TP-User-Data field contains a header, in particular a 3GPP TS 31.115 header. For that the TP_UDHI (User Data Header Indicator) bit field, in the MTI (Message-Type-Indicator) field, is set to 1. The User Data Header is part of the TP User Data of the Short Message element.
Bytes
Bytes
IEDLn IEDn
SM (8-bit data)
Byte Boundary
Figure 12 - The UDH in an SM-PP The Command Packet and the Response Packet are partially mapped into the UDH structure. Information Element Identifier (IEIs) value range 70-7F are reserved in 3GPP TS 23.040: 70 and 71 are specified below, 72 7D are reserved for future use,
102/192
If Command Packet and Response Packet are too large to be contained in a single Short Message (including the Command Header or the Response Header), it is concatenated as defined below.
103/192
15.1.1.2
UDHL (1)
IEIa (1)
IEDLa (1)
02
70
00
0D, 11 or 15
optional
The UDH is mapped with the Command Packet Identifier. The CPI identifies the Command Packet and indicates the presence of the Command Packet Length and the Command Header before the Secured Data. The UDHL = 02, The CPI (or IEIa) = 70, The IEDLa = 00 accordingly with 3GPP TS 23.040. The CHI is a null field for SMS-PP. Developer tip When sending a SMS SUBMIT, the applet developer should take care with the length of the secured data, as the length of the Command Packet cannot exceed 140 octets. If the length of the Command packet is greater than 140 octets, then the secured data should be concatenated (see Command Packet contained in Concatenated Short Message Point to Point chapter).
104/192
UDHL 07
IEIa 00
IEILa 03
IEIDa
Seq nb, Ref nb, Nb SM
IEIb 70
IEILb 00
UDHL 05
IEIa 00
IEILa 03
IEIDa
Seq nb, Ref nb, Nb SM
SD SD
If data is ciphered, then they are ciphered before being split into individual concatenated Short Message. The Concatenation Control Header of the UDH in each Short Message is not ciphered. The CPL fields and the CHL field are included in the RC/CC/DS calculation if used.
15.1.1.4 Structure of a Response Packet contained in a Single Short Message Point to Point
The Response Packet is generated by the Receiving Entity, and can contain some data returned by the Receiving Application. In the case where the USIM application is the receiving application, according the value of the bit 6 of the SPI2, the Response packet is: Retrieved by the ME, and included in the User-Data part of the SMS-DELIVER-REPORT, Fetched by the ME after the Send Short message proactive command
15.1.1.5
In the case of a response packet originating from the USIM, the UDHI bit of the response packet SMS is not set, since the USIM cannot notify the ME that it should be set. The sending entity processes the response packet as if the UDHI bit has been set.
105/192
Response Header
CNTR (5) PCNTR (1) RC/CC/DS (0, 4 or 8) Additional Response Data
02
71
00
0A, 0E or 12
conditional
Figure 14 - Response packet structure The UDH is mapped with the Response Packet Identifier. The RPI identifies the Response Packet and indicates the presence of the Response Packet Length and the Response Header before the Secured Data. UDHL = 02, RPI (or IEIa) = 71, and the IEDLa = 00 accordingly with 3GPP TS 23.040. The RHI is a null field for SMS-PP.
Applet developer tips The applet developer should take care with the length of the additional response data, as the length of the Response Packet cannot exceed 140 octets. If the length of the Response Packet is greater than 140 octets, the additional response data should be concatenated (see Response Packet contained in Concatenated Short Message Point to Point chapter).
UDHL 07
IEIa 00
IEILa 03
IEIDa
Seq nb, Ref nb, Nb SM
IEIb 71
IEILb 00
106/192
UDHL 05
IEIa 00
IEILa 03
IEIDa
Seq nb, Ref nb, Nb SM
SD SD
If data is ciphered, then they are ciphered before being split into individual concatenated Short Message. The Concatenation Control Header of the UDH in each Short Message is not ciphered. The RPL fields and the RHL field are included in the RC/CC/DS calculation if used.
15.1.1.7
Concatenated SMS-PP
TP_UDH
Secured Data
TP_UDH1
Secured Data
TP_UDH2
Secured Data
TP_UDH
Secured Data
First concatenated SM
Last Concatenated SM
Comments Indicates the length of the entire SM The first octet of the content or User Data part of the Short Message itself. Length of the total User Data Header includes the length of IEIa + IEIDLa + IEDa + IEIb + IEIDLb + IEDb + Identifies this Header as a concatenation control header defined in 3GPP TS 23.040. Length of the concatenation control header (= 3). These octets contain the reference number, sequence number and total number of messages in the sequence, as defined in 3GPP TS 23.040. Identifies this element as the Packet Identifier.
IEIa
IEIDLa IEDa
'00', indicating concatenated short message Length of Concatenation header 3 octets containing data concerned with concatenation
IEIb
UDH for concatenated Short Message Point to Point The Information Element Data field contains information set by the sending entity so that the receiving entity is able to re-assemble the short message in the correct order. The Information Element Data octets are coded as follows: Octet 1: Concatenated Short Message reference number: this reference number is constant within a concatenate session
107/192
Octet 2: Maximum number of short message in the concatenate session: indicate the total number of short message within a concatenate session. The value is constant within a concatenate session Octet 3: Sequence number of the current message: indicate the sequence number of the short message within a concatenate session.
Length (1 or 2)
Tag (1)
Length (1)
Source (1)
Destination (1)
Tag (1)
Length (1)
TON/NPI (1)
SCA (1 10)
Tag (1)
Length (1 or 2)
USSD TPDU
TP-DCS (1)
TP-UDF-PFI (1)
TP-UDH_CCF (optional)
TP-UDSecured data
108/192
Figure 15: USSD message structure Secured data are binary (8 bits). For that the DCS (Data Coding Scheme) should be set to 0x96. The transport mayer only contains this byte. The UDH may contain two fields: - A mandatory PFI (Packet Format Information) field, which is coded on 1 byte. The PFI contains information on the format of the USSD String. An optional CCF (Concatenation Control Field) field, which is coded on 3 bytes. The CCF field presence is indicated by the PFI.
15.1.2.1 General structure of the User Data Header in a Secured Single USSD message
The PFI is coded as follows: b8 b7 B6 b5 b4 B3 X 0 b2 0 0 b1 0 1 Description Proprietary Application Data format Application Data formatted according No CCF field. Application Data CCF field present. RFU formatted according
to
102.225.
to
102.225.
Other combinations
The usage of CCF field allows USSD Messages to be concatenated to form a longer message: Byte 1: Concatenated USSD Message reference number. This octet shall contain a modulo-256 counter indicating the reference number for a particular USSD Message, Concatenated or not. This reference number shall remain constant for every USSD Message that makes up a particular Concatenated USSD Message. Byte 2: Total number of USSD Messages in the Concatenated USSD Message. This octet shall contain a value in the range 1 to 255 indicating the total number of USSD Messages constituting the Concatenated USSD Message. The value shall start at 1 and remain constant for every USSD Message that makes up the Concatenated USSD message. If the value is zero then the receiving entity shall ignore the whole USSD Message. Byte 3: Sequence number of the current USSD Message. This octet shall contain a value in the range 1 to 255 indicating the sequence number of a particular USSD Message within the Concatenated USSD Message. The value shall start at 1 and increment by one for every USSD Message sent within the Concatenated USSD Message. If the value is zero or the value is greater than the value in octet 2 then the receiving entity shall ignore the whole USSD Message. The UM field contains the actual application data (e.g. secure Command/Response Packets coded according to the present document). In each USSD String in a concatenated series, the PFI and CCF fields shall be present. Command and Response packets exceeding 159 bytes shall be segmented as described in following chapters.
109/192
15.1.2.2 Command Packet and User Data Header contained in a Secured Single USSD message
The UM field of an USSD String contains the Command Packet. Command Packet Command Header
PFI (1) CPI (1) CPL (2) CHL (1) SPI (2) KIc (1) KID (1) TAR (3) CNTR (5) PCNTR (1) RC/CC/DS (0, 4 or 8) Secured Data
03
0D, 11 or 15
optional
The Command Packet shall be coded as the generic Command Packet described in TS 102 225. In the Command Packet, the Command Packet Identifier (CPI) value is '03' and the Command Header Identifier (CHI) is a Null field. CPI, CPL and CHL shall be included in the calculation of the RC/CC/DS. The SPI shall be coded as specified in TS 102 225. Developer tip When sending a USSD message, the applet developer should take care with the length of the secured data, as the length of the Command Packet cannot exceed 160 octets. If the length of the Command packet is greater than 140 octets, then the secured data should be concatenated (see next chapters)
15.1.2.3 Command Packet and User Data Header contained in concatenated USSD Messages
If the Command Packet, which is structured as described in section Error! Reference source not found., is longer than 159 bytes (including the Command Header) then it shall be handled as follows : The entire Command Packet including the Command Header shall be separated into its component concatenated parts. The Command Packet is handled as a Concatenated USSD Message as described in annex A of the present document. The Command Packet Header will only be present in the first segment of a concatenated message.
If the data is ciphered, then it is ciphered as described above, before being broken down into individual concatenated elements. CPI, CPL and CHL shall be included in the calculation of the RC/CC/DS. The SPI shall be coded as specified in TS 102 225. An example illustrating a Command Packet split over a sequence of three messages is shown below.
110/192
PFI
CC F1
CH
PFI
CCF2
PFI
CCF3
W here CCFn = C oncate nation Control Field (1,2,3) PFI = Pac ket Form at Inform ation (see Ann ex) CH = C om m and Head er
05
0D, 11 or 15
optional
111/192
The entire Response Packet including the Response Header shall be separated into its component concatenated parts. The Response Packet is handled as a Concatenated USSD Message as described in annex X of the present document. The Response Packet Header will only be present in the first segment of a concatenated message.
If the data are ciphered, then it is ciphered as described above, before being broken down into individual concatenated elements. RPI, RPL and RHL shall be included in the calculation of the RC/CC/DS. An example illustrating a Response Packet split over a sequence of three messages is shown below.
RH
Padding
PFI
CCF1
RH
PFI
PFI
CCF3
Where CCFn = Concatenation Control Field (1, 2, 3) PFI = Packet Format Information (see Annex A) RH = Response Header
If it is indicated in the SPI2 of a Command Packet to send back a PoR and if the Response Packet is too large to be contained in a single USSD String, then: One single Response Packet shall be sent back to the SE using the Return Result Component contained in the subsequent Facility message. This Response Packet: Shall not contain any additional response data Shall contain the Response Status Code set to '0C' ('Actual response data to be sent using a ProcessUnstructuredSS-Request invoke component (i.e. using SEND USSD proactive command) '). The security applied to this Response Packet shall be the one indicated in the SPI2 of the Command Packet. This shall be followed by a complete Response Packet, contained in a concatenated USSD Message as defined above
15.1.2.6
112/192
Single Envelope(USSD) Description USSD data download tag Length of following data Device identities TLV USSD String TAG USSD String Length DCS PFI Ref Nb of seg Seg. Nb USSD String TLV CPI CPL CHL SPI1-SPI2 KIC/KID TAR CNTR PCNTR RC/CC/DS Secured Data Command Header CCF1 USSD String Value D9 XX... XX... 0A XX... 96 05 01 XX 01 03 XX... XX... XXXX XXXX XXXXXX XXXX XX XXXX XX.. Length 1 see TS 102 223 1 See 13.1.2 1 1 1 1 1 1 See 12.1.3 See 12.1.3 2 2 3 5 1 Depends on SPI1 N
Concatenated Envelope(USSD) 1st segment Description USSD data download tag Length of following data Device identities TLV USSD String TAG USSD String Length DCS PFI Ref Nb of seg Seg. Nb USSD String TLV USSD String Secured Data CCF1 Value D9 XX XX 0A XX 96 05 01 XX 02 XX.. Length 1 See see TS 102 223 1 See 1 1 1 1 1 N
113/192
15.1.2.7
Note that Terminal Profile of handset should indicate the support of proactive USSD SEND command ( bit 4 of Fourth byte of terminal profile must be set). According TS 31.111, the following format is used to code a proactive USSD message: Description Proactive UICC command tag Length of following data Command details Alpha Identifier (optional) Device identities TLV USSD String TLV Value Length D0 1 See 12.1.3 See (1) (see TS 102 223 See A Error! Referen ce source not found.
Icon identifier (optional) Text attribute (present if Alpha ID present) Frame identifier (optional) USSD envelope structure
(1)
The Command details for SEND USSD defined in TS 31.111: Command details for SEND USSD
The complete SEND USSD command can be represented this way : Description Proactive UICC command tag Length of following data Command details tag Length Command number Send USSD Command type RFU Device identities TLV USSD String TAG USSD String Length DCS PFI RPI RPL RHL TAR CNTR PCNTR RSC RC/CC/DS USSD String TLV Command Details Secured Data Response Header USSD String Value D0 XX... 81 03 XX 12 00 XX... 8A XX... 96 01 05 XX... XX... XXXXXX XXXX XX XX XXXX XX.. Length 1 See 12.1.3 1 1 1 1 1 see TS 102 223 1 See 12.1.3 1 1 1 See 12.1.3 See 12.1.3 3 5 1 1 Depends on SPI2 of command message N
114/192
15.2.2.1
Serial Number
This parameter is a 16-bit integer, which identifies a particular CBS message (which may be one to fifteen pages in length) from the source and type indicated by the Message Identifier and is altered every time the CBS message with a given Message Identifier is changed. For more detail refer to 3GPP TS 23.041.
15.2.2.2
Message Identifier
This parameter identifies the source and type of the CBS message. A number of CBS messages may originate from the same source and/or be of the same type. These will be distinguished by the Serial Number. The Message Identifier is coded in binary. The ME shall attempt to receive the CBS messages whose Message Identifiers are in the "search list". This "search list" shall contain the Message Identifiers stored in the EFCBMI, EFCBMID and EFCBMIR files on the SIM and any Message Identifiers stored in the ME in a "list of CBS messages to be received". If the ME has restricted capabilities with respect to the number of Message Identifiers it can search for, the Message Identifiers stored in the SIM shall take priority over any stored in the ME. For SMS CB Message, the Message Identifier use the range: 1000 107F: for Cell Broadcast Data Download in "clear" (i.e. unsecured) to the USIM (see 3GPP TS 31.111). If a message Identifier from this range is in the "search list", the ME shall attempt to receive this CBS message. 1080 10FF: for Cell Broadcast Data Download secured according to 3GPP TS 31.115 to the SIM (see 3GPP TS 31.111). If a message Identifier from this range is in the "search list", the ME shall attempt to receive this CBS message.
15.2.2.3
This parameter indicates the intended handling of the CBS message at the MS, the alphabet/coding, and the language (when applicable). This is defined in 3GPP TS 23.038.
115/192
15.2.2.4
Page Parameter
This parameter is coded as two 4-bit fields. The first field (bits 0-3) indicates the binary value of the total number of pages in the CBS message and the second field (bits 4-7) indicates binary the page number within that sequence. The coding starts at 0001, with 0000 reserved. If a mobile receives the code 0000 in either the first field or the second field then it shall treat the CBS message exactly the same as a CBS message with page parameter 0001 0001 (i.e. a single page message).
15.2.2.5
Content of Message
This parameter is a copy of the 'CBS-Message-Information-Page' as sent from the CBC (Cell Broadcast Centre) to the BSC (Base Station Controller). The content of the message is secured as defined in this document.
Command Packet in CBS page of an SMS-CB message: SMS-CB Generalised Command Comments specific Packet Elements elements SN Refer to 3GPP TS 23.041. Coded on 2 octets containing the ID of a particular message. MID CPI='1080' to '109F' Coded on 2 octets containing the source and type of the message. The Command Packet Identifier range is reserved in 3GPP TS 23.041. (see note) DCS Refer to 3GPP TS 23.041. Coded on 1 octet containing the alphabet coding and language as defined in 3GPP TS 23.038. PP Refer to 3GPP TS 23.041. Coded on 1 octet to indicate the page number and total number of pages. Content of CPL Length of the Command Packet, coded over 2 octets, and shall not be Message coded according to ISO/IEC 7816-6. CHI The Command Header Identifier. Null field. CHL This shall indicate the number of octets from and including the SPI to the end of the RC/CC/DS field. Binary coded over 1 octet. SPI to RC/CC/DS in the The remainder of the Command Header. Command Header Secured Data Application Message, including possible padding octets. NOTE: Generally, the CPI is coded on 1 octet, as specified in Structure of Command Packet Chapter. However, the CPI for the SMS-CB message is coded on 2 octets as the values reserved in 3GPP TS 23.041 to identify the Command Packet are MID values which are coded on 2 octets.
116/192
CH
Secured Data
Padding
In the above figure, Header = 6 Octet header as defined in 3GPP TS TS 23.041 (i.e. SN, MID, DCS and PP) and = Command Header includes here the CPL, CHL, SPI to RC/CC/DS. CH
CH
Secured Data
Padding
In the above figure, Header = 6 Octet header as defined in 3GPP TS 23.041 (i.e. SN, MID, DCS and PP) and = Command Header includes here the CPL, CHL, SPI to RC/CC/DS. CH
Figure 17 - CBS structure with Secured Data Securing of the complete CBS message is done by the Sending Entity. The Secured CBS message is formatted in accordance with 3GPP TS 31.115 and transmitted to the MS as CBS pages. The CBS pages are received by the ME and sent directly to the USIM Toolkit Application, by analyzing the MID value.
117/192
card
Application (RFM/RAM/...)
ME
SGSN/GGSN/Server
Application
UICC
BIP (for GPRS)
Figure 18 - BIP Protocol stack SGSN: Serving GPRS Support Node GGSN: Gateway GPRS Support Node As defined in ETSI TS 102 223 (Annex A) the BIP commands and events are separated into different classes e and f. This categorization is also reflected in the Terminal Profile sections, as seen in the following section. The following USAT table reflect the standard BIP command/event-set (class e):
118/192
Some additional commands and events (class f) relevant to BIP are used for local bearers mainly (e.g. Bluetooth, IrDA): Proactive command: SERVICE SEARCH Proactive command: GET SERVICE INFORMATION Proactive command: DECLARE SERVICE Event download: Local connection event
The BIP commands and events are available for 2G and 3G with following bearers: Network Bearers: CSD and HSCSD bearer Circuit Switched Data bearer, this is a regular data call used in a 2G network High Speed Circuit Switched Data bearer, this is an optional high speed data call used in a 2G network Packet Data Service GPRS (General Packet Radio Service) for packet oriented connection used in 2G networks, or UTRAN for packet oriented connection used in 3G networks Local Bearers: e.g. Bluetooth and IrDA links BIP can be used also in two different modes in order to exchange data between the SCWS and the handset browser (BIP in server mode described in 17) and to exchange data between the UICC applications and the handset application (BIP in terminal server mode described in 9.6).
119/192
If the terminal supports the Last Number Dialed service, the terminal does not store the channel set-up details (called party number and associated parameters) sent by this UICC command in EFLND.
16.2.2.1
The UICC indicates whether the terminal should establish the link immediately, in background mode or upon receiving the first transmitted data (on demand). The UICC provides to the terminal a list of parameters necessary to activate a packet data service. The terminal will attempt at least one packet data service activation. Example of GPRS Open channel: If immediate packet data service activation is requested, the ME allocates buffers, activates the PDP (Packet data protocol) context, informs the SIM and reports the channel Id using TERMINAL RESPONSE (Command performed successfully). If on demand PDP packet data service activation is requested, the ME allocates buffers, informs the SIM and reports the channel identifier using TERMINAL RESPONSE (Command performed successfully). If background mode packet data service activation is requested, the ME does the same steps as under on demand PDP. At the end of activation (which can take a longer time depending on the network) the terminal sends a channel status event (Link Established) to the UICC. Developer Tip: In case of an error in opening a channel in background mode the ME sends a Channel Status Event Link not established - no further info.
16.2.2.2
This command is used to establish a connection using a local bearer (Bluetooth, IrDA, RS232, USB). The UICC can act as a server or a client. In the server use case, the UICC performs an OPEN CHANNEL only after having received a Local Connection event from the terminal. Upon receiving this command, the ME decides if it is able to execute the command. The UICC indicates whether the ME should establish the link immediately or upon receiving the first transmitted data (on demand). The UICC provides to the terminal a list of parameters necessary to establish a link. The UICC may request the use of an automatic reconnection mechanism. The UICC may also request an optional maximum duration for the reconnection mechanism. The terminal attempts at least one link establishment set-up. The UICC may also request an optional maximum duration for the terminal to automatically release the link if no data is exchanged.
16.2.2.3
The UICC indicates whether the terminal should establish the link immediately or upon receiving the first transmitted data (on demand). The terminal is responsible for providing the parameters necessary to establish the connection (e.g. APN for GPRS, Address for CSD, etc.). Upon receiving this command, the terminal decides if it is able to execute the command. Example behaviours are listed in clauses for the selected bearer. Developer Tip:
120/192
This functionality needs to be handled carefully, because the result is extremely linked to the terminal configuration.
16.2.2.4
The following table shows all parameters of the different OPEN CHANNEL commands:
Proactive UICC command Tag Length (over following parameters) Command details Device identities Alpha identifier Icon identifier Address Subaddress Duration 1 (present if Duration 2 is present) Duration 2 Bearer description Buffer size Network Access Name Other address (local address) Text String (User login) Text String (User password) UICC/terminal interface transport level Data destination address (requested
UICC/terminal interface transport is present)
when
M M M M O O M O C O M M O O O O C C O
M M M M O O C O M M O O C O C O
Remote Entity Address Text Attribute (may be present only if the Alpha
Identifier is present)
Frame Identifier Legend: M = Mandatory C = Conditional (dependency described in brackets) O = Optional - = not available
121/192
122/192
The event is only sent, if the error condition is not resulting from the execution of a proactive command and if the Channel Status event is part of the current SET UP EVENT LIST. From Rel. 6 on the structure of the Envelope (Event Download - Channel Status) contains a Bearer description data object, which is only present after an OPEN CHANNEL in background mode. See example in Annex I in ETSI TS 102 223
123/192
According to ETSI TS 102 223 the BIP commands are separated into 2 classes, class e and f, which can be found in the Terminal Profile Bytes of the ME: Sixth byte: (Event driven information extensions)
b8 b7 b6 b5 b4 b3 b2 b1 Event: Language selection Event: Browser Termination BIP Event: Data available BIP Event: Channel status Event: Access Technology Change Event: Display parameters changed BIP Event: Local Connection Event: Network Search Mode Change
Rel. 5 x x x
Rel. 6 x x x
124/192
Rel. 5 x x x
Rel. 6 x x x x x x x
On reception of BIP envelope, trigger applet registered to the event: BIP events Rel. 5 EVENT_EVENT_DOWNLOAD_DATA_AVAILABLE x EVENT_EVENT_DOWNLOAD_CHANNEL_STATUS x EVENT_EVENT_DOWNLOAD_LOCAL_CONNECTION -
Rel. 6 x x x
Rel. 5 x x x -
Rel. 6 x x x x x x
Rel. 5 -
Rel. 6 x
Moreover as specified in ETSI TS 102 241 the Toolkit Framework assures a minimum behavior for managing BIP events and dedicated channels: In order to allow the toolkit applet to be triggered by the BIP related events, the Toolkit Framework must have previously issued a SET UP EVENT LIST proactive command. When a toolkit applet changes one or more of these requested events of its registry object, the Toolkit Framework dynamically updates the event list stored in the ME during the current card session. For the events DOWNLOAD DATA AVAILABLE, DOWNLOAD CHANNEL STATUS and DOWNLOAD LOCAL CONNECTION (new in Release 6) the framework only triggers the applet registered to these events with the appropriate channel or service identifier. When a Toolkit Applet has sent an OPEN CHANNEL proactive command and received a successful TERMINAL RESPONSE, the framework registers the received channel identifier for the calling Toolkit Applet. When a Toolkit Applet has sent a CLOSE CHANNEL proactive command and received a successful TERMINAL RESPONSE or at card reset, the framework releases the channel identifier contained in the command. The Toolkit Framework prevents a toolkit applet to issue a SEND DATA, RECEIVE DATA and CLOSE CHANNEL proactive commands using a channel identifier, which is not allocated to it. If an applet attempts to issue such a command the Toolkit Framework throws an exception (command not allowed). The Toolkit Framework prevents a toolkit applet to issue a DECLARE SERVICE (add, delete) proactive commands using a service identifier, which is not allocated to it. If an applet attempts to issue such a command the Toolkit Framework throws an exception (command not allowed).
125/192
In case of the maximum number of allocated Services is exceeded the Toolkit Framework throws a Toolkit Exception (no service id available). The Toolkit Framework prevents a toolkit applet to issue an OPEN CHANNEL proactive command if it exceeds the maximum number of channel allocated to this applet during the INSTALL [install]. If an applet attempts to issue such a command the Toolkit Framework throws an exception (command not allowed).
An example of a BIP APDU exchanges is available in the Annex I of the ETSI TS 102 223. An example of an Applet using BIP API and BIP functionalities is available in Annex D of the 3GPP 43.019 (Rel. 5)
126/192
17
SCWS
17.1 Scope
The aim of this chapter is to give an overview of the Smart Card Web Server4 (SCWS) technology or UICC webserver5 technology. The SCWS is a standard HTTP 1.1 web server embedded in a card allowing the communication with a HTTP client on the handset e.g. a web browser. The SCWS v1.0 Enabler is specified by the Open Mobile Alliance (OMA). The ETSI SCP specification refer to the OMA specification and define also an API to forward HTTP requests to applets (SCWS Extensions) and to send back the response of applets. This technology requires the link between the UICC and the ME to be either BIP or native TCP/IP.
17.3 Specifications
SCWS is specified mainly by two standardization groups: OMA and ETSI. The relevant specifications are OMA specifications: Smartcard Web Serve rv1.0 Enabler Requirements Document (RD), Architecture Document (AD) and Technical Specification document (TS). The documents may be found on the OMA web site http://www.openmobilealliance.org/Technical/release_program/SCWS_v1_0.aspx ETSI specifications: ETSI TS 102 588 Application invocation Application Programming Interface (API) by a UICC webserver for Java Card platform ETSI TS 102 223 Card Application Toolkit (CAT) ETSI TS 102 483 Internet Protocol connectivity between UICC and terminal
4 5
SCWS Smart Card Web Server is the Open Mobile Alliance (OMA) terminology UICC web server is the ETSI SCP terminology
127/192
UICC TCP/IP BIP gateway BIP Access Control BIP network Terminal Equipment
SCWS
A SCWS
solution consist of: a smart card with a SCWS in it, and supporting BIP a handset with an HTTP client supporting BIP and TCP/IP an administration server supporting SCWS administration protocols over GPRS/UMTS and SMS.
The smart card provides a web server for the user to browse using the device WEB browser or a device application managing HTTP, e.g. a JavaME Midlet. Access by other entities is not allowed, e.g. an external Web-Browser. This web server is accessible via a gateway that translates the TCP/IP protocol to another local protocol between the device and the smart card. The architecture should be open to allow the choice of several smartcard-device protocols as the local bearer to transport the HTTP requests and responses. 1.Interface between browser, HTTP/HTTPS client and the SCWS Gateway for sending/receiving HTTP or HTTPS requests and responses. 2.Interface between SCWS Gateway and the SCWS. 3.Interface between the smart card and a remote administration application. 4.Interface between the Access Control Policy Enforcer (ACP) and the device operating system The ACP Enforcer applies filtering as specified in the filtering rules read from the smart card.
128/192
Terminal
Gateway BIP commands localhost: port number
BIP
Web Browse
The BIP protocol is specified in ETSI TS 102 223 and enables the smart card to communicate with external entities over standardised protocols, including TCP/IP. The smart card can open a BIP data channel with the terminal in UICC server mode. The smart card becomes a server allowing TCP applications in the terminal to connect to it on a TCP port number. When the BIP channel is opened the terminal shall listen on the localhost IP address at the TCP port given in the command and forward incoming / outgoing data on this port to / from the UICC. All the SIM Alliance members guarantee that the BIP server mode channel is opened right after the terminal profile. Detail on the management of a BIP channel between the UICC and the handset in the chapter 16. In order to open a BIP channel in UICC server mode, the OPEN CHANNEL command is issued with the UICC/terminal interface transport level parameter including the Transport protocol type set to 3 TCP,UICC in server mode and the port number to be used.
Instead of using the BIP protocol, the TCP/IP protocol over USB as defined the ETSI TS 102 600 and ETSI TS 102 483 can be used. In this case the card shall implement a TCP/IP stack and the device shall be able to access the card through its TCP/IP stack. Developer tip: Amount of data in a HTML page can easily reach several tens of KBytes. This amount of data can be quite slow to transfer, thus lowering user experience. Therefore, HTML designers should carefully design each page until a faster interface (i.e. USB) is available.
129/192
130/192
17.10.1
Command PUT DELETE GET POST
The following administrative commands are defined by the SCWS 1.0 OMA specifications:
The special administrative commands are used to define some configuration parameters of the SCWS (for example start/stop the HTTP or HTTPs server operational mode) the protection sets to protect a URI or a sub-tree meaning for example that the user shall be authenticated before accessing the resource the users login and password when required by protection sets the mapping of SCWS Extensions registered to the SCWS on a given URI The audit commands are available to retrieve the list of file names and directory names under a given directory URI the used memory and available memory under the SCWS the defined protection sets and the list of protected URI sub-trees the registered SCWS Extensions and information related to these SCWS Extensions (associated URI, etc) Interoperability Issue: The implementation of audit commands is optional and may not be implemented on all cards.
17.10.2
The Full Administration Protocol is implemented over a standard HTTP 1.1 layer. The card is the HTTP client and the remote administration server is the HTTP server. The protocol is currently implemented over GSM/GPRS or UMTS using the BIP TCP client mode defined in the ETSI TS 102 223. The remote administration server sends first a PUSH SMS to ask the card to open a BIP channel in TCP client mode. Then a TLS channel is opened using the PSK-TLS mechanism (Pre-Shared Key TLS). Once the TLS communication is established the card sends a HTTP POST request to the remote administration server in order to get the first administrative commands. The remote administration server encapsulates the administrative commands in the response to the HTTP POST request. Developer Tip The OMA specification defines that an administration session can be triggered by a card local event (time based, new IMEI, etc) or by another card application. Currently the ETSI TS 102 588 doesnt define any API for a card application to trigger an administration session.
131/192
SCWS
BIP Network
17.10.3
When using this protocol the administrative commands are encapsulated into SMS formatted according the 3GPP TS 31.115 and the 3GPP TS 31.116. This protocol is suitable only for some amount of data such as sending a short administrative command to update a SCWS configuration parameter. This protocol is not suitable to update SCWS resources such as HTML pages.
132/192
ScwsExtensionService Class implementing the ScwsExtension interface. ScwsException Smart Card Webserver exception and its associated constants.
17.11.2
A SCWS Extension is a standard javacard applet loaded using standard commands (Install for load, Load and Install for install). The SCWS Extension registers to the SCWS using an API of the SCWS framework. The SCWS Extension is not yet accessible. To become accessible a SCWS Extension shall be mapped to a URI by using the proper SCWS administrative command.
133/192
134/192
Network
OTA Platform
Application
UICC ME
Application
Security
CAT_TP Link
UDP BIP APDU
IP Network
IP
e.g. RFM and RAM: ETSI TS 102 226 and 3GPP TS 31.116 Security layer: ETSI TS 102 225 Transport layer: ETSI TS 102 127 Bearer Independent Protocol layer: ETSI TS 102 223 Physical layer: ETSI TS 102 221
Figure 19 - Overview CAT_TP protocol layer with associated layers in OTA platform, UE & UICC environment
135/192
UICC
Network
OTA Platform
ME PUSH SMS (Request for Open Channel + Request for CAT_TP link establishment) Proactive: OPEN CHANNEL
Terminal Response
RAM/RFM
Proactive SEND DATA with Link Establishment SYN PDU : ports, Max SDU,card id..
Terminal Response
ACK PDU
ACK - DATA
Data Transmission
Figure 20 - Illustration Data Exchange in PUSH mode *Note: This PDU may alternatively contain the PoR.
136/192
The segmentation management functionality in CAT_TP splits the data in several segments in sending entity and reorders the data packets in the receiving entity. User data is treated as SDU and passed to the CAT-TP layer. Each SDU is fragmented into smaller CAT_TP PDUs, if it is necessary and sent to ME using UDP packets. The ME transfers each CAT_TP PDU to the card using several APDUs according to the BIP protocol. In the card, the several PDUs are re-assembled as one SDU. The SDU includes the secured header and the secured user data according to the ETSI TS 102 225 specification.
IP Packet 2
IP Packet 3
CAT_TP (last)
SIM Alliance recommendations SIM Alliance members recommend defining a Max SDU size that is a multiple of the PDU buffer size.
137/192
using the Terminal Response. The negotiated value is then sent back by the card to the OTA platform during the CAT_TP link establishment. The OTA platform announces its own max PDU size in the SYN ACK PDU. The 2 max PDU size values may be different. SIM Alliance recommendations The ME is usually able to receive only one UDP packet. It is therefore recommended using a PDU size close to 1K bytes.
138/192
Example: Acknowledgement Number =21 with Window Size = 4 Highest Sequence Number = 25 PDU SN#20 SN#21 SN#22 SN#23 SN#24 SN#25 SN#26 SN#27 SN#28
Window
The window size is the maximum number of PDU that the card is currently able to process for a CAT_TP connection. SIM Alliance recommendations It is recommended using a window value of 1 on server side. Setting the window size to 1 has no real impact on the bearer performance but it ensures the interoperability with the mobile implementation that may not manage several PDUs concurrently. A Window Size of zero is permitted, effectively interrupting data exchange, which might be required when the receiver is temporarily out of resources. When a received PDU has a sequence number that falls within the acceptance window, it is acknowledged. If the sequence number is equal to the left-hand edge (i.e., it is the next sequence number expected), the PDU is acknowledged with a cumulative acknowledgement (ACK). If the sequence number is within the acceptance window but is out of sequence, it is acknowledged with a non-cumulative acknowledgement (EACK). The CAT_TP module in the transmitting host sends PDUs until all PDUs allowed by the currently defined window are sent. Once this limit is reached, the transmitting CAT_TP module may only send a new PDU after it receives a window announcement that increases to the new highest sequence number.
139/192
The SIM Alliance members guarantee that this parameter can be updated post issuance but no interoperable mechanism is defined.
140/192
Text String (User login) Text String (User password) UICC/terminal interface transport level Define that the UDP protocol is used and the UDP port number of the OTA platform Data destination address Define the IP address of the OTA platform Text Attribute Text Attribute applies to the Alpha Identifier. It may be present only if the Alpha Identifier is present.
(*1)
specification 3GPP TS 31.111 Max PDU size, refer to clause 18.4.2 The Network Access Name is in fact the APN (Access Point Name). The Access Point Name identifies the Gateway GGSN which provides interworking with an external packet data network (for example operator.com). User login and password for authentication to access the domain. (*2)
According to the ETSI TS 102 223 Release 6, the ME shall implement the following: If Alpha Id not defined, the ME uses its default string for the OPEN CHANNEL confirmation sentence. If Alpha Id defined, the ME shall use it for the OPEN CHANNEL confirmation sentence. If Alpha Id is null, the ME should not display anything and should not ask for user confirmation for the OPEN CHANNEL (Transparent Mode)
ME compliant with previous releases of the ETSI TS 102 223 may display a confirmation sentence even if the Alpha Id is set to null.
(*2)
It is not possible to set only the login or the password, if they are required to open the connection, the 2 parameters shall be set and in the right order (login first and then password).
Data objects of PUSH command Request for CAT_TP link establishment Field CAT_TP Destination Port Max SDU size Identification data Description Define the CAT-TP port number of the OTA platform. (This field is mandatory). The transport protocol type is insignificant and shall be set to zero. Maximum length of SDU suggested by the OTA platform to be used by the card, refer to clause 18.4.1. Field used to uniquely identify the card (e.g. MSISDN, ICCID), refer to clause 18.5.2
141/192
It is possible to ask for a response packet to get the result of the process of the PUSH commands (the OPEN_CHANNEL and/or the CAT_TP link establishment). The response is sent when a PoR is requested in the PUSH SMS, it is mandatory to use the mode PoR response sent using SMS_SUBMIT. The support of the additional response data is optional. The SIM Alliance members guarantee that they all manage the additional response data. The coding of the response data is defined in the ETSI TS 102 226. SIM Alliance recommendation concerning PoR management: The PoR is only interesting in case of PUSH Request for Open Channel or Request for CAT-TP link establishment failure or other security errors (ETSI TS 102 225). If the PUSH SMS requests succeed, the OTA platform is already aware of it as the link is open. The sending of the PoR once the channel and the link are established may disturb the communication between the ME and the card. It is recommended to send the PUSH SMS without requesting a PoR. If the link establishment fails, the OTA platform can send a second PUSH SMS requesting a PoR (using SMS-SUBMIT) to retrieve the error cause.
142/192
143/192
What is new in release 7 is that theses commands are not only only C-APDU. They can be also proactive comands. A new mechanism called script chaining allows to chain several commands and maintaining the execution context. A Command TLV can be one of the following: A C-APDU, containing a remote management command; An Immediate Action TLV, containing a proactive command or another action to be performed when it is encountered while processing the sequence of Command TLVs; An Error Action TLV, containing a proactive command to be performed only if an error is encountered in a C-APDU following this TLV. A Script Chaining TLV as first Command TLV.
Command TLV 1
Command TLV 2
Command TLV N
Commmand scripting template and the tags values of theses TLV are : Description Command Scripting template tag Response Scripting template tag Number of executed command TLV objects tag Bad format TLV tag Immediate Action tag Immediate Action Response tag Error Action tag Script Chaining tag Script Chaining Response tag Length of tag 1 1 1 1 1 1 1 1 1 Value AA AB 80 90 81 81 82 83 83
19.1.4.1
Figure 24 - Format of a Command Session TLV Note: the presence of the Comprehension Requirement bit is irrelevant for the card.
144/192
The LC parameter represents the APDU input data and it is present only for Case 3 / Case 4 commands; in these cases, also the Data field is present; a LC value of 00 means 256 bytes. The LE parameter represents the APDU output data and it is present only for Case 2 / Case 4 commands. A LE value of 00 means all data available, that is the whole amount of data to be returned without the constraint of 256 bytes. The total size of a single C-APDU TLV can be up to 262 bytes. Command sessions are independent of each other, e.g. in case of Remote File Management, at the beginning of each command session the root directory is selected (the root is the MF in case of a UICC RFM, or is the ADF in case of a USIM RFM). When the first command results in an error, command packet execution is aborted and this C-APDU becomes the last executed command and the R-APDU is part of the Response Scripting Template.
19.1.4.2
It is a BER TLV data object that allows the RAM to issue a proactive command during the execution or that allows to abort the execution if a proactive session is ongoing. It shall be formatted as shown below: It can be present in normal format ( datas present in the command itself ) or in referenced format ( data present in EFRMA
Length = 1 byte
Type of action
Length in bytes 1
Name '01' to '7F': Reference to a record in EFRMA '81': Proactive session indication '82': Early response other values: RFU
Immediate Action TLV - referenced format action type In case of reference to a record in EFRMA the referenced record shall contain the set of COMPREHENSION-TLV data objects preceded by a length value as defined for a BER TLV. If present, the Immediate Action TLV coding "proactive session indication" shall be: The first Command TLV in the script if there is no script chaining. The second Command TLV in the script if there is script chaining.
145/192
In case of "proactive session indication", execution of the remaining script shall be suspended if a proactive session is ongoing. Script processing shall be resumed after the end of the proactive session. If the UICC cannot suspend the script execution, e.g. because there is not enough internal resources available, the UICC shall terminate the processing of the script and return a "suspension error" in the response data.
If no "proactive session indication" is present as first Command TLV and another proactive session is ongoing, proactive commands in the script shall be silently ignored.
In case of "early response", the response to the sending entity shall be sent before processing the rest of the command TLVs. The number of executed commands TLV objects shall include all objects up to the immediate action TLV encoding the "early response". No other response data shall be sent after the response sent due to the early response action TLV.
This is useful in case of some refresh modes, where the UICC might not be able to send a response after the refresh is performed by the terminal.
Proactive commands as defined in following table are allowed as Immediate Action. The behavior of the card for other commands is undefined. DISPLAY TEXT PLAY TONE REFRESH Allowed proactive commands for Immediate Action
19.1.4.3
The Error Action TLV is a BER TLV data object that allows the Remote Management Application to issue a proactive command in case of error in the execution. It shall be formatted as shown in following tables:
Length = 1 byte
Type of action
Length in bytes 1
Length in bytes 1 1
Name Error Action tag Length of Error Action = 0 Error Action TLV - no action
146/192
In case of referenced format, the referenced record in EFRMA shall contain the set of COMPREHENSION-TLV data objects preceded by a length value as defined for a BER TLV. DISPLAY TEXT PLAY TONE Allowed proactive commands for Error Action If an error is encountered when processing a C-APDU, error actions shall be performed as follows: If there is an Error Action TLV between the start of the script and the C-APDU resulting in an error, the action defined in the last Error Action TLVs shall be performed. If this last Error Action TLV has zero length, no action shall be performed. If there is no Error Action TLV between the start of the script and the C-APDU resulting in an error, no action shall be performed.
19.1.4.4
The optional Script Chaining TLV is a BER-TLV data object and shall be coded as shown in this table: Length in bytes 1 1 1 Name Script Chaining tag Script Chaining Length= 1 Script Chaining Value Script Chaining TLV If present, the Script Chaining TLV shall be present only once and shall be the first Command TLV in the Command Script. It may only be present for Remote File Management. If it is received by any other application standardised in TS 101 220, the error "Script Chaining not supported by this application" shall be send back to the sending entity. The Script Chaining Value is defined as follows: '01' first script delete chaining information upon card reset '11' '02' '03' first script keep chaining information across card reset subsequent script subsequent script(s) will follow subsequent script last script
Whether or not chaining information is kept across card reset(s) is defined in the first script for the whole chain. This command allows to maintain a persistant OTA context between 2 or more OTA scripts (even if card is powered off). It will be used for large files management. This mechanism allows persistent OTA Context: o o o File context and PIN context persistent through OTA sessions. OTA context kept during the card session OTA context kept across card reset (implementation needs a backup in eeprom)
The additional response application data which may be sent by a Remote Management application is a BER-TLV data object.
In case no Script Chaining is present in the command list or processing of the Script Chaining produces no error, it shall be formatted according to :
X A Number of executed Command TLV objects R-APDU of first executed case 2/ case 4 C-APDU in the script
147/192
Expanded Format of Remote Management application additional response data The Response Scripting template is a BER-TLV data object as defined in TS 101 220. The Number of executed command TLV objects is a BER-TLV data object and shall be coded as shown here :
Length in bytes 1 1 X
Description Number of executed command TLV objects tag Length=X Number of executed command TLV objects
The Number of executed command TLV objects value corresponds to the number of command TLV objects executed within the command script. The structure of each R-APDU shall be a TLV structure coded according to the R-APDU COMPREHENSION-TLV data object coding defined in TS 102 223. The restriction on the length of the R-APDU mentioned in the note in TS 102 223 shall not apply. For Le='00', the length of the R-APDU may be coded on more than two bytes. A Remote Management application response string may contain a single or several R-APDU TLVs. In case of a unknown Tag, or TLV with a wrong format (e.g. length > length of BER-TLV or length < 4) is encountered while processing the command script, a Bad format TLV shall be put into the response data and processing of the command script shall be aborted at that point. The Number of executed C-APDUs shall take into account the incorrectly formatted TLV. The Bad format TLV is a BER-TLV data object and shall be coded as shown in Error! Reference source not found. Length in bytes Description 1 Bad format TLV tag 1 Length 1 Error type Bad format TLV Error type Coding: '01': Unknown Tag found '02': Wrong length found '03': Length not found Other values: RFU. If "proactive session indication" is present in the script and a proactive session is ongoing and the UICC is unable to suspend script processing, the additional response application data shall be formatted according to following tables and indicate "suspension error".
Length in bytes 1 L X A
Name Response Scripting template tag Length of Response Scripting template= X+A Number of executed command TLV objects (value is 1) Immediate Action Response
Expanded Format of Remote Management application additional response data in case of Immediate Action error
148/192
The Immediate Action Response is an Immediate Action Response TLV which is a BER-TLV data object coded as shown here
Length in bytes 1 1 X
Description Immediate Action Response tag Length=X Immediate Action Response Value Immediate Action Response TLV
The Immediate Action Response Value is defined as follows: '01' Suspension error In case a Script Chaining TLV indicating "subsequent script " is present in the list, the following situations shall be considered as chaining errors: The previous script did not contain a Script Chaining TLV indicating "first script " or "subsequent script subsequent script(s) will follow"; The first script of the chain indicating "first script delete chaining information upon card reset" was processed in an earlier card session. In case of chaining errors, the additional response application data shall be formatted according to this table:
Length in bytes 1 L2 X A
Name Response Scripting template tag Length of Response Scripting template= X+A Number of executed Command TLV objects Script Chaining Response
Expanded Format of Remote Management application additional response data in case of Script Chaining error
Length in bytes 1 1 X
Description Script Chaining Response tag Length=X Script Chaining Result Value Script Chaining Response TLV
The Script Chaining Response tag is defined in 18.1.4. The Script Chaining Result Value is defined as follows:
'01' '02' 03
No previous script Script Chaining not supported by this application Unable to process script chaining (e.g. no resources to store chaining context)
149/192
Unless Script Chaining is used, the MF shall be implicitly selected and be the current directory at the beginning of a
Command "session".
Unless Script Chaining is used, the ADF shall be implicitly selected and be the current directory at the beginning of a
Command "session".
150/192
20.3 RFM and expanded format using script chaining TLV command
For the Expanded Remote Application data format, it is possible to chain two or more scripts using Script Chaining TLVs. If a Script Chaining TLV indicating "first script " or "subsequent script subsequent script(s) will follow" is processed successfully, the file context (current directory, current file, current tag pointer, etc.) and the PIN verification status at the end of the script shall be remembered until the next script is processed by the Remote File Management application. If the next script contains a Script Chaining TLV indicating "subsequent script " that is processed successfully, the remembered file context and PIN verification status shall be restored. Else the default context shall be used. If a non-shareable file is selected by the remembered file context, the mechanisms defined in TS 102 221 limiting the access to non-shareable files shall apply.
It is up to the sending entity to guarantee that a sequence of scripts, each relying on the context of the previous one, is processed in the correct sequence by the UICC. This can be achieved by using a reliable transport mechanism, by waiting for a positive response of one script before sending the next, or by using appropriate settings in the security layer ("process only if counter value is one higher than previous value").
151/192
By changing these parameters different access rights and different security levels can be defined for the different applications. Interoperability Issue: The way Remote File Application parameters are configured is not specified in ETSI TS 102 226 standards. SIM Alliance members provide proprietary mechanisms to configure those parameters.
SELECT
The SELECT command supports all the selection modes when selecting a DF or an EF by FID or by path; the FID 7FFF, dedicated to select the current ADF, cannot be used in cases of UICC RFM. The SELECT by DF Name can not be used in the RFMs because it is used to select a different ADF and each USIM RFM manages just one ADF. Warning: If a file is declared as not shareable, the file selection status can prevent the file from being selected in other contexts (I/O, toolkit applets). In this case, if the file is currently selected by User Equipment or by a Toolkit Applet, it can not be selected by RFM and vice versa.
READ BINARY, UPDATE BINARY, READ RECORD, UPDATE RECORD, SEARCH RECORD, INCREASE, ACTIVATE FILE, DEACTIVATE FILE,
152/192
The operations are allowed only if a Security Condition (SC) related to the relevant Access Mode (AM) is granted by the RFM application Access Domain. The access rights granted to an application by its Access Domain is independent from the access rights granted at the UICC/Terminal interface. This implies in particular that the status of a secret code (e.g. disabled PIN1, blocked PIN2, etc.) at the UICC/Terminal interface does not affect the access rights granted to an application. Security Condition and Access Mode are indicated in EFARR (see ETSI TS 102 221).
VERIFY PIN, CHANGE PIN, ENABLE PIN, DISABLE PIN, UNBLOCK PIN
The PIN related commands affect the PIN value or the PIN blocking status both in RFM sessions and in I/O sessions: presenting a wrong PIN value for three times, the PIN is blocked also for the I/O session; changing PIN value via OTA affects PIN value also for the I/O session, and so onInteroperability Issue: SIM Alliance members are not interoperable about the PIN verification during an OTA sessions: it may or may not change the set of operations granted to the RFM application in the current session.
153/192
Figure 26 - Remote Application Management Architecture Remote Application Management on a card includes the ability to load, install and remove applications. It is performed RAM Issuer Domain OPEN Security OP API
Runtime Environment
154/192
Load Request
Load 1
Load n
Install Application . Figure 27 - Loading and installing an application The INSTALL command must be sent first with the Load option. Several LOAD commands are then sent to the card; they include the package byte code, which is sent to the card, block by block. Each block is numbered and the last block is clearly identified. Depending on the applet size, several bearer message entities might be used for loading the package. An applet is installed via the INSTALL command sent with the Install option. Installation does not necessarily occur during the same session as the package loading phase.
155/192
packet structure according to ETSI TS 102 225. Key Version Number 11 is used for the calculation of the UICC Toolkit Parameters DAP and Access Domain DAP. Definition of the key identifier which has to be used for the ciphering of the key values which are provided in the PUT KEY command. Clarification of the version of the transport key DEK used when replacing or creating a key set. Extended to retrieve the SCP Registry Data (if bit2 of P2 is set) Extended to retrieve: FF 1F menu parameters (see 3GPP TS 23.048) FF 20 card resources (see 3GPP TS 23.048) FF 21 information on the card resources used and available FF 22 to FF 3F reserved for allocation in ETSI TS 102 226
Interoperability Issues The SIM Alliance members do not guarantee that the SELECT, STORE DATA, DELETE Key, INSTALL [for personalization] and INSTALL [for extradition] commands as defined in GP 2.1.1 are supported by the Remote Application Management on each card. Concerning the GlobalPlatform commands used via OTA the SIM Alliance members do not guaranty the interoperability concerning the status word sent in the additional data of the response packet. The SIM Alliance members recommend using the GET DATA with FF 21 to retrieve the card resources instead of using FF 20. Furthermore they recommend to use the GET STATUS to retrieve the menu parameters instead of using GET DATA with FF 1F.
156/192
Figure 28 - SAT and USAT toolkit install parameters The INSTALL command for install mode is formatted as follows when installing an applet with SIM file access and toolkit specific parameters: Presence M M M M Length 1 5-16 1 5-16 Description Length of the load file AID Load file AID Length of the class file AID Class file AID
157/192
M C
1 0-n
Length of the application instance AID Application instance AID Length of the application privilege Application privilege Install parameter length Install parameter field (TLV formatted) Presence Length Description M 1 Tag of the System Parameters field: EF M 1 Length of the System Parameters field 10 M System Parameters field (TLV formatted) Presence Length Description M 1 Tag of the non-volatile memory required: C8 M 1 Length of the non-volatile memory required for the installation field M 2 Non-volatile memory required for the installation field (in bytes) M 1 Tag of the volatile memory required: C7 M 1 Length of the volatile memory required for the installation field M 2 Volatile memory required for the installation field (in bytes) O 1 Tag of the SIM file access and toolkit applications specific parameter field: CA C 1 Length of the SIM file access and toolkit applications specific parameter field C 6-n SIM file access and toolkit applications specific parameter field M 1 Tag of the Applet-Specific Parameters field: C9 M 1 Length of the Applet-Specific Parameters field C 0-o Applet-Specific Parameters Length of the install token The Install Token is mandatory for Delegated Management. The install token shall not be present if Delegated Management is not used.
M Mandatory; C conditional; O optional Note The memory space required indicates the minimum size to be available on the card when downloading the application. The USIM must prevent the applet from being installed if the required size is not available on the card. The INSTALL command for install mode is formatted as follows when installing an applet with UICC System specific parameters: Presence M M M M M M M C M M Length 1 5-16 1 5-16 1 5-16 1 0 or 1 1 14 Description Length of the load file AID Load file AID Length of the class file AID Class file AID Length of the application instance AID Application instance AID Length of the application privilege Application privilege Install parameter length Install parameter field (TLV formatted) Presence Length Description M 1 Tag of the System Parameters field: EF M 1 Length of the System Parameters field 10 M System Parameters field (TLV formatted) Presence Length Description M 1 Tag of the non-volatile memory required: C8 M 1 Length of the non-volatile memory required
158/192
M C
1 0-n
for the installation field Non-volatile memory required for the installation field (in bytes) M 1 Tag of the volatile memory required: C7 M 1 Length of the volatile memory required for the installation field M 2 Volatile memory required for the installation field (in bytes) O 1 Tag of the UICC System specific parameters field: EA C 1 Length of the UICC System specific parameters constructed field C 0-m UICC System specific parameters constructed value field M 1 Tag of the Applet-Specific Parameters field: C9 M 1 Length of the Applet-Specific Parameters field C 0-o Applet-Specific Parameters Length of the install token The Install Token is mandatory for Delegated Management. The install token shall not be present if Delegated Management is not used. M 2
Interoperability Issue The memory space required on the card is not a physical memory reservation. The physical memory size actually used on the card depends on the card manufacturer. There is currently no interoperability in this respect and you are advised to use the value ranges provided by the card manufacturers. If the installation of an application fails all allocated resources are freed but the claiming of the resources might differ depending on the card manufacturer.
21.2.3.1
The SIM File Access and Toolkit Application Specific Parameters are mandatory for applications using the sim.toolkit.ToolkitInterface or sim.access.SIMView interface specified as defined in 3GPP TS 43.019. The SIM File Access and Toolkit Application Specific Parameters are used to specify the resources that the application instance can use. These resources include the timers and menu items for the SET UP MENU proactive command. The network operator or service provider can also define the menu position and the menu identifier of the menus activating the application. The following format is used to code the application parameters: Name Length of the Access Domain field Access Domain Priority level for the Toolkit application instance Maximum number of timers allowed for the application instance Maximum text length for a menu entry Maximum number of menu entries allowed for this application instance Position of the first menu entry (00 means last position) Identifier of the first menu entry (00 means that the identifier is not significant) ... ... ... C 1 Position of the last menu entry (00 means last position) C 1 Identifier of the last menu entry (00 means that the identifier is not significant) O 0 or 1 Maximum number of BIP channels for this application instance O 0 or 1 Length of the Minimum Security Level field C 0-r Minimum Security Level (MSL) O 0 or 1 Length of the TAR Value(s) field (= 3*t) C 3*t TAR Value(s) of the Toolkit application instance M Mandatory; C conditional; O optional Refer to ETSI TS 102 226 for further details on these parameters (including default values for optional parameters). Access Domain field: Some values are mandatory whereas others are optional. SIM Alliance members support the following values: 00 full access 01 APDU access (reserved for 2G; see 3GPP TS 31.116) 02 UICC access (reserved for 3G; see description below) Presence M M M M M M C C Length 1 1-q 1 1 1 1 1 1
159/192
If an optional parameter is included, then all the previous parameters in the table above shall be included also. If no parameter is set in the Maximum number of channels field, a default value is allocated for the application instance by the card. Interoperability Issue The default parameter for the Maximum number of channels is card manufacturer dependent.
21.2.3.2
Presence O C C
The UICC System Specific Parameters value field of the INSTALL [for install] command shall be coded as follows:
O C C O C C
1 1 o 1 1 p
O C
1 1
160/192
UICC Administrative Access Application specific parameters Presence Length Name O 1 Length of UICC file system AID (= 00) O 0 Empty UICC file system AID O 1 Length of Administrative Access Domain for UICC file system O m Administrative Access Domain for UICC file system O 1 Length of Administrative Access Domain DAP O 0 or n Administrative Access Domain DAP O 1 Length of ADF #1 AID O 5-16 ADF #1 AID O 1 Length of Administrative Access Domain for ADF #1 O o Administrative Access Domain for ADF #1 O 1 Length of Administrative Access Domain DAP #1 O 0 or p Administrative Access Domain DAP # 1 ... ... ... O 1 Length of ADF #q AID O 5-16 ADF #q AID O 1 Length of Administrative Access Domain for ADF #q O o Administrative Access Domain for ADF #q O 1 Length of Administrative Access Domain DAP #q O 0 or p Administrative Access Domain DAP #q
Note The UICC access application specific parameters and UICC administrative access application specific parameters are also applicable for non-Toolkit applets which want to access the file system. Coding of the Access Domain Data for UICC access mechanism The UICC access mechanism is coded as follows: Byte 1: 02 for UICC access
161/192
Byte 2: b8 b7 b6 b5 b4 b3 b2 b1 Application Application Application Application Application Application Application Application Byte 3: b8 b7 b6 b5 b4 b3 b2 b1 ADM1 ADM2 ADM3 ADM4 ADM5 ADM6 ADM7 ADM8 Byte 4: b8 b7 b6 b5 b4 b3 b2 b1 ADM9 ADM10 ALWAYS Local PIN ( only applicable for ADF ) RFU RFU RFU RFU These access rights are checked against SE ID 01 access rules as defined in ETSI TS 102 221 (see 6.4.1 of the present document). Note The Administrative Access Domains are coded the same way as the Access Domains. The UICC access parameters are applicable to applications using the uicc.access.FileView defined in ETSI TS 102 241. The UICC Administrative access application specific parameters field is used to specify the access rights for the application instance to administrate the file system. The UICC Administrative access parameters are applicable to applications using the uicc.access.fileadministration.AdminFileView defined in ETSI TS 102 241, also for operations inherited from uicc.access.FileView (e.g. readBinary(..)). PIN 1 PIN 2 PIN 3 PIN 4 PIN 5 PIN 6 PIN 7 PIN 8
Interoperability Issue The SIM Alliance members do not guaranty that the warning status word 62 00 (Application has been logically deleted) is supported.
162/192
Applet Developer Tip As it is not possible in Javacard 2.2.1 to delete an applet owning an object stored in a static field, use the AppletEvent.uninstall method to release such references.
21.2.5.1
Extended Card Resources Length Description 1 Number of installed applications tag 1 Number of installed applications length X Number of installed applications 1 Free non volatile memory tag 1 Free non volatile memory length Y Free non volatile memory 1 Free volatile memory tag 1 Free volatile memory length Z Free volatile memory
Note SIM Alliance members recommend using the GET DATA for the Extended Card Resources instead of the GET DATA for the Card Resources as it is limited to 64kb regarding the free memory size returned.
Value SCP Registry Data Menu parameters Value First menu entry position First menu entry identifier First menu entry state ... Last menu entry position Last menu entry identifier Last menu entry state
The menu entry identifiers and positions are the ones provided in the Menu Entries list defined in ETSI TS 102 241 and are returned regardless of the menu entry state as well as regardless of the Application life cycle state (e.g. Selectable/Locked, etc.). The menu entry state is defined as follows: '00': menu entry is disabled '01': menu entry is enabled other values RFU Interoperability Issue The LOGICALLY DELETED life cycle state as known from the OP 2.0.1 is not supported by all card manufacturers as this life cycle state is not defined in the GP 2.1.1. The SIM Alliance members advise to use only combinations of P1 as defined in the GP 2.1.1 as other combinations defined in previous versions of the GlobalPlatform might not be supported by all card manufacturers.
163/192
164/192
Host
Application
Security Domain
SELECT application
SELECT response
Message to unwrap
Unwrapped message
Message to unwrap
Unwrapped message
Crypted message
Decrypted message
APDU Interface
GP API
165/192
The PUT KEY is either issued via a secure channel or via OTA, in the latter case the TAR is evaluated by the Toolkit Framework to channel the command to the right Security Domain. According to the GP specification, keys have to be associated with a certain algorithm and length. In the PUT KEY command, an algorithm identifier together with length information is sent to the card together with the key data. Keys can be updated by using the PUT KEY command, but the key deletion command may not be supported by each card. Keys are always organized in Key Sets. According to GP, a Key Set may contain one to many keys. The ETSI TS 102 225 precises the definition to three keys per key sets (KID, KIc and DEK see also Error! Reference source not found.) and an additional counter. A maximum of 15 key sets for OTA transportation is allowed for the ISD. SIM Alliance members support up to 15 key sets for OTA transportation for each security domain. Key Sets are identified with a version number that is unique within its SD. Keys within key sets are identified by a unique index within the key set. Key Set versions and key indices have to be specified in the PUT KEY command. The key used for ciphering the key values (e.g. KIc, KID or DEK) of the PUT KEY command is the key with identifier 3 (i.e. DEK). It is a static key. When replacing or adding key(s) within the same key set, or when updating the key version number of a key set, the encrypting key to be used is the DEK of the same key version number as the changed key(s). When creating key set(s), the encrypting key to be used is the DEK of the same key version number as KIc and KID in the Command Packet containing the PUT KEY command. The key version number of KIc and KID used to secure the Response Packet is the same as the key version number indicated in the Command Packet. The transport security keys (i.e. KIc/KID) used to secure the Response Packet are the same as the ones of the Command Packet containing the PUT KEY command.
166/192
167/192
ISO controls the assignment of RIDs to companies, with each company obtaining its own unique RID. Companies assign PIXs for AIDs using their own RIDs.
168/192
ETSI 3GPP Axalto Gemplus Giesecke & Devrient ST Incard Oberthur Card Systems Sagem Orga
22
21
20
19
18
17
16
15
14
13
12
11
10
1. Ni bb le
Country code
Application code
Figure 30 - Structure of an AID For further details, refer to technical specification ETSI TS 101 220.
169/192
'A000000009' 'A000000009'
'0003' '0005'
Allocated from 3GPP: Application 3GPP UICC 3GPP USIM 3GPP USIM toolkit 3GPP ISIM API Application 3GPP (U)SIM API for Java Card RID 'A000000087' 'A000000087' 'A000000087' 'A000000087' 3GPP Application Code '1001' '1002' '1003' '1004' Document 3GPP TS 31.101 3GPP TS 31.102 3GPP TS 31.111 3GPP TS 31.103
'A000000087'
'1005'
3GPP TS 31.130
Country Code
To indicate the country of the application provider of the ETSI or 3G standardized application. List of actual country codes is published by ITU. In case of API Country Code is not used and set to FF FF
170/192
For 2G Applications:
It is used for the following applications: GSM (0001), GSM SIM toolkit (0002) or GSM SIM API for Java Card (0003) 15 16 17 18 19 20 21 22 Application Provider specific data Toolkit Application Reference (TAR) Toolkit Application Reference (TAR) as specified in ETSI TS 102 226, is managed by the application provider (i.e. operator in that case) except for TAR values beginning with hexadecimal value 'B' (most significant bits of digit 15) which are reserved for future use by the 3GPP and the TAR value '000000' which is reserved for the Issuer Security Domain (see ETSI TS 102 226). Application Provider specific data is used for application administration purposes.
19
20
21
171/192
Issuer Security Domain Issuer Security Domain '00 00 00' ETSI TS 102 226 1st level application issuer specific values Allocated by the 1st level application '00 00 01' to 'AF FF FF' issuer Allocated by the 1st level application 'C0 00 00' to 'FF FF FF' issuer Remote File Management Applications UICC Shared File System 'B0 00 00' and ETSI TS 102 226 'B0 00 02' to 'B0 00 0F' SIM File System 'B0 00 10' to 'B0 00 1F' 3GPP TS 31.116 USIM File Systems (may include 'B0 00 01' and 3GPP TS 31.116 UICC Shared file system) 'B0 00 20' to 'B0 01 1F' RFU 'B0 01 20' to 'B0 FF FF' Payment Applications RFU 'B1 00 00' to 'B1 FF FF' USAT Interpreter Application USAT Interpreter Application 'B2 00 00' to 'B2 00 FF' ETSI TS 131 114 Reserved for future categories RFU 'B2 01 00' to 'BF FE FF' Proprietary toolkit application Proprietary toolkit application 'BF FF 00' to 'BF FF FF'
Major, Minor
Major, Minor
2.2
A000000009 0003FFFFFFFF8910710002
2.6
Major, Minor
Major, Minor
172/192
A0 00 00 00 09 00 05 FF FF FF FF 89 12 00 00 00 1.0
A.10
The following table shows the AIDs of the packages described in the Java Card Specification 2.2.1: Package AID java.lang 'A0000000620001' javacard.framework 'A0000000620101' javacard.security 'A0000000620102' javacardx.crypto 'A0000000620201'
173/192
There are constructed and primitive TLVs existing where the value part of the constructed TLV-Object again can hold several constructed or primitive TLV-objects.
T L T L V T V L V ... constructed primitive
Examples for BER-TLV: tags for several templates, like the FCP template, Security attribute template, PIN Status Template COMPACT-TLV: historical bytes of the ATR COMPREHENSION-TLV: card application toolkit data-objects (proactive commands, envelopes, etc)
A summary of assigned TLV tag-values can be found under ETSI TS 101 220, section 7.2. All unassigned tag values are reserved for future use.
174/192
B.2 BER-TLVs
The coding of a BER-TLV tag field depends on the usage of the TLV-object. Following table explains the tag encoding scheme: Table: First byte of BER-TLV tag fields according to ISO 7816-4
b8/b7 00 01 10 11
b6
b5-b1 universal class application class context specific class private class
0 1 xxxxx 11111
primitive encoding constructed encoding tag number from zero to thirty (short tag field, e.g. consisting of a single byte) tag number greater than thirty (long tag field, e.g. consisting of 2 or 3 bytes)
B.3 COMPACT-TLVs
According to ETSI TS 101 220 the COMPACT-TLV data objects are used for the historical bytes of the ATR only. The COMPACT-TLV data objects are deduced from interindustry BER-TLV data objects with tag field '4X' and length field '0Y'. The coding is 'XY' followed by a value field of 'Y' bytes fixing one or more data elements. In this clause, quartet 'X' is referred to as the compact tag and quartet 'Y' as the compact length.
B.4 COMPREHENSION-TLVs
The COMPREHENSION-TLV data objects are not encoded as BER-TLV tag fields. They are primitive data objects defined in ETSI TS 101 220 Release 7 for the specific purpose of indicating the Comprehension Required Flag (CR) in the tag. The value of the first byte identifies the format used.
First byte value '00' '01' to '7E' '7F' '80' '81' to 'FE' 'FF'
Format Not used Single byte Three-byte Reserved for future use Single byte Not used
The specification ETSI TS 101 220 Release 7 defines only COMPREHENSION-TLVs with one byte length. The same value in the different formats represents the same data object. Unless otherwise stated, for COMPREHENSION-TLV it is the responsibility of the UICC application and the terminal to decide the value of the Comprehension Required (CR) flag for each data object in a given command. Handling of the CR flag is the responsibility of the receiving entity. CR Comprehension required Comprehension not required Value 1 0
Three-byte format
175/192
Byte 2 5 4
Tag value format: Byte 1 equal to '7F' indicates that the tag is in the three-byte format. CR: Comprehension required for this object. Use and coding is the same as in single byte format. Tag value: Coded over 15 bits, with bit 7 of byte 2 as the most significant bit. Range from '00 01' to '7F FF'.
Byte 2 Byte 3 Byte 4 not present not present not present length ('80' to 'FF') not present not present length ('01 00' to 'FF FF') not present length ('01 00 00' to 'FF FF FF')
Note: Even if ETSI TS 101 220 refers to BER coding with this table, the correct naming would be DER (distinguished encoding rules) coding, which is a subset of BER. With DER it is mandatory to use the shortest possible length coding. E.g. if you want to code T='C0', V= 'AA BB CC', following rules apply: 'C0 81 03 AA BB CC' (valid BER coding according to ISO 7816-4 but not allowed for ETSI TS 101 220) 'C0 03 AA BB CC' (valid DER coding according to ISO 8825-1, mandated in ETSI TS 101 220)
176/192
Command message
As an UICC command, the CREATE FILE is coded according to table 1. Table 1: CREATE FILE command message Code CLA INS P1 P2 Lc Data field Le Value 0X E0 '00' '00' Length of the subsequent data field Data sent to the UICC Not present
177/192
Mechanisms to specify 2G security attributes (i.e. the access conditions valid when the card is put in a 2G mobile) are not specified by ETSI specification and so they are not interoperable.
Tag 80/81: Size of the EF (Tag 80) or DF/ADF (Tag 81). It does not include the size of the structural information for the created object. It is the size returned in the FCP information provided in a response to a SELECT APDU command and labeled "Reserved File Size" for EF. For DF creation, the tag 81 may be ignored. Tag C6: PIN status template data object needed only in case of DF creation Interoperability issue SIMAlliance members cannot guarantee that cards behavior is interoperable for this TLV. However it is recommended to include it in the CREATE command as it is a mandatory field. This tag may be ignored too.
Tag A5: Proprietary tags can be used to define how to fill created EFs, to specify the BER-TLV maximum file size, to define a specific file information or other proprietary behaviors that may vary from supplier to supplier.
Limitations:
The maximum number of EF for a given DF is 255 (limitation from the answer to a select). The maximum size of an EF is 32k as the read binary cannot access to more than 32k (due to SFI in P1P2 parameters).
If a file is indicated as not-shareable and is the current file of one application, then another application cannot delete it. If a file is indicated as shareable then it can be deleted by one application independently of whether or not the file is the current file of any other application. So in this case, if another application is using concurrently the deleted file, the processing by the application may fail. If a DF is shareable and an application, having the appropriate rights, requests to delete it, the whole DF including all EFs can be deleted whatever shareable status they have.
Interoperability issue: SIMAlliance members cannot guarantee that deletion of shareable EF/DF will result in the same final file context for other applications.
SIMAlliance members cannot guarantee that deletion of mapped files is interoperable. After successful completion of this command, the deleted file can no longer be selected. The resources held by the file are released and the memory used by this file is set to the logical erased state. It is not possible to interrupt this process in such a way that the data can become recoverable.
Command message
The DELETE FILE command message is coded according to table 2. Table 2: DELETE FILE command message
Code CLA INS P1 P2 Lc Value 0X E4 '00' '00' Not present or length of the subsequent data field
178/192
FID is mandatory in the JAVA API. When not present, the current selected EF/DF/ADF on the considered logical channel is deleted.
In case the size of a linear fixed or transparent EF is decreased: the removed data are deleted and removed from the end of the existing data and the remaining data already contained in the previously allocated memory space are not modified by the RESIZE FILE command For a BER-TLV structured EF, the Reserved File Size or the Maximum File Size or both can be resized. If the Maximum File Size is decreased and the new size conflicts with the used size, then depending on the mode chosen in P1 parameter, the command is rejected or all objects in the file are deleted.
Command message
The RESIZE FILE command message is coded according to table 3. Table 3: RESIZE command message Code Value CLA 8X INS D4 P1 00 (or 0 for BER-TLV EF mode selection) P2 '00' Lc Length of the subsequent data field Data Field Data sent to the ICC Le Not present
179/192
command is rejected (see previous note). This New File Size low limit is at least the size needed by one record. For transparent files, if this size is set to '00', all the content of the EF is removed but the EF is not deleted (it is then exactly as if the EF was created with a size set to '00') and the structural information is still available. For BER-TLV structured EF, if File Size is present, it indicates the minimum number of bytes reserved for the body of the file. The value includes administrative overhead (if any) that is required to store TLV objects, but not the structural information for the file itself. The current content of the file remains still the same whatever is the new reserved file size value (in case of increase of the current file size, below is the decrease case). Tag '81': Total File Size. This TLV is only used in case of MF or a DF/ADF resize operation. It contains the New Total File Size for the MF or this DF/ADF. This size is the new amount of physical memory allocated for the MF or a DF/ADF (i.e. it does not include structural information) for card not implementing dynamic allocation of memory. The amount of EFs or DFs which may be created is implementation dependent. The MF or DF/ADF can be resized to '00' only if it does not contain any file. In this case, the structural information is still available for the MF or DF/ADF. For an ADF, the resizing to '00' does not affect EFDIR and any other information necessary to administer an application. After tag 'A5', there can be some other optional or proprietary TLV objects, for example to define with which pattern use to fill the created space resizing an object with a higher size. The full support of these features may vary from a card supplier to another. About the optional sub TLV object with tag 86 (Maximum File Size for a BER-TLV structured EF located inside the TLV beginning by A5), this TLV object will only be provided if a BER-TLV structured EF is resized. The Maximum File Size indicates the new maximum number of bytes that can be allocated for the body of the file. As previously, this value includes administrative overhead (if any) that is required to store TLV objects, but not the structural information for the file itself. In case the New Maximum File Size is decreased and the size used by the existing TLV is greater than the New Maximum File Size: If P1 indicates Mode 0, all existing TLV objects are deleted (the file itself is not deleted). The New Maximum File Size is assigned to the file. If P1 indicates Mode 1, no action is performed and it returns an error telling the conditions of use are not satisfied.
180/192
Some CAP file components are optional. Some optional components are used on-card, some are used off-card. Applet.cap is required on-card and is generated only if the package defines one or more applets. Export.cap is required on-card only if other packages may import elements of this package Descriptor.cap may be used or ignored on-card. Custom.cap may be used or ignored on-card Debug.cap may be used off-card by a software development environment for the debugging. The SUN specification doesnt define any load format or installation protocol. But SUN recommends loading the different CAP file components in the order defined by the table 21 of the SUN Javacard 2.2.1 VM specification either for interoperability and minimum resource consumption. Global Platform defines the commands used for the installation, as described in 21.
181/192
Application behavior
Applet installation The application allocates a first level menu item during applet installation, after the application registration; this operation registers also the application to the event menu selection.
tkRegistry = ToolkitRegistrySystem.getEntry(); // Registering to the toolkit tkRegistry.initMenuEntry(menuTitle, (short)0, (short)menuTitle.length, (byte)0, // Next false, // Help (byte)0, // Icon (short)0); // Icon action supported Qualifier Identifier
Then the file EF SUME (6F54) under the DF_TELECOM (7F10) is selected during applet installation; it contains the menu text,; it is suggested to invoke the FileViewBuilder object only during applet installation as it allocates a new memory object. Also an administration file view object is allocated and it selects the DF TELECOM during applet installation; this object is used to perform administrative operations (resize). Note that the files are selected only at this stage and they are not selected anymore during application lifetime. fvEF_DF_TELECOM = AdminFileViewBuilder. getTheUICCAdminFileView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvEF_SUME = UICCSystem.getTheUICCView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvEF_SUME.select(UICCConstants.FID_DF_TELECOM); fvEF_SUME.select(FID_EF_SUME); fvEF_DF_TELECOM.select(UICCConstants.FID_DF_TELECOM); The last operation is allocating a TLV handler object, to be used for resizing operation; also in this case, due to the memory consumption associated to this operation, it is better to invoke this method only at installation time: // The edit handler is allocated with exactly size of the Resize Command template editHandler = (EditHandler)HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER, (short)resizeCommand.length);
182/192
Operative behavior
The application can be triggered only by menu selection event; the user is prompted to insert a new menu title by issuing a Get Input proactive command: // The user is prompted with a get input to change the menu title ProactiveHandler proh = ProactiveHandlerSystem.getTheHandler(); // Note: missing 8_BIT_DATA from ETSI - used 0x04 proh.initGetInput( (byte)0x00, (byte)0x04, insertNewTitle_text, (short)0, (short)insertNewTitle_text.length, (short)1, (short)20 ); res = proh.send(); If the user accepts to change the event, the inputted text is retrieved by the Proactive Response Handler and an Alpha Identifier TLV is built by setting the menu title: // If the user presses ok... if (res == (byte)0x00) { // The text is retrieved by the Proactive Response Handler ProactiveResponseHandler proresh = ProactiveResponseHandlerSystem. getTheHandler(); // To perform copy operation, the Volatile Byte Array is used (no memory // allocation) globalBuffer = UICCPlatform.getTheVolatileByteArray(); dataLen = proresh.copyTextString(globalBuffer, (short)2); // Data is stored inside the Menu Resize in a T-L-V structure globalBuffer[0] = ToolkitConstants.TAG_ALPHA_IDENTIFIER; globalBuffer[1] = (byte)(dataLen-2); // The file is resized to exactly fit the buffer resizeMenuFile(dataLen); // File content is updated fvEF_SUME.updateBinary((short)0, globalBuffer, (short)0, dataLen); } Before updating the file content, a Resize operation is performed on the file size in order to let the new content fitting. To simplify the building of the Resize command, the array containing the structure of the resize command is pre-stored in the application, and only the size field is set. // The new length is set in the byte array Util.setShort(resizeCommand, FILE_LENGTH_OFFSET, newFileLength); editHandler.clear(); editHandler.appendArray(resizeCommand, (short)0, (short)resizeCommand.length); // The resize operation is performed fvEF_DF_TELECOM.resizeFile(editHandler);
Installation parameters
The following installation parameters are required:
183/192
The resize file operation on EF SUME must be granted; the condition to be fulfilled depends on card configuration.
Applet Source
/*-----------------------------------------------------------------/ SIM Alliance / Java Card Interoperability Working Group / Demo applet 1 - Menu Resizer / / The Menu Resizer is a simple toolkit application with one first level / menu entry, with an user text set as Change title. / / Once the user selects the menu entry, a user prompt with a notifying / text Insert the new title requests the user to type a new text for the USIM Menu. / /-----------------------------------------------------------------*/ package simalliance ; import import import import import uicc.system.*; uicc.access.*; uicc.access.fileadministration.*; uicc.toolkit.*; javacard.framework.*;
public class menuResize extends Applet implements ToolkitInterface { // FileView object selecting the DF Telecom - it is used to perform resizing of EF 6F54 AdminFileView fvEF_DF_TELECOM; // FileView object selecting the DF Telecom / EF Sume // it is used to update content of EF_Sume FileView fvEF_SUME; // FID of EF Sume static final short FID_EF_SUME = (short)0x6F54;
// Title of the menu item allocated to the application private static byte [] menuTitle = {(byte)'C', (byte)'h', (byte)'a', (byte)'g', (byte)'e', (byte)' ', (byte)'t', (byte)'i', (byte)'l', (byte)'e'} ; // Text shown to the user to get a new menu title ("Insert the new title:") private static byte [] insertNewTitle_text = {(byte)'I', (byte)'n', (byte)'e', (byte)'r', (byte)'t', (byte)' ', (byte)'h', (byte)'e', (byte)' ', (byte)'e', (byte)'w', (byte)' ', (byte)'i', (byte)'t', (byte)'l', (byte)':' } ; // Template for the resize command private static byte [] resizeCommand = (byte) 0x54, (byte) (byte) 0x00 }; // Offset in the resize command template for the file length static final short FILE_LENGTH_OFFSET = (short)6; // Reference to the toolkit registry private static ToolkitRegistry tkRegistry; // Reference to an Edit Handler object, used to execute the resize command private EditHandler editHandler; /** 0x80, (byte) 0x02,
(byte)'n', (byte)'t',
184/192
/** * Toolkit initialization * * Virtual method invoked after the registration to the toolkit **/ public void initToolkit() { tkRegistry = ToolkitRegistrySystem.getEntry(); // Registering to the toolkit tkRegistry.initMenuEntry(menuTitle, (short)0, (short)menuTitle.length, (byte)0, // Next false, // Help (byte)0, // Icon (short)0); // Icon action supported Qualifier Identifier
// The DF Telecom and the EF SUME are selected in the two FileView and AdminFileView // objects. // Note that DF Telecom points to an administrative File View object, to perform // resize operation. fvEF_DF_TELECOM = AdminFileViewBuilder. getTheUICCAdminFileView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvEF_SUME = UICCSystem.getTheUICCView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvEF_SUME.select(UICCConstants.FID_DF_TELECOM); fvEF_SUME.select(FID_EF_SUME); fvEF_DF_TELECOM.select(UICCConstants.FID_DF_TELECOM); // The edit handler is allocated with exactly size of the Resize Command template editHandler = (EditHandler)HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER, (short)resizeCommand.length); } /** * Installation method * * After the applet instantiation and registration, all toolkit initialization * operations are performed **/ public static void install(byte bArray[], short bOffset, byte bLength) { menuResize menuResizeApplet = new menuResize(); } /** * processToolkit * Entry point for the toolkit events * The application is registered only to the menu selection event **/ public void processToolkit(short event) { byte res; byte[] globalBuffer; short dataLen; if (event == ToolkitConstants.EVENT_MENU_SELECTION)
185/192
// Note: missing 8_BIT_DATA from ETSI - used 0x04 proh.initGetInput( (byte)0x00, (byte)0x04, insertNewTitle_text, (short)0, (short)insertNewTitle_text.length, (short)1, (short)20 ); res = proh.send(); // If the user presses ok... if (res == (byte)0x00) { // The text is retrieved by the Proactive Response Handler ProactiveResponseHandler proresh = ProactiveResponseHandlerSystem. getTheHandler(); // To perform copy operation, the Volatile Byte Array is used (no memory // allocation) globalBuffer = UICCPlatform.getTheVolatileByteArray(); dataLen = proresh.copyTextString(globalBuffer, (short)2); // Data is stored inside the Menu Resize in a T-L-V structure globalBuffer[0] = ToolkitConstants.TAG_ALPHA_IDENTIFIER; globalBuffer[1] = (byte)(dataLen-2); // The file is resized to exactly fit the buffer resizeMenuFile(dataLen); // File content is updated fvEF_SUME.updateBinary((short)0, globalBuffer, (short)0, dataLen); } } } /** * Resize Menu File * * It performs the resizing of the EF Sume file. **/ public void resizeMenuFile(short newFileLength) { // The new length is set in the byte array Util.setShort(resizeCommand, FILE_LENGTH_OFFSET, newFileLength); editHandler.clear(); editHandler.appendArray(resizeCommand, (short)0, (short)resizeCommand.length); // The resize operation is performed fvEF_DF_TELECOM.resizeFile(editHandler); } // // process // public void process(APDU apdu) { } public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) { if (clientAID == null) // It's the system invoking return((Shareable)this); return null; } }
186/192
Application behavior
Applet installation
The applet selects, in two different FileView objects, the DF Phonebook under DF Telecom and, in case it is present on the card, under the ADF USIM (the DF PhoneBook under the ADF USIM is optional); then it uses the two FileView objects to register to File Update events and so monitoring any file under the two dedicated files. // Registering to the toolkit tkRegistry = ToolkitRegistrySystem.getEntry(); fvDF_PB_TELECOM = UICCSystem.getTheUICCView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvDF_PB_TELECOM.select(UICCConstants.FID_DF_TELECOM); fvDF_PB_TELECOM.select(FID_DF_PHONEBOOK); // Registering to the File Update Event to monitor Phonebook under DF Telecom tkRegistry.registerFileEvent(ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE, fvDF_PB_TELECOM); try { fvDF_PB_ADF = UICCSystem.getTheFileView(usim_AID, (short)0, (byte)usim_AID.length, JCSystem.NOT_A_TRANSIENT_OBJECT); fvDF_PB_ADF.select(FID_DF_PHONEBOOK); // Registering to the File Update Event to monitor Phonebook under ADF USIM // note: this folder is optional tkRegistry.registerFileEvent(ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE, fvDF_PB_ADF); } catch (Exception ignored) { // In this case, there is no DF Phonebook under ADF // No exception is thrown as the DF Phonebook under the USIM is optional } // The editHandler is used to buffer the file update event in case of reentrancy. editHandler = (EditHandler)HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER, (short)100); }
Operative behavior
The application can be triggered only by file update events; it can be triggered in reentrancy or with the Proactive Handler available. In both cases, the first action it performs is copying the File List TLV (indicating the update file), the Update Information TLV (which part of the file has been updated) and, if present, the AID TLV in the editHandler. if (event == ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE) { editHandler.clear();
187/192
// The Tag List TLV, the Update Information TLV and, in case, the AID TLV are // copied from the envelope handler to the edit handler env.findTLV(ToolkitConstants.TAG_FILE_LIST, (byte)0x01); dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(ToolkitConstants.TAG_FILE_LIST, globalBuffer, (short)0, dataLen); if (env.findTLV(ToolkitConstants.TAG_AID, (byte)0x01) != ToolkitConstants.TLV_NOT_FOUND) { dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(ToolkitConstants.TAG_AID, globalBuffer, (short)0, dataLen); } env.findTLV(TAG_UPDATE_INFORMATION, (byte)0x01); dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(TAG_UPDATE_INFORMATION, globalBuffer, (short)0, dataLen);
If the application is able to send out immediately SMS, the operation is performed; otherwise it is delayed until the proactive handler is available; this is notified to the application by the Proactive Handler Available event. // To send out the SM, the proactive handler must be available; in case it // isn't,the application registers to the Proactive Handler Available event and // quits. // It will triggered again as soon as the Proactive Handler is available. try { ProactiveHandler proh = ProactiveHandlerSystem.getTheHandler(); } catch (Exception e) { /** The EnvelopeHandler information are stored inside the editHandler, * to be used at the Proactive Handler event afterward * Note: if two subsequent file update event happen in reentrance, the first * one is lost **/ tkRegistry.setEvent(ToolkitConstants.EVENT_PROACTIVE_HANDLER_AVAILABLE); return; } sendSMS(); } if (event == ToolkitConstants.EVENT_PROACTIVE_HANDLER_AVAILABLE) { /** * I'm registered to the event only after the triggering in reentrance and the * eventual availability of the Proactive Handler **/ sendSMS(); }
188/192
The sendSMS is an easy function that prepares the SMS to be sent and perform the proactive command; note that the Volatile Byte Array of the UICCPlatform is used to save resources: public void sendSMS() { byte[] globalBuffer; short offset=(short)0; globalBuffer = UICCPlatform.getTheVolatileByteArray(); ProactiveHandler proh = ProactiveHandlerSystem.getTheHandler(); proh.init(PRO_SHORT_MESSAGE, (byte)0x00, ToolkitConstants.DEV_ID_NETWORK ); /** * Building the TP-DU **/ // // // // // // // // // 1st Byte TP-MTI = SMS_Submit 01 TP-RD = False 0 TP-VPF = Not Present 00 TP-SRR = Optional TP-UDHI = 0 (not 102 225 message) TP-RP = Not Set 0 00000001 = 0x01
// Temp buff contains the header globalBuffer[offset++] = (byte)0x01; // MRI globalBuffer[offset++] = (byte)0x01; // Reads the destination address data offset=Util.arrayCopyNonAtomic(destAddress, (short)0, globalBuffer, offset, (sort)destAddress.length); globalBuffer[offset++] = (byte)0x7F; globalBuffer[offset++] = (byte)0xF6; globalBuffer[offset++] = (byte)editHandler.getLength(); offset = editHandler.copy(globalBuffer, offset, editHandler.getLength()); // Total len of TPDU proh.appendTLV((byte)(TAG_SMS_TPDU | ToolkitConstants.TAG_SET_CR), globalBuffer, (short)0, offset); proh.send(); }
Installation parameters
The following installation parameters are required:
189/192
Applet Source
/*-----------------------------------------------------------------/ SIM Alliance / Java Card Interoperability Working Group / Demo applet 2 - Phone Book Monitor / / The Phone Book Monitor is a toolkit application able to monitor / any update in any file of the 3G phonebook. / Any update is immediately communicated to a remote server by sending / an SMS containing the information about the updating. / /-----------------------------------------------------------------*/ package simalliance; import import import import import import uicc.system.*; uicc.access.*; uicc.access.fileadministration.*; uicc.toolkit.*; uicc.usim.toolkit.ToolkitConstants; javacard.framework.*;
public class phoneBookMonitor extends Applet implements ToolkitInterface { // FileView object selecting the phonebook under the DF Telecom and the ADF USIM // it is used to perform file system monitoring FileView fvDF_PB_TELECOM, fvDF_PB_ADF; // FID of the PhoneBook DF static final short FID_DF_PHONEBOOK // Short Message Command Identifier static final byte PRO_SHORT_MESSAGE = (short)0x5F3A;
= (byte)0x13;
// Tag in the Send SM Proactive Command indicating a TP-DU static final byte TAG_SMS_TPDU = (byte)0x0B; // AID of an USIM application. It could be adapted to card configuration. private static byte [] usim_AID = { (byte)0xA0,(byte)0x00,(byte)0x00,(byte)0x00, (byte)0x87,(byte)0x10,(byte)0x02,(byte)0xFF, (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x89, (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00 }; // Destination address of the SMS. It must be updated with a valid value. private static byte [] destAddress = { (byte)0x06, (byte)0x33, (byte)0x24, (byte)0x35, (byte)0x21 }; // Reference of the toolkit registry private static ToolkitRegistry tkRegistry; private static final byte TAG_UPDATE_INFORMATION = (byte)0x3B;
// The edit Handler is used to store the file list when the applet is triggered in // reentrancy private EditHandler editHandler; // Size of data stored inside bufferArray private short storedDataLength; /** * Constructor * **/ public phoneBookMonitor() { register();
190/192
initToolkit(); } /** * Toolkit initialization * * Virtual method invoked after the registration to the toolkit **/ public void initToolkit() { // Registering to the toolkit tkRegistry = ToolkitRegistrySystem.getEntry(); fvDF_PB_TELECOM = UICCSystem.getTheUICCView(JCSystem.NOT_A_TRANSIENT_OBJECT); fvDF_PB_TELECOM.select(UICCConstants.FID_DF_TELECOM); fvDF_PB_TELECOM.select(FID_DF_PHONEBOOK); // Registering to the File Update Event to monitor Phonebook under DF Telecom tkRegistry.registerFileEvent(ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE, fvDF_PB_TELECOM); try { fvDF_PB_ADF = UICCSystem.getTheFileView(usim_AID, (short)0, (byte)usim_AID.length, JCSystem.NOT_A_TRANSIENT_OBJECT); fvDF_PB_ADF.select(FID_DF_PHONEBOOK); // Registering to the File Update Event to monitor Phonebook under ADF USIM // note: this folder is optional tkRegistry.registerFileEvent(ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE, fvDF_PB_ADF); } catch (Exception ignored) { // In this case, there is no DF Phonebook under ADF // No exception is thrown as the DF Phonebook under the USIM is optional } // The editHandler is used to buffer the file update event in case of reentrancy. editHandler = (EditHandler)HandlerBuilder.buildTLVHandler(HandlerBuilder.EDIT_HANDLER, (short)100); } /** * Installation method * * After the applet instantiation, the toolkit resources are allocated. **/ public static void install(byte bArray[], short bOffset, byte bLength) { phoneBookMonitor applet = new phoneBookMonitor(); } /** * processToolkit * Entry point for the toolkit events; the applet is registered only to external * file update event and it can get registered to Proactive Handler Event **/ public void processToolkit(short event) { byte[] globalBuffer; // The Volatile Byte Array is retrieved, to save resources. globalBuffer = UICCPlatform.getTheVolatileByteArray(); short dataLen;
191/192
if (event == ToolkitConstants.EVENT_EXTERNAL_FILE_UPDATE) { editHandler.clear(); /* * The external event is analyzed */ EnvelopeHandler env = EnvelopeHandlerSystem.getTheHandler(); dataLen = (short)0; // The Tag List TLV, the Update Information TLV and, in case, the AID TLV are // copied from the envelope handler to the edit handler env.findTLV(ToolkitConstants.TAG_FILE_LIST, (byte)0x01); dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(ToolkitConstants.TAG_FILE_LIST, globalBuffer, (short)0, dataLen); if (env.findTLV(ToolkitConstants.TAG_AID, (byte)0x01) != ToolkitConstants.TLV_NOT_FOUND) { dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(ToolkitConstants.TAG_AID, globalBuffer, (short)0, dataLen); } env.findTLV(TAG_UPDATE_INFORMATION, (byte)0x01); dataLen = env.copyValue((short)0,globalBuffer,(short)0, env.getValueLength()); editHandler.appendTLV(TAG_UPDATE_INFORMATION, globalBuffer, (short)0, dataLen); // To send out the SM, the proactive handler must be available; in case it // isn't,the application registers to the Proactive Handler Available event and // quits. // It will triggered again as soon as the Proactive Handler is available. try { ProactiveHandler proh = ProactiveHandlerSystem.getTheHandler(); } catch (Exception e) { /** The EnvelopeHandler information are stored inside the editHandler, * to be used at the Proactive Handler event afterward * Note: if two subsequent file update event happen in reentrance, the first * one is lost **/ tkRegistry.setEvent(ToolkitConstants.EVENT_PROACTIVE_HANDLER_AVAILABLE); return; } sendSMS(); } if (event == ToolkitConstants.EVENT_PROACTIVE_HANDLER_AVAILABLE) { /** * I'm registered to the event only after the triggering in reentrance and the * eventual availability of the Proactive Handler **/ sendSMS(); } }
192/192
proh.init(PRO_SHORT_MESSAGE, (byte)0x00, ToolkitConstants.DEV_ID_NETWORK ); /** * Building the TP-DU **/ // // // // // // // // // 1st Byte TP-MTI = SMS_Submit 01 TP-RD = False 0 TP-VPF = Not Present 00 TP-SRR = Optional TP-UDHI = 0 (not 102 225 message) TP-RP = Not Set 0 00000001 = 0x01
// Temp buff contains the header globalBuffer[offset++] = (byte)0x01; // MRI globalBuffer[offset++] = (byte)0x01; // Reads the destination address data offset=Util.arrayCopyNonAtomic(destAddress, (short)0, globalBuffer, offset, (sort)destAddress.length); globalBuffer[offset++] = (byte)0x7F; globalBuffer[offset++] = (byte)0xF6; globalBuffer[offset++] = (byte)editHandler.getLength(); offset = editHandler.copy(globalBuffer, offset, editHandler.getLength()); // Total len of TPDU proh.appendTLV((byte)(TAG_SMS_TPDU | ToolkitConstants.TAG_SET_CR), globalBuffer, (short)0, offset); proh.send(); } // // process // public void process(APDU apdu) { } public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) { if (clientAID == null) // It's the system invoking return((Shareable)this); return(null); } }