450 lines
17 KiB
Python
Executable File
450 lines
17 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Verify MT6797 CCCI UAPI header constants, 16-byte framing, and CCCI_FS server."""
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
HDR_PATH = os.path.join(BASE_DIR, "prebuilt", "kernel", "include", "linux", "mt6797_ccci.h")
|
|
PROTO_C = os.path.join(BASE_DIR, "src", "geminux-daemons", "geminux-ccci-proto.c")
|
|
FS_C = os.path.join(BASE_DIR, "src", "geminux-daemons", "geminux-ccci-fs.c")
|
|
CELL_C = os.path.join(BASE_DIR, "src", "geminux-daemons", "geminux-cell-proto.c")
|
|
DAEMON_INC = os.path.join(BASE_DIR, "src", "geminux-daemons")
|
|
KERNEL_INC = os.path.join(BASE_DIR, "prebuilt", "kernel", "include")
|
|
|
|
C_TEST = r"""
|
|
#define _POSIX_C_SOURCE 200809L
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include "geminux-ccci-proto.h"
|
|
#include "geminux-ccci-fs.h"
|
|
#include "geminux-cell-proto.h"
|
|
|
|
typedef struct {
|
|
uint8_t pkts[8][4096];
|
|
size_t lens[8];
|
|
size_t count;
|
|
} capture_t;
|
|
|
|
static int capture_send(const uint8_t *pkt, size_t pkt_len, void *user) {
|
|
capture_t *cap = (capture_t *)user;
|
|
assert(cap->count < 8);
|
|
assert(pkt_len <= 4096);
|
|
memcpy(cap->pkts[cap->count], pkt, pkt_len);
|
|
cap->lens[cap->count] = pkt_len;
|
|
cap->count++;
|
|
return 0;
|
|
}
|
|
|
|
static uint32_t le32(const uint8_t *p) {
|
|
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
|
|
((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
|
|
}
|
|
|
|
static void put32(uint8_t *p, uint32_t v) {
|
|
p[0] = (uint8_t)(v & 0xffU);
|
|
p[1] = (uint8_t)((v >> 8) & 0xffU);
|
|
p[2] = (uint8_t)((v >> 16) & 0xffU);
|
|
p[3] = (uint8_t)((v >> 24) & 0xffU);
|
|
}
|
|
|
|
static size_t append_lv_str16(uint8_t *dst, const char *s) {
|
|
size_t slen = strlen(s);
|
|
uint32_t bytes = (uint32_t)((slen + 1U) * 2U);
|
|
size_t aligned = (bytes + 3U) & ~(size_t)3U;
|
|
put32(dst, bytes);
|
|
memset(dst + 4, 0, aligned);
|
|
for (size_t i = 0; i < slen; i++) {
|
|
dst[4 + i * 2] = (uint8_t)s[i];
|
|
}
|
|
return 4 + aligned;
|
|
}
|
|
|
|
static size_t append_lv_bytes(uint8_t *dst, const void *src, uint32_t bytes) {
|
|
size_t aligned = (bytes + 3U) & ~(size_t)3U;
|
|
put32(dst, bytes);
|
|
memset(dst + 4, 0, aligned);
|
|
if (bytes > 0) memcpy(dst + 4, src, bytes);
|
|
return 4 + aligned;
|
|
}
|
|
|
|
static size_t append_lv_u32(uint8_t *dst, uint32_t v) {
|
|
uint8_t raw[4];
|
|
put32(raw, v);
|
|
return append_lv_bytes(dst, raw, 4);
|
|
}
|
|
|
|
static void build_hdr(uint8_t *pkt, uint32_t data0, uint32_t total,
|
|
uint32_t slot, uint32_t op) {
|
|
put32(pkt + 0, data0);
|
|
put32(pkt + 4, total);
|
|
put32(pkt + 8, MT6797_CCCI_CH_FS_RX);
|
|
put32(pkt + 12, slot);
|
|
put32(pkt + 16, op);
|
|
}
|
|
|
|
static void send_fs_req(geminux_ccci_fs_t *fs, capture_t *cap,
|
|
uint32_t slot, uint32_t op,
|
|
const uint8_t *stream, size_t slen) {
|
|
cap->count = 0;
|
|
size_t off = 0;
|
|
do {
|
|
size_t clen = slen - off;
|
|
if (clen > GEMINUX_CCCI_FS_MAX_CHUNK) clen = GEMINUX_CCCI_FS_MAX_CHUNK;
|
|
bool more = (off + clen < slen);
|
|
uint8_t pkt[GEMINUX_CCCI_FS_HDR_LEN + GEMINUX_CCCI_FS_MAX_CHUNK];
|
|
build_hdr(pkt, more ? GEMINUX_CCCI_FS_MORE : 0U,
|
|
(uint32_t)(GEMINUX_CCCI_FS_HDR_LEN + clen), slot, op);
|
|
memcpy(pkt + GEMINUX_CCCI_FS_HDR_LEN, stream + off, clen);
|
|
assert(geminux_ccci_fs_process_packet(fs, pkt, GEMINUX_CCCI_FS_HDR_LEN + clen,
|
|
capture_send, cap) == 0);
|
|
if (more) assert(cap->count == 0);
|
|
off += clen;
|
|
} while (off < slen);
|
|
assert(cap->count >= 1);
|
|
}
|
|
|
|
int main(void) {
|
|
assert(sizeof(struct mt6797_ccci_header) == 16);
|
|
assert(sizeof(struct mt6797_ccci_md_query_ap_feature) == 72);
|
|
assert(sizeof(struct mt6797_ccci_ap_query_md_feature) == 100);
|
|
|
|
uint32_t chword = MT6797_CCCI_CHAN_PACK(15U, 0x123U, 1U);
|
|
assert(MT6797_CCCI_CHAN_ID(chword) == 15U);
|
|
assert(MT6797_CCCI_CHAN_SEQ(chword) == 0x123U);
|
|
assert(MT6797_CCCI_CHAN_ASSERT(chword) == 1U);
|
|
|
|
geminux_ccci_sm_t sm;
|
|
geminux_ccci_sm_init(&sm);
|
|
assert(sm.state == MT6797_MD_STATE_GATED);
|
|
|
|
/* Little-endian wire encoding of HS1 on CONTROL_RX (channel 0) */
|
|
uint8_t hs1_wire[16] = {
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0xff, 0xff, 0xff, 0xff,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x2a, 0x00, 0x00, 0x00,
|
|
};
|
|
struct mt6797_ccci_header rx, tx;
|
|
bool need_reply = false;
|
|
geminux_ccci_unpack_hdr(hs1_wire, &rx);
|
|
assert(rx.channel == MT6797_CCCI_CH_CONTROL_RX);
|
|
assert(rx.data1 == MT6797_CCCI_MSG_HS1);
|
|
assert(rx.reserved == 42U);
|
|
|
|
assert(geminux_ccci_handle_ctrl(&sm, &rx, &tx, &need_reply));
|
|
assert(need_reply);
|
|
assert(sm.state == MT6797_MD_STATE_HS1);
|
|
assert(tx.channel == MT6797_CCCI_CH_CONTROL_TX);
|
|
assert(tx.data1 == MT6797_CCCI_MSG_HS1);
|
|
assert(tx.reserved == 42U);
|
|
|
|
struct mt6797_ccci_header ready_rx;
|
|
geminux_ccci_pack_hdr(&ready_rx, 0, MT6797_CCCI_MSG_NORMAL_BOOT_READY,
|
|
MT6797_CCCI_CH_CONTROL_RX, 0);
|
|
assert(geminux_ccci_handle_ctrl(&sm, &ready_rx, &tx, &need_reply));
|
|
assert(!need_reply);
|
|
assert(sm.state == MT6797_MD_STATE_READY);
|
|
|
|
struct mt6797_ccci_header ex_rx;
|
|
geminux_ccci_pack_hdr(&ex_rx, 1, MT6797_CCCI_MSG_MD_EX,
|
|
MT6797_CCCI_CH_CONTROL_RX, 0);
|
|
assert(geminux_ccci_handle_ctrl(&sm, &ex_rx, &tx, &need_reply));
|
|
assert(sm.state == MT6797_MD_STATE_EXCEPTION);
|
|
|
|
/* Clean-room CCCI_FS server tests */
|
|
char tmpl[] = "/tmp/geminux-fs-root-XXXXXX";
|
|
char *root = mkdtemp(tmpl);
|
|
assert(root != NULL);
|
|
|
|
geminux_ccci_fs_t fs;
|
|
geminux_ccci_fs_init(&fs, root, NULL);
|
|
capture_t cap;
|
|
uint8_t sbuf[8192];
|
|
size_t pos;
|
|
|
|
/* 1. CREATEDIR Z:\NVRAM */
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_str16(sbuf + 4, "Z:\\NVRAM");
|
|
send_fs_req(&fs, &cap, 1U, GEMINUX_CCCI_FS_OP_CREATEDIR, sbuf, pos);
|
|
assert(le32(cap.pkts[0] + 16) == 0xFFFF1007U);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_str16(sbuf + 4, "Z:\\NVRAM\\TEST");
|
|
send_fs_req(&fs, &cap, 1U, GEMINUX_CCCI_FS_OP_CREATEDIR, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
|
|
/* 2. OPEN + multi-fragment WRITE (5000 bytes) + GETFILESIZE + CLOSE */
|
|
put32(sbuf, 2);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "Z:\\NVRAM\\TEST\\lid01.bin");
|
|
pos += append_lv_u32(sbuf + pos, 0x00020000U); /* FS_CREATE_ALWAYS */
|
|
send_fs_req(&fs, &cap, 2U, GEMINUX_CCCI_FS_OP_OPEN, sbuf, pos);
|
|
assert(le32(cap.pkts[0] + 16) == 0xFFFF1001U);
|
|
int32_t fh = (int32_t)le32(cap.pkts[0] + 28);
|
|
assert(fh > 0);
|
|
|
|
uint8_t payload[5000];
|
|
for (size_t i = 0; i < sizeof(payload); i++) payload[i] = (uint8_t)((i * 37U + 11U) & 0xffU);
|
|
put32(sbuf, 3);
|
|
pos = 4;
|
|
pos += append_lv_u32(sbuf + pos, (uint32_t)fh);
|
|
pos += append_lv_bytes(sbuf + pos, payload, sizeof(payload));
|
|
pos += append_lv_u32(sbuf + pos, sizeof(payload));
|
|
send_fs_req(&fs, &cap, 2U, GEMINUX_CCCI_FS_OP_WRITE, sbuf, pos);
|
|
assert(le32(cap.pkts[0] + 16) == 0xFFFF1004U);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
assert(le32(cap.pkts[0] + 36) == sizeof(payload));
|
|
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_u32(sbuf + 4, (uint32_t)fh);
|
|
send_fs_req(&fs, &cap, 2U, GEMINUX_CCCI_FS_OP_GETFILESIZE, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
assert(le32(cap.pkts[0] + 36) == sizeof(payload));
|
|
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_u32(sbuf + 4, (uint32_t)fh);
|
|
send_fs_req(&fs, &cap, 2U, GEMINUX_CCCI_FS_OP_CLOSE, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
|
|
/* 3. CMPT_READ (multi-fragment TX reassembly verification) */
|
|
uint8_t cmpt_req[40] = {0};
|
|
put32(cmpt_req + 0x00, 0x1BU); /* OPEN | GETFILESIZE | READ | CLOSE */
|
|
put32(cmpt_req + 0x0c, 0x00000100U); /* FS_READ_ONLY */
|
|
put32(cmpt_req + 0x20, sizeof(payload));
|
|
put32(sbuf, 2);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "z:\\nvram\\test\\LID01.BIN");
|
|
pos += append_lv_bytes(sbuf + pos, cmpt_req, sizeof(cmpt_req));
|
|
send_fs_req(&fs, &cap, 3U, GEMINUX_CCCI_FS_OP_CMPT_READ, sbuf, pos);
|
|
assert(cap.count == 2);
|
|
assert(le32(cap.pkts[0] + 0) == GEMINUX_CCCI_FS_MORE);
|
|
assert(le32(cap.pkts[0] + 12) == 3U);
|
|
assert(le32(cap.pkts[0] + 16) == 0xFFFF1022U);
|
|
assert(cap.lens[0] == GEMINUX_CCCI_FS_HDR_LEN + GEMINUX_CCCI_FS_MAX_CHUNK);
|
|
assert(le32(cap.pkts[1] + 0) == 0U);
|
|
assert(le32(cap.pkts[1] + 16) == 0xFFFF1022U);
|
|
|
|
uint8_t reasm[8192];
|
|
size_t rlen = 0;
|
|
for (size_t i = 0; i < cap.count; i++) {
|
|
size_t clen = cap.lens[i] - GEMINUX_CCCI_FS_HDR_LEN;
|
|
memcpy(reasm + rlen, cap.pkts[i] + GEMINUX_CCCI_FS_HDR_LEN, clen);
|
|
rlen += clen;
|
|
}
|
|
assert(le32(reasm) == 4U);
|
|
assert(le32(reasm + 4) == 8U);
|
|
assert(le32(reasm + 8) == 0x1BU);
|
|
assert((int32_t)le32(reasm + 12) == 0);
|
|
assert(le32(reasm + 20) == sizeof(payload));
|
|
assert(le32(reasm + 28) == sizeof(payload));
|
|
assert(le32(reasm + 32) == sizeof(payload));
|
|
assert(memcmp(reasm + 36, payload, sizeof(payload)) == 0);
|
|
|
|
/* 4. Case-insensitive GETATTRIBUTES, FINDFIRST/FINDNEXT/FINDCLOSE, GETDISKINFO */
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_str16(sbuf + 4, "z:\\nvram\\test\\LID01.BIN");
|
|
send_fs_req(&fs, &cap, 0U, GEMINUX_CCCI_FS_OP_GETATTRIBUTES, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0x20);
|
|
|
|
uint8_t bzero = 0;
|
|
put32(sbuf, 4);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "Z:\\NVRAM\\TEST\\*.*");
|
|
pos += append_lv_bytes(sbuf + pos, &bzero, 1);
|
|
pos += append_lv_bytes(sbuf + pos, &bzero, 1);
|
|
pos += append_lv_u32(sbuf + pos, 260U);
|
|
send_fs_req(&fs, &cap, 0U, GEMINUX_CCCI_FS_OP_FINDFIRST, sbuf, pos);
|
|
int32_t find_h = (int32_t)le32(cap.pkts[0] + 28);
|
|
assert(find_h > 0);
|
|
assert(le32(cap.pkts[0] + 32) == 52U);
|
|
assert(le32(cap.pkts[0] + 64) == sizeof(payload));
|
|
|
|
put32(sbuf, 1);
|
|
pos = 4 + append_lv_u32(sbuf + 4, (uint32_t)find_h);
|
|
send_fs_req(&fs, &cap, 0U, GEMINUX_CCCI_FS_OP_FINDCLOSE, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
|
|
put32(sbuf, 2);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "Z:\\");
|
|
pos += append_lv_u32(sbuf + pos, 0U);
|
|
send_fs_req(&fs, &cap, 0U, GEMINUX_CCCI_FS_OP_GETDISKINFO, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 32);
|
|
assert(le32(cap.pkts[0] + 32) == 84U);
|
|
|
|
/* 5. Path traversal rejection */
|
|
put32(sbuf, 2);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "Z:\\NVRAM\\..\\..\\etc\\passwd");
|
|
pos += append_lv_u32(sbuf + pos, 0x00000100U);
|
|
send_fs_req(&fs, &cap, 4U, GEMINUX_CCCI_FS_OP_OPEN, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == -2);
|
|
|
|
/* 6. XDELETE recursive cleanup of temp dir */
|
|
put32(sbuf, 2);
|
|
pos = 4;
|
|
pos += append_lv_str16(sbuf + pos, "Z:\\NVRAM");
|
|
pos += append_lv_u32(sbuf + pos, 7U);
|
|
send_fs_req(&fs, &cap, 0U, GEMINUX_CCCI_FS_OP_XDELETE, sbuf, pos);
|
|
assert((int32_t)le32(cap.pkts[0] + 28) == 0);
|
|
geminux_ccci_fs_reset(&fs);
|
|
rmdir(root);
|
|
|
|
/* 7. Cellular / lpac PTY AT normalizer + LPA + JSON + CGCONTRDP tests */
|
|
char nout[256];
|
|
bool in_ccho = false;
|
|
geminux_esim_track_tx_cmd("AT+CCHO=\"A0000005591010FFFFFFFF8900000100\"", &in_ccho);
|
|
assert(in_ccho);
|
|
assert(geminux_esim_normalize_at_line("1", in_ccho, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "+CCHO: 1\r\n") == 0);
|
|
assert(geminux_esim_normalize_at_line("OK", in_ccho, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "OK\r\n") == 0);
|
|
|
|
in_ccho = false;
|
|
geminux_esim_track_tx_cmd("AT+CCHO=?", &in_ccho);
|
|
assert(!in_ccho);
|
|
assert(geminux_esim_normalize_at_line("1", false, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "1\r\n") == 0);
|
|
assert(geminux_esim_normalize_at_line("+CME ERROR: 100", false, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "ERROR\r\n") == 0);
|
|
assert(geminux_esim_normalize_at_line("+CMS ERROR: 500", false, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "ERROR\r\n") == 0);
|
|
assert(geminux_esim_normalize_at_line("+EIND: 128", false, nout, sizeof(nout)) == 0);
|
|
assert(geminux_esim_normalize_at_line("+CEREG: 1", false, nout, sizeof(nout)) == 0);
|
|
assert(geminux_esim_normalize_at_line("+CGLA: 4,\"9000\"", false, nout, sizeof(nout)) > 0);
|
|
assert(strcmp(nout, "+CGLA: 4,\"9000\"\r\n") == 0);
|
|
|
|
char smdp[128], mid[128], ccode[64];
|
|
bool req_conf = false;
|
|
assert(geminux_parse_lpa_code("LPA:1$rsp.truphone.com$MATCH-123",
|
|
smdp, sizeof(smdp), mid, sizeof(mid),
|
|
ccode, sizeof(ccode), &req_conf) == 0);
|
|
assert(strcmp(smdp, "rsp.truphone.com") == 0);
|
|
assert(strcmp(mid, "MATCH-123") == 0);
|
|
assert(!req_conf);
|
|
assert(geminux_parse_lpa_code("LPA:1$smdp.example.com$ABC$$1",
|
|
smdp, sizeof(smdp), mid, sizeof(mid),
|
|
ccode, sizeof(ccode), &req_conf) == 0);
|
|
assert(strcmp(smdp, "smdp.example.com") == 0);
|
|
assert(strcmp(mid, "ABC") == 0);
|
|
assert(req_conf);
|
|
assert(geminux_parse_lpa_code("LPA:1$bad host$ABC;rm",
|
|
smdp, sizeof(smdp), mid, sizeof(mid),
|
|
ccode, sizeof(ccode), &req_conf) != 0);
|
|
assert(geminux_validate_apn("internet.carrier.net"));
|
|
assert(!geminux_validate_apn("bad;apn"));
|
|
|
|
char masked[32];
|
|
geminux_mask_iccid("894450000000001234", masked, sizeof(masked));
|
|
assert(strncmp(masked, "8944", 4) == 0);
|
|
assert(strstr(masked, "1234") != NULL);
|
|
assert(strstr(masked, "5000") == NULL);
|
|
|
|
const char *lpac_ok =
|
|
"{\"type\":\"progress\",\"payload\":{\"message\":\"es10c_get_profiles_info\"}}\n"
|
|
"{\"type\":\"lpa\",\"payload\":{\"code\":0,\"message\":\"success\",\"data\":["
|
|
"{\"iccid\":\"89000000000000009999\",\"profileState\":\"enabled\","
|
|
"\"serviceProviderName\":\"CarrierA\",\"profileName\":\"Data\",\"profileNickname\":\"Main\"}"
|
|
"]}}\n";
|
|
geminux_esim_profile_t profs[4];
|
|
int ecode = -1;
|
|
char emsg[96] = {0};
|
|
int nprofs = geminux_parse_lpac_profiles_json(lpac_ok, profs, 4, &ecode, emsg, sizeof(emsg));
|
|
assert(nprofs == 1 && ecode == 0);
|
|
assert(profs[0].enabled);
|
|
assert(strcmp(profs[0].iccid, "89000000000000009999") == 0);
|
|
assert(strcmp(profs[0].label, "Main \xe2\x80\x94 CarrierA") == 0);
|
|
|
|
const char *lpac_err =
|
|
"{\"type\":\"lpa\",\"payload\":{\"code\":-1,\"message\":\"es9p\",\"data\":\"TLS error\"}}\n";
|
|
assert(geminux_parse_lpac_profiles_json(lpac_err, profs, 4, &ecode, emsg, sizeof(emsg)) < 0);
|
|
assert(ecode == -1);
|
|
assert(strstr(emsg, "TLS error") != NULL);
|
|
|
|
const char *rdp =
|
|
"+CGPADDR: 1,\"10.42.99.7\"\r\n"
|
|
"+CGCONTRDP: 1,5,\"internet\",\"10.42.99.7.255.255.255.0\",\"10.42.99.1\",\"1.1.1.1\",\"8.8.8.8\"\r\n";
|
|
char ip4[32], gw4[32], d1[32], d2[32];
|
|
assert(geminux_parse_cgpaddr_and_rdp(rdp, ip4, sizeof(ip4), gw4, sizeof(gw4),
|
|
d1, sizeof(d1), d2, sizeof(d2)) == 0);
|
|
assert(strcmp(ip4, "10.42.99.7") == 0);
|
|
assert(strcmp(gw4, "10.42.99.1") == 0);
|
|
assert(strcmp(d1, "1.1.1.1") == 0);
|
|
assert(strcmp(d2, "8.8.8.8") == 0);
|
|
return 0;
|
|
}
|
|
"""
|
|
|
|
|
|
def main():
|
|
with open(HDR_PATH, "r", encoding="utf-8") as handle:
|
|
hdr = handle.read()
|
|
|
|
expected = {
|
|
"MT6797_CCCI_CH_CONTROL_RX": r"\b0\b",
|
|
"MT6797_CCCI_CH_CONTROL_TX": r"\b1\b",
|
|
"MT6797_CCCI_CH_FS_RX": r"\b14\b",
|
|
"MT6797_CCCI_CH_FS_TX": r"\b15\b",
|
|
"MT6797_CCCI_CH_RPC_RX": r"\b32\b",
|
|
"MT6797_CCCI_CH_RPC_TX": r"\b33\b",
|
|
"MT6797_CCCI_CH_IMSV_UL": r"\b52\b",
|
|
"MT6797_CCCI_CH_IMSV_DL": r"\b53\b",
|
|
"MT6797_CCCI_CH_IMSEM_UL": r"\b101\b",
|
|
"MT6797_CCCI_CH_IMSEM_DL": r"\b102\b",
|
|
"MT6797_CCCI_CH_STATUS_RX": r"\b67\b",
|
|
"MT6797_CCCI_CH_STATUS_TX": r"\b68\b",
|
|
"CCCI_IOC_SET_HEADER": r"_IO\(MT6797_CCCI_MAGIC,\s*21\)",
|
|
"CCCI_IOC_CLR_HEADER": r"_IO\(MT6797_CCCI_MAGIC,\s*22\)",
|
|
"MT6797_CCCI_MSG_HS1": r"0xFFFFFFFFU",
|
|
"MT6797_CCCI_MSG_NORMAL_BOOT_READY": r"0xB0000002U",
|
|
"MT6797_CCCI_CTL_HS_V2": r"2U",
|
|
}
|
|
for macro, pat in expected.items():
|
|
if not re.search(rf"#define\s+{macro}\s+{pat}", hdr):
|
|
raise AssertionError(f"Missing or mismatched macro {macro} in {HDR_PATH}")
|
|
|
|
with tempfile.TemporaryDirectory(prefix="geminux-ccci-test-") as tmp:
|
|
src = os.path.join(tmp, "test_ccci.c")
|
|
bin_path = os.path.join(tmp, "test_ccci")
|
|
with open(src, "w", encoding="utf-8") as handle:
|
|
handle.write(C_TEST)
|
|
|
|
gcc = shutil.which("gcc")
|
|
if gcc:
|
|
subprocess.run(
|
|
[gcc, "-std=c11", "-Wall", "-Wextra", "-Werror",
|
|
"-I", DAEMON_INC, "-I", KERNEL_INC,
|
|
src, PROTO_C, FS_C, CELL_C, "-o", bin_path],
|
|
check=True,
|
|
)
|
|
subprocess.run([bin_path], check=True)
|
|
else:
|
|
subprocess.run(
|
|
["docker", "run", "--rm", "-v", f"{BASE_DIR}:/geminux:ro",
|
|
"-v", f"{tmp}:/work", "alpine:3.24", "sh", "-eu", "-c",
|
|
"apk add --no-cache build-base linux-headers >/dev/null && "
|
|
"gcc -std=c11 -Wall -Wextra -Werror -I/geminux/src/geminux-daemons "
|
|
"-I/geminux/prebuilt/kernel/include /work/test_ccci.c "
|
|
"/geminux/src/geminux-daemons/geminux-ccci-proto.c "
|
|
"/geminux/src/geminux-daemons/geminux-ccci-fs.c "
|
|
"/geminux/src/geminux-daemons/geminux-cell-proto.c -o /work/test_ccci && "
|
|
"/work/test_ccci"],
|
|
check=True,
|
|
)
|
|
|
|
print("[PASS] MT6797 CCCI 16-byte framing, CCCI_FS, lpac AT bridge, and PDN parser verified")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|