==== 4.5.1 Applet Selection with MANAGE CHANNEL OPEN ==== Upon receiving a MANAGE CHANNEL OPEN command on an I/O interface, the Java Card RE shall run the following procedure: 1. The MANAGE CHANNEL OPEN command uses: CLA=**%b000000cc*** (where **cc** in the bits (b2,b1) denotes the origin logical channel: 0-3), or CLA=**%0100dddd*** (where **dddd** in the bits (b4-b1) denote the origin logical channel: 4-19), INS=**0x70** and P1=**0**. Two variants of this command are supported: *P2=**0** when the Java Card RE shall assign a new logical channel number. *P2= the logical channel number specified. *If the MANAGE CHANNEL OPEN command has non-zero secure messaging bits (b4,b3*) in the CLA byte when the origin logical channel is 0-3 or non-zero bit (b6*) when the origin logical channel is 4-19, the Java Card RE responds with status code **0x6882** (**SW_SECURE_MESSAGING_NOT_SUPPORTED**). *If the MANAGE CHANNEL command is issued with P1 not equal to **0** or **0x80**, or if the unsigned value of P2 is greater than **19**, the Java Card RE responds with status code **0x6A81** (**SW_FUNC_NOT_SUPPORTED**). 2. If the origin logical channel on that I/O interface is not open, the Java Card RE responds with status code **0x6881** (**SW_LOGICAL_CHANNEL_NOT_SUPPORTED**). 3. If the Java Card RE supports only the basic logical channel on that I/O interface, the Java Card RE responds with status code **0x6881** (**SW_LOGICAL_CHANNEL_NOT_SUPPORTED**). 4. If the P2=**0** variant is used: *If the expected length value (Le) is not equal to **1**, the Java Card RE responds with status code **0x6C01** (**SW_CORRECT_LENGTH_00+0x01**). *If resources for the new logical channel are not available, the Java Card RE responds with status code **0x6A81** (**SW_FUNC_NOT_SUPPORTED**). 5. If the P2 != **0** variant is used: If resources for the specified logical channel are not available or the logical channel is already open, the Java Card RE responds with status code **0x6A86** (**SW_INCORRECT_P1P2**). 6. The new logical channel on the I/O interface that received the MANAGE CHANNEL OPEN command is now open. This logical channel will be the assigned channel for the applet instance that will be selected on it. 7. Determine the applet instance to be selected on the new logical channel. *If the origin logical channel is the basic logical channel (logical channel 0), then: *If a default applet instance for the new logical channel on the I/O interface is defined, pick the default applet instance for that logical channel as the candidate for selection on the new logical channel. *Otherwise, set the Java Card RE state so that no applet is active on the new logical channel. The Java Card RE responds with status code **0x9000** and if the P2=**0** variant is used, one data byte containing the newly assigned logical channel number. *If an applet instance is active on the origin logical channel, pick the applet instance as the candidate for selection on the new logical channel. *Otherwise, set the Java Card RE state so that no applet is active on the new logical channel. The Java Card RE responds with status code **0x9000** and if the P2=**0** variant is used, one data byte containing the newly assigned logical channel number. 8. If the candidate applet instance is not a multiselectable applet (as defined in [[4.2_Multiselectable Applets| Section 4.2, Multiselectable Applets]]) and the candidate applet's context is active, the Java Card RE shall close the new logical channel. The Java Card RE responds with status code **0x6985** (**SW_CONDITIONS_NOT_SATISFIED**). 9. Assign the **CLEAR_ON_DESELECT** transient memory segment for the new logical channel: *If the applet's context is active, assign the **CLEAR_ON_DESELECT** transient memory segment associated with that context to this logical channel. *Otherwise, assign a new (zero-filled) **CLEAR_ON_DESELECT** transient memory segment to this new logical channel. 10. Check whether the candidate applet instance accepts selection: *If the candidate applet's context is active, the Java Card RE shall set the candidate applet instance as the currently selected applet instance and call the **MultiSelectable.select** method, where the parameter **appInstAlreadyActive** is set to **true** if the same applet instance is already active on another logical channel. A context switch into the candidate applet instance's context occurs at this point. For more details on contexts, see [[6.1.2_Contexts and Context Switching| Section 6.1.2, Contexts and Context Switching]]. *Otherwise, if the candidate applet's context is not active, the Java Card RE shall set the candidate applet instance as the currently selected applet instance and call the **Applet.select** method. A context switch into the candidate applet instance's context occurs at this point. *If the applet instance's **select** method throws an exception or returns **false**, then the Java Card RE closes the new logical channel. The Java Card RE responds with status code **0x6999** (**SW_APPLET_SELECT_FAILED**). 11. The Java Card RE responds with status code **0x9000** (and if the P2=**0** variant is used, 1 data byte containing the newly assigned logical channel number.) Note - Unlike the SELECT FILE commands to select an applet instance, the MANAGE CHANNEL command is never forwarded to the applet instance.