aa33d25466
TERMINAL PROFILE:
- GET /api/terminal-profile returns the profile in effect + the CLI default;
POST /api/terminal-profile validates ({profile}, hex, even, 1-255 bytes),
stores it in memory and re-sends it, resetting the STK session like
/api/rescue (the shared _resend_terminal_profile helper; rescue now
delegates to it). __main__ keeps server.cli_terminal_profile.
- Phone tab: a TERMINAL PROFILE block next to STATUS and Polling with the
current hex/byte count, Send (re-send) and Configure. The Configure
dialog has a device-model preset selector, a hex field and a per-bit
form generated from a 264-entry table for TS 102 223 V18.3.0 5.2 bytes
1-33 (pySim's table as scaffold, later bytes/3GPP bits added from the
spec; beyond the table generic RFU labels). Form <-> hex sync both
ways, hex authoritative, bits preserved. Apply posts the new value.
- Presets: Xiaomi Mi A1 (project default), Quectel GSM module example.
In-memory only, no persistence.
Custom files:
- Canonical paths rooted at MF / ADF.USIM / ADF.ISIM; entries are
{path, name, kind}. The editor now uses root + parent-DF selector +
4-hex FID + alias, requires the parent DF to be defined first, rejects
duplicates, rewrites descendants when a DF's path changes and cascades
deletes after a confirmation.
- Legacy forms are normalized on load/import (3F00/... -> MF/..., relative
a153/4954 resolved against the custom DFs); unresolvable entries are
dropped and reported in the list.
- Tree injection matches by exact parent path via the new pysimFsNodePath
(same-FID DFs under different parents no longer collide);
profilerCustomNameForPath uses the same normalization.
SW cache otaman-v167; help EN/RU + docs/api.md + AGENTS updated.
Tests: 236 Python + 371 frontend.
103 lines
3.7 KiB
JavaScript
103 lines
3.7 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const html = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
|
|
|
|
function extractFunc(src, name) {
|
|
const re = new RegExp('function\\s+' + name + '\\s*\\([^)]*\\)\\s*\\{');
|
|
const m = re.exec(src);
|
|
if (!m) throw new Error('function ' + name + ' not found');
|
|
let i = m.index + m[0].length - 1;
|
|
let depth = 0;
|
|
for (; i < src.length; i++) {
|
|
if (src[i] === '{') depth++;
|
|
else if (src[i] === '}') {
|
|
depth--;
|
|
if (depth === 0) break;
|
|
}
|
|
}
|
|
return src.slice(m.index, i + 1);
|
|
}
|
|
|
|
let code = 'var pysimCustomFiles = [];\n';
|
|
for (const fn of ['pysimFsNodePath', 'pysimCustomInject', 'pysimCustomParent', 'pysimCustomFid']) {
|
|
code += extractFunc(html, fn) + '\n';
|
|
}
|
|
eval(code);
|
|
|
|
function node(name, fid, parent, children) {
|
|
return { name, fid, parent: parent || null, children: children || null, isDir: true };
|
|
}
|
|
|
|
function tree() {
|
|
const mf = node('MF', '3F00', null, []);
|
|
const dfA = node('DF.A', '5F01', mf);
|
|
const dfB = node('DF.B', '5F02', mf);
|
|
const dfC = node('DF.C', '5F03', mf, [node('EF.X', '6F46', null)]);
|
|
dfC.children[0].parent = dfC;
|
|
const adf = node('ADF.USIM', '7FFF', mf);
|
|
const efImsi = node('EF.IMSI', '6F07', adf);
|
|
adf.children = [efImsi];
|
|
mf.children = [dfA, dfB, dfC, adf];
|
|
return { mf, dfA, dfB, dfC, adf, efImsi };
|
|
}
|
|
|
|
test('pysimFsNodePath builds canonical paths from MF and ADF roots', () => {
|
|
const t = tree();
|
|
assert.strictEqual(pysimFsNodePath(t.mf), 'MF');
|
|
assert.strictEqual(pysimFsNodePath(t.dfA), 'MF/5F01');
|
|
assert.strictEqual(pysimFsNodePath(t.dfC.children[0]), 'MF/5F03/6F46');
|
|
assert.strictEqual(pysimFsNodePath(t.adf), 'ADF.USIM');
|
|
assert.strictEqual(pysimFsNodePath(t.efImsi), 'ADF.USIM/6F07');
|
|
});
|
|
|
|
test('injection matches full paths, so same-FID DFs stay apart', () => {
|
|
const t = tree();
|
|
pysimCustomFiles = [
|
|
{ path: 'MF/5F01/6F46', name: 'EF.ONLY-A', kind: 'ef' },
|
|
{ path: 'MF/5F02/6F46', name: 'EF.ONLY-B', kind: 'ef' },
|
|
{ path: 'ADF.USIM/6F07', name: 'EF.MY-IMSI', kind: 'ef' },
|
|
];
|
|
pysimCustomInject(t.mf);
|
|
assert.strictEqual(t.mf.children.length, 4, 'MF-level injection adds nothing');
|
|
pysimCustomInject(t.dfA);
|
|
assert.strictEqual(t.dfA.children.length, 1);
|
|
assert.strictEqual(t.dfA.children[0].name, 'EF.ONLY-A');
|
|
assert.strictEqual(t.dfA.children[0].customPath, 'MF/5F01/6F46');
|
|
pysimCustomInject(t.dfB);
|
|
assert.strictEqual(t.dfB.children[0].name, 'EF.ONLY-B');
|
|
pysimCustomInject(t.dfC);
|
|
assert.strictEqual(t.dfC.children.length, 1, 'unrelated DF is untouched');
|
|
pysimCustomInject(t.adf);
|
|
assert.strictEqual(t.adf.children.length, 1);
|
|
assert.strictEqual(t.adf.children[0].name, 'EF.MY-IMSI');
|
|
assert.strictEqual(t.adf.children[0].customPath, 'ADF.USIM/6F07');
|
|
});
|
|
|
|
test('injection renames and marks an existing model node', () => {
|
|
const t = tree();
|
|
pysimCustomFiles = [{ path: 'MF/5F03/6F46', name: 'EF.RENAMED', kind: 'ef' }];
|
|
pysimCustomInject(t.dfC);
|
|
assert.strictEqual(t.dfC.children.length, 1);
|
|
assert.strictEqual(t.dfC.children[0].name, 'EF.RENAMED');
|
|
assert.strictEqual(t.dfC.children[0].custom, true);
|
|
});
|
|
|
|
test('injected DFs are directories and can host their own children', () => {
|
|
const t = tree();
|
|
pysimCustomFiles = [
|
|
{ path: 'MF/5F10', name: 'DF.NEW', kind: 'df' },
|
|
{ path: 'MF/5F10/6F46', name: 'EF.UNDER-NEW', kind: 'ef' },
|
|
];
|
|
pysimCustomInject(t.mf);
|
|
const df = t.mf.children.find(c => c.fid === '5F10');
|
|
assert.ok(df, 'custom DF injected into MF');
|
|
assert.strictEqual(df.isDir, true);
|
|
assert.strictEqual(pysimFsNodePath(df), 'MF/5F10');
|
|
pysimCustomInject(df);
|
|
assert.strictEqual(df.children.length, 1);
|
|
assert.strictEqual(df.children[0].name, 'EF.UNDER-NEW');
|
|
});
|