diff --git a/frontend/help-ru.html b/frontend/help-ru.html
index b986146..40d5eb9 100644
--- a/frontend/help-ru.html
+++ b/frontend/help-ru.html
@@ -482,7 +482,7 @@
Работа с сессией Card Application Toolkit. Три подвкладки: «Телефон» (меню STK, STATUS и опрос, подписанные события, журнал проактивных команд), «Конфигурация TR» (данные ответов, подставляемые в TERMINAL RESPONSE для проактивных команд) и «eSIM» (локальные операции с eUICC).
- Если карта выдала команду SET UP MENU, вверху этого представления появляется блок «Меню STK» с изумрудной кнопкой STK: <название>, открывающей оверлей меню (браузер STK-меню карты). Если карта не задала меню, вместо кнопки показывается «Меню не задано картой». Состояние меню обновляется при каждом открытии представления. Интерактивные проактивные команды всегда получают TERMINAL RESPONSE: оверлей ждёт вашего выбора, и если вы не ответили и не нажали Timeout, сервер сам отвечает результатом timeout через --menu-timeout секунд (по умолчанию 60, 0 отключает). Назад и Timeout продолжают диалог с картой: если карта в ответ выдаёт следующую проактивную команду (SELECT ITEM или DISPLAY TEXT), панель показывает её; кэшированное верхнее меню появляется только когда карте больше нечего выполнять.
+ Если карта выдала команду SET UP MENU, вверху этого представления появляется блок «Меню STK» с изумрудной кнопкой STK: <название>, открывающей оверлей меню (браузер STK-меню карты). Если карта не задала меню, вместо кнопки показывается «Меню не задано картой». Состояние меню обновляется при каждом открытии представления. Пункты меню, для которых карта передала Next Action Indicator (TS 102 223 §8.24), показывают его серым суффиксом (например, → SET UP MENU) — что карта выполнит при выборе пункта. Интерактивные проактивные команды всегда получают TERMINAL RESPONSE: оверлей ждёт вашего выбора, и если вы не ответили и не нажали Timeout, сервер сам отвечает результатом timeout через --menu-timeout секунд (по умолчанию 60, 0 отключает). Назад и Timeout продолжают диалог с картой: если карта в ответ выдаёт следующую проактивную команду (SELECT ITEM или DISPLAY TEXT), панель показывает её; кэшированное верхнее меню появляется только когда карте больше нечего выполнять.
8.2 Подписанные события (SET UP EVENT LIST)
События, которые отслеживает карта. У каждого события есть кнопка Отправить, открывающая форму, специфичную для типа события:
diff --git a/frontend/help.html b/frontend/help.html
index 1760838..432c668 100644
--- a/frontend/help.html
+++ b/frontend/help.html
@@ -481,7 +481,7 @@
Interacts with the Card Application Toolkit session. The view has three pills: Phone (STK menu, STATUS and polling, subscribed events, proactive command log), TR Config (response data injected into TERMINAL RESPONSEs for proactive commands) and eSIM (local eUICC operations).
- When the card has issued a SET UP MENU command, a “STK menu” block appears at the top of this view with an emerald STK: <title> button that opens the menu overlay (same as the card’s STK menu browser). If the card has not set up a menu, the block shows “No menu set by the card” instead. The menu state is refreshed each time the view is opened. User-interactive proactive commands always get a TERMINAL RESPONSE: the overlay pauses for your choice, and if you neither answer nor press Timeout, the server answers with a timeout result after the --menu-timeout seconds (default 60, 0 disables). Back and Timeout keep the dialogue with the card going: when the card replies with a further proactive command (SELECT ITEM or DISPLAY TEXT) the panel shows it; the cached top menu appears only when the card has nothing more to execute.
+ When the card has issued a SET UP MENU command, a “STK menu” block appears at the top of this view with an emerald STK: <title> button that opens the menu overlay (same as the card’s STK menu browser). If the card has not set up a menu, the block shows “No menu set by the card” instead. The menu state is refreshed each time the view is opened. Menu items whose card-provided Next Action Indicator (TS 102 223 §8.24) is present show it as a small gray suffix (e.g. → SET UP MENU) — what the card would do when the item is selected. User-interactive proactive commands always get a TERMINAL RESPONSE: the overlay pauses for your choice, and if you neither answer nor press Timeout, the server answers with a timeout result after the --menu-timeout seconds (default 60, 0 disables). Back and Timeout keep the dialogue with the card going: when the card replies with a further proactive command (SELECT ITEM or DISPLAY TEXT) the panel shows it; the cached top menu appears only when the card has nothing more to execute.
8.2 Subscribed events (SET UP EVENT LIST)
The events the card monitors. Each event has a Send button that opens a form specific to the event type:
diff --git a/frontend/index.html b/frontend/index.html
index e2b72fe..0c1b228 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -1559,7 +1559,7 @@
// ===== Version =====
// Single source of truth for the PWA version: shown in the header and used
// by the server version check in pysimConnect().
-const SIMPLE_VERSION = '3.5.2';
+const SIMPLE_VERSION = '3.5.3';
document.getElementById('app-version').textContent = 'v' + SIMPLE_VERSION;
// ===== Tab switching =====
@@ -7693,6 +7693,12 @@ async function stkMenuExit() {
stkMenuClose();
}
+// TS 102 223 8.24: the item's next action (coded like the Type of Command);
+// the server only attaches nai_name for values the table marks for the NAI.
+function stkMenuNaiSuffix(item) {
+ return (item && item.nai_name) ? '\u25b8 ' + item.nai_name : '';
+}
+
function stkMenuRenderItems() {
const content = document.getElementById('stk-menu-panel-content');
content.innerHTML = 'Loading...';
@@ -7700,7 +7706,9 @@ function stkMenuRenderItems() {
if (!data || !data.items) { content.innerHTML = 'No menu data'; return; }
let html = '';
data.items.forEach(item => {
- html += '
' + item.id + '' + esc(item.text) + '
';
+ const nai = stkMenuNaiSuffix(item);
+ html += '
' + item.id + '' + esc(item.text) + '' +
+ (nai ? '' + esc(nai) + '' : '') + '
';
});
html += '
';
content.innerHTML = html;
diff --git a/frontend/sw.js b/frontend/sw.js
index ed58cb7..254dcba 100644
--- a/frontend/sw.js
+++ b/frontend/sw.js
@@ -1,4 +1,4 @@
-const CACHE = 'simple-v254';
+const CACHE = 'simple-v255';
const URLS = [
'index.html',
'help.html',
diff --git a/frontend/tests/stk_menu.test.js b/frontend/tests/stk_menu.test.js
index f231a06..709db1a 100644
--- a/frontend/tests/stk_menu.test.js
+++ b/frontend/tests/stk_menu.test.js
@@ -22,6 +22,7 @@ function extractFunc(src, name, asyncFn) {
}
let code = extractFunc(html, 'stkMenuRespond', true) + '\n';
+code += extractFunc(html, 'stkMenuNaiSuffix') + '\n';
code += 'globalThis.esc = s => s;\n';
eval(code);
@@ -38,6 +39,14 @@ function setup(response) {
return calls;
}
+test('the STK menu item suffix shows the item next action (8.24)', () => {
+ assert.strictEqual(stkMenuNaiSuffix({ id: 1, text: 'Menu', nai: 0x25, nai_name: 'SET UP MENU' }),
+ '\u25b8 SET UP MENU');
+ // no NAI (or a reserved one, which the server drops) -> no suffix
+ assert.strictEqual(stkMenuNaiSuffix({ id: 2, text: 'Info' }), '');
+ assert.strictEqual(stkMenuNaiSuffix(null), '');
+});
+
test('back with a fetched SELECT ITEM continues the card dialogue', async () => {
const data = { type: 'select_item', items: [{ id: 1, text: 'Info' }] };
const calls = setup(data);
diff --git a/pyproject.toml b/pyproject.toml
index c0813d7..7b371da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pysim-simple-server"
-version = "3.5.2"
+version = "3.5.3"
description = "HTTP REST server wrapping pysim for the SIMple PWA"
requires-python = ">=3.8"
# pysim is a git-only dependency installed explicitly by setup.bat/setup.sh.
diff --git a/pysim_simple_server/server.py b/pysim_simple_server/server.py
index 2371ac1..2f194de 100644
--- a/pysim_simple_server/server.py
+++ b/pysim_simple_server/server.py
@@ -29,7 +29,7 @@ from osmocom.tlv import BER_TLV_IE
from osmocom.utils import rpad
-VERSION = '3.5.2'
+VERSION = '3.5.3'
MAX_ENVELOPE_SEGMENTS = 5 # max SMS segments for outgoing C-APDU in ENVELOPE
@@ -1691,12 +1691,12 @@ def _decode_cmd(cmd_type, raw, qualifier):
if cmd_type == 0x24:
items = _parse_select_item(raw)
if items:
- return [{'label': 'Items', 'value': ', '.join('%s. %s' % (it['id'], it['text']) for it in items)}]
+ return [{'label': 'Items', 'value': ', '.join(_item_line(it) for it in items)}]
return []
if cmd_type == 0x25:
items = _parse_setup_menu_items(raw)
if items:
- return [{'label': 'Items', 'value': ', '.join('%s. %s' % (it['id'], it['text']) for it in items)}]
+ return [{'label': 'Items', 'value': ', '.join(_item_line(it) for it in items)}]
return []
if cmd_type in (0x40, 0x42, 0x43):
return _decode_bip_cmd(cmd_type, raw)
@@ -3567,8 +3567,57 @@ def _parse_display_text(raw):
return None
+# TS 102 223 8.24 + Table 9.4: the Items Next Action Indicator reuses the
+# Type of Command coding, but only the values the table marks "Used for Next
+# Action Indicator". The ToC-only values are reserved there and shall be
+# ignored, as are '00' and any value not listed (8.24).
+NAI_TYPES = frozenset([
+ 0x10, 0x11, 0x12, 0x13, 0x15, # SET UP CALL / SEND SS / SEND USSD / SEND SM / LAUNCH BROWSER
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x28, # PLAY TONE .. SET UP IDLE MODE TEXT
+ 0x30, 0x31, 0x32, 0x33, # PERFORM CARD APDU .. GET READER STATUS
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, # BIP commands
+ 0x60, 0x61, 0x62, # MMS commands
+ 0x81, # end of the proactive session
+])
+
+
+def _nai_name(value):
+ """Items Next Action Indicator name (TS 102 223 Table 9.4); None = reserved."""
+ if value in NAI_TYPES:
+ return PROACTIVE_TYPE_NAMES.get(value)
+ if 0xF0 <= value <= 0xFE:
+ return 'Proprietary (0x%02X)' % value
+ return None
+
+
+def _attach_nai(items, nai):
+ """Attach an Items Next Action Indicator list (TS 102 223 8.24) to items.
+
+ One byte per item in list order; a short list leaves the tail without an
+ indicator, extra bytes are ignored, reserved values are skipped (8.24)."""
+ if not items or not nai:
+ return items
+ for i, item in enumerate(items):
+ if i >= len(nai):
+ break
+ name = _nai_name(nai[i])
+ if name:
+ item['nai'] = nai[i]
+ item['nai_name'] = name
+ return items
+
+
+def _item_line(item):
+ """'1. Menu' plus ' -> SET UP MENU' when the item has a next action."""
+ line = '%s. %s' % (item['id'], item['text'])
+ if item.get('nai_name'):
+ line += ' \u2192 ' + item['nai_name']
+ return line
+
+
def _parse_select_item(raw):
items = []
+ nai = None
if raw[0] == 0xD0:
off = _skip_ber_len(raw, 1)
while off < len(raw) - 1:
@@ -3581,11 +3630,14 @@ def _parse_select_item(raw):
pass
elif tag in (0x8F, 0x0F) and tlen >= 2:
items.append({'id': val[0], 'text': _decode_stk_text(val[1:])})
- return items
+ elif tag in (0x18, 0x98) and tlen >= 1:
+ nai = val
+ return _attach_nai(items, nai)
def _parse_setup_menu_items(raw):
items = []
+ nai = None
if not raw or raw[0] != 0xD0:
return items
off = _skip_ber_len(raw, 1)
@@ -3594,7 +3646,9 @@ def _parse_setup_menu_items(raw):
val = raw[off + 2: off + 2 + tlen]; off += 2 + tlen
if tag == 0x8F and tlen >= 2:
items.append({'id': val[0], 'text': _decode_stk_text(val[1:])})
- return items
+ elif tag in (0x18, 0x98) and tlen >= 1:
+ nai = val
+ return _attach_nai(items, nai)
def _handle_proactive_chain(scc, sw91, on_fetch=None, status_poll=True):
@@ -3676,6 +3730,7 @@ def _send_terminal_profile(scc, tp_hex):
off = _skip_ber_len(raw, 1)
menu = None
items = []
+ nai = None
while off < len(raw) - 1:
tag, tlen = raw[off], raw[off + 1]
val = raw[off + 2: off + 2 + tlen]
@@ -3697,9 +3752,12 @@ def _send_terminal_profile(scc, tp_hex):
except Exception:
txt = val[1:].hex()
items.append({'id': val[0], 'text': txt})
+ elif tag in (0x18, 0x98) and tlen >= 1:
+ nai = val
elif tag in (0x99, 0x19) and tlen >= 1:
event_list = [b for b in val]
if menu:
+ _attach_nai(items, nai)
sim_menu = menu
if fdata and cmd_type:
entry = _log_proactive(cmd_type, raw, cmd_qual, cmd_num)
diff --git a/tests/test_ota_helpers.py b/tests/test_ota_helpers.py
index e97d1c5..9430474 100644
--- a/tests/test_ota_helpers.py
+++ b/tests/test_ota_helpers.py
@@ -28,6 +28,8 @@ from pysim_simple_server.server import (
_decode_tr,
_log_proactive,
_ota_reference,
+ _parse_select_item,
+ _parse_setup_menu_items,
_record_tr,
_send_secured_packet,
_spi_from_bytes,
@@ -432,6 +434,43 @@ class TestProactiveDecode(unittest.TestCase):
r = _decode_cmd(0x05, bytes.fromhex('d00c810301050082028381990101'), None)
self.assertEqual(r, [{'label': 'Events', 'value': 'Call connected'}])
+ def test_decode_cmd_set_up_menu_with_next_action(self):
+ # TS 102 223 8.24: one NAI byte per item, in item order (UCS2 item text).
+ extras = bytes.fromhex(
+ '8F0A0180004D0065006E0075' # 1: 'Menu'
+ '8F0A028000430061006C006C' # 2: 'Call'
+ '18022510') # NAI: SET UP MENU, SET UP CALL
+ raw = self._cmd_raw(0x25, 0x00, extras)
+ items = _parse_setup_menu_items(raw)
+ self.assertEqual([it['nai'] for it in items], [0x25, 0x10])
+ self.assertEqual([it['nai_name'] for it in items], ['SET UP MENU', 'SET UP CALL'])
+ self.assertEqual(self._decoded(0x25, raw)['Items'],
+ '1. Menu \u2192 SET UP MENU, 2. Call \u2192 SET UP CALL')
+
+ def test_decode_cmd_next_action_reserved_is_ignored(self):
+ # '26' (PROVIDE LOCAL INFORMATION) is Type-of-Command only, so it is
+ # reserved for the NAI and shall be ignored (8.24).
+ extras = bytes.fromhex('8F0A0180004D0065006E0075' '180126')
+ raw = self._cmd_raw(0x25, 0x00, extras)
+ items = _parse_setup_menu_items(raw)
+ self.assertNotIn('nai', items[0])
+ self.assertNotIn('nai_name', items[0])
+ self.assertEqual(self._decoded(0x25, raw)['Items'], '1. Menu')
+
+ def test_decode_cmd_select_item_short_next_action_list(self):
+ # A short NAI list leaves the tail without an indicator; extra bytes
+ # beyond the item count are ignored (8.24).
+ extras = bytes.fromhex(
+ '8F0A0180004D0065006E0075'
+ '8F0A028000430061006C006C'
+ '180121')
+ raw = self._cmd_raw(0x24, 0x00, extras)
+ items = _parse_select_item(raw)
+ self.assertEqual(items[0]['nai_name'], 'DISPLAY TEXT')
+ self.assertNotIn('nai_name', items[1])
+ self.assertEqual(self._decoded(0x24, raw)['Items'],
+ '1. Menu \u2192 DISPLAY TEXT, 2. Call')
+
def test_decode_cmd_send_short_message(self):
# SEND SHORT MESSAGE with an SMS-SUBMIT TPDU carrying GSM-7 text.
tpdu = bytes.fromhex('010006912143F5000005E8329BFD06')