Add MT6797 MD1 CCCI boot/RPC/FS, lpac eSIM, voice audio, and CONSYS Wi-Fi fix

This commit is contained in:
Luxferre committed 2026-11-25 08:07:24 +02:00
1 parent 1b93479666
commit 92a31539e6
34 files changed
+8556 -117

No files matched your search

+420 -30
View File
@@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -31,6 +32,11 @@
#define HIT_WIFI_DISC 12
#define HIT_DNS_CUSTOM 13
#define HIT_DNS_APPLY 14
#define HIT_CELL_INPUT 15
#define HIT_CELL_ADD 16
#define HIT_CELL_USE 17
#define HIT_CELL_DEL 18
#define HIT_CELL_DATA 19
enum {
WORK_NONE = 0,
@@ -39,6 +45,12 @@ enum {
WORK_WIFI_DISC,
WORK_DNS_APPLY,
WORK_DNS_TEST,
WORK_ESIM_LIST,
WORK_ESIM_DL,
WORK_ESIM_USE,
WORK_ESIM_DEL,
WORK_CELL_DATA,
WORK_CELL_CFG,
WORK_BT_PWR,
WORK_BT_SCAN,
WORK_BT_CONN,
@@ -52,17 +64,30 @@ typedef struct {
char col3[48];
} net_row_t;
typedef struct {
char idx_tag[8];
bool enabled;
char masked_iccid[32];
char label[128];
} esim_ui_row_t;
typedef struct {
gemui_app_t *app;
int tab; /* 0=Wi-Fi, 1=DNS, 2=Cellular/4G, 3=Bluetooth, 4=USB/HDMI */
int tab; /* 0=Wi-Fi, 1=DNS, 2=4G/eSIM, 3=Bluetooth, 4=USB/HDMI */
bool wifi_on;
bool wifi_connected;
bool cellular_on;
bool cell_data_up;
bool cell_ims_on;
bool cell_physical_sim;
bool esim_loaded;
bool bt_on;
bool bt_svc_up;
bool hdmi_on;
int dns_mode;
net_row_t rows[32];
esim_ui_row_t esim_profiles[16];
int esim_count;
geminux_wifi_group_t wifi_groups[GEMINUX_MAX_WIFI_GROUPS];
geminux_bt_dev_t bt_devs[GEMINUX_MAX_BT_DEVS];
int num_rows;
@@ -72,8 +97,14 @@ typedef struct {
char psk[128];
char active_dns[128];
char custom_dns[192];
char cell_slot[16];
char cell_apn[64];
char cell_ip[48];
char cell_input[256];
char cell_summary[128];
bool focus_psk;
bool focus_dns;
bool focus_cell;
bool show_psk;
pid_t worker_pid;
@@ -94,7 +125,7 @@ static uint64_t net_now_ms(void) {
static int net_visible_rows(const net_state_t *st) {
int h = st->app ? gemui_height(st->app) : 940;
int foot_h = (st->tab == 0 || st->tab == 1 || st->tab == 3) ? 94 : 0;
int foot_h = (st->tab <= 3) ? 94 : 0;
int box_h = h - (92 + 82 + 88) - 20 - foot_h;
int vis = (box_h - 8) / 72;
return vis > 0 ? vis : 1;
@@ -369,6 +400,149 @@ static void refresh_bt(net_state_t *st, const char *prev_mac) {
}
}
static void parse_esim_list_output(net_state_t *st, const char *raw) {
st->esim_count = 0;
st->esim_loaded = true;
if (!raw || !raw[0]) return;
char tmp[4096];
snprintf(tmp, sizeof(tmp), "%s", raw);
char *save = NULL;
for (char *ln = strtok_r(tmp, "\r\n", &save); ln; ln = strtok_r(NULL, "\r\n", &save)) {
if (strcmp(ln, "NO_PROFILES") == 0) {
st->esim_count = 0;
return;
}
if (strncmp(ln, "PROFILE\t", 8) != 0) continue;
if (st->esim_count >= 16) break;
char *f1 = ln + 8;
char *t2 = strchr(f1, '\t');
if (!t2) continue;
*t2++ = '\0';
char *t3 = strchr(t2, '\t');
if (!t3) continue;
*t3++ = '\0';
char *t4 = strchr(t3, '\t');
if (!t4) continue;
*t4++ = '\0';
esim_ui_row_t *p = &st->esim_profiles[st->esim_count++];
memset(p, 0, sizeof(*p));
snprintf(p->idx_tag, sizeof(p->idx_tag), "%s", f1);
p->enabled = (strcmp(t2, "enabled") == 0);
snprintf(p->masked_iccid, sizeof(p->masked_iccid), "%s", t3);
snprintf(p->label, sizeof(p->label), "%s", t4[0] ? t4 : "eSIM Profile");
}
}
static void refresh_cellular(net_state_t *st) {
char out[4096] = {0};
st->scroll_off = 0;
gemui_unix_cmd("/run/geminux/ccci.sock", "status", out, sizeof(out));
st->cellular_on = strstr(out, "READY") != NULL;
snprintf(st->cell_slot, sizeof(st->cell_slot), "esim");
snprintf(st->cell_apn, sizeof(st->cell_apn), "internet");
st->cell_ims_on = true;
st->cell_data_up = false;
st->cell_physical_sim = false;
st->cell_ip[0] = '\0';
st->cell_summary[0] = '\0';
char op[64] = "", tech[32] = "", sig[16] = "", mmst[32] = "offline";
out[0] = '\0';
const char *st_cmd[] = {"doas", "/usr/sbin/geminux-cellctl", "status", NULL};
if (gemui_run_cmd_timeout(st_cmd, out, sizeof(out), 1500) == 0 && out[0]) {
char *save = NULL;
for (char *ln = strtok_r(out, "\r\n", &save); ln; ln = strtok_r(NULL, "\r\n", &save)) {
if (strncmp(ln, "slot=", 5) == 0) {
snprintf(st->cell_slot, sizeof(st->cell_slot), "%s", ln + 5);
st->cell_physical_sim = (strcmp(st->cell_slot, "physical") == 0);
} else if (strncmp(ln, "apn=", 4) == 0) {
snprintf(st->cell_apn, sizeof(st->cell_apn), "%s", ln + 4);
} else if (strncmp(ln, "ims=", 4) == 0) {
st->cell_ims_on = (strcmp(ln + 4, "0") != 0);
} else if (strncmp(ln, "ccmni0_up=", 10) == 0) {
st->cell_data_up = (atoi(ln + 10) != 0);
} else if (strncmp(ln, "ccmni0_ip=", 10) == 0) {
if (strcmp(ln + 10, "none") != 0) snprintf(st->cell_ip, sizeof(st->cell_ip), "%s", ln + 10);
} else if (strncmp(ln, "mm_state=", 9) == 0) {
snprintf(mmst, sizeof(mmst), "%s", ln + 9);
} else if (strncmp(ln, "operator=", 9) == 0 && strcmp(ln + 9, "none") != 0) {
snprintf(op, sizeof(op), "%s", ln + 9);
} else if (strncmp(ln, "access_tech=", 12) == 0 && strcmp(ln + 12, "none") != 0) {
snprintf(tech, sizeof(tech), "%s", ln + 12);
} else if (strncmp(ln, "signal=", 7) == 0) {
snprintf(sig, sizeof(sig), "%s", ln + 7);
}
}
}
int r = 0;
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"SIM Slot: %s", st->cell_physical_sim ? "Physical Micro-SIM (Tray)" : "Soldered eSIM (ST33 eUICC)");
snprintf(st->rows[r].col2, sizeof(st->rows[0].col2), "%s",
st->cell_physical_sim ? "Physical SIM" : "Embedded eSIM");
snprintf(st->rows[r].col3, sizeof(st->rows[0].col3), "Switch Slot");
r++;
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"4G Data (ccmni0) — APN: %s", st->cell_apn);
snprintf(st->rows[r].col2, sizeof(st->rows[0].col2), "%s",
(st->cell_data_up && st->cell_ip[0]) ? st->cell_ip : "Disconnected");
snprintf(st->rows[r].col3, sizeof(st->rows[0].col3), "%s",
st->cell_data_up ? "Active" : "Down");
r++;
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"IMS / VoLTE & VoWiFi Calling");
snprintf(st->rows[r].col2, sizeof(st->rows[0].col2), "%s",
st->cell_ims_on ? "Enabled (CEVDP=3)" : "Disabled");
snprintf(st->rows[r].col3, sizeof(st->rows[0].col3), "%s",
st->cell_ims_on ? "ON" : "OFF");
r++;
if (!st->esim_loaded) {
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"eSIM Profiles: Press 'Scan eSIM Profiles' to query ST33");
snprintf(st->rows[r].col2, sizeof(st->rows[0].col2), "lpac AT Bridge");
snprintf(st->rows[r].col3, sizeof(st->rows[0].col3), "Ready");
r++;
} else if (st->esim_count == 0) {
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"eSIM Profiles: Empty (paste LPA:1$... below to install)");
st->rows[r].col2[0] = '\0';
st->rows[r].col3[0] = '\0';
r++;
} else {
for (int i = 0; i < st->esim_count && r < 24; i++) {
const esim_ui_row_t *p = &st->esim_profiles[i];
snprintf(st->rows[r].col1, sizeof(st->rows[0].col1),
"%seSIM %s: %.100s", p->enabled ? "* " : "", p->idx_tag, p->label);
snprintf(st->rows[r].col2, sizeof(st->rows[0].col2), "%s",
p->enabled ? "Enabled" : "Disabled");
snprintf(st->rows[r].col3, sizeof(st->rows[0].col3), "%s", p->masked_iccid);
r++;
}
}
st->num_rows = r;
if (st->sel_row < 0 || st->sel_row >= st->num_rows) st->sel_row = 0;
net_clamp_scroll(st);
if (op[0]) {
snprintf(st->status_text, sizeof(st->status_text),
"MD1: %s | %.48s (%.24s %.8s%%) | %.36s",
st->cellular_on ? "READY" : "GATED",
op, tech[0] ? tech : mmst, sig[0] ? sig : "0",
st->cell_data_up && st->cell_ip[0] ? st->cell_ip : st->cell_slot);
} else {
snprintf(st->status_text, sizeof(st->status_text),
"MT6797 MD1: %s | State: %.24s | Slot: %s | Data: %.36s",
st->cellular_on ? "READY" : "GATED", mmst, st->cell_slot,
st->cell_data_up && st->cell_ip[0] ? st->cell_ip : "down");
}
}
static void refresh_tab(net_state_t *st) {
char prev_key[96] = {0};
if (st->tab == 0 && st->sel_row >= 0 && st->sel_row < st->num_rows) {
@@ -378,7 +552,7 @@ static void refresh_tab(net_state_t *st) {
}
st->num_rows = 0;
st->sel_row = -1;
if (st->tab != 2) st->sel_row = -1;
static char out[16384];
out[0] = '\0';
@@ -387,23 +561,7 @@ static void refresh_tab(net_state_t *st) {
} else if (st->tab == 1) {
refresh_dns(st);
} else if (st->tab == 2) {
st->scroll_off = 0;
gemui_unix_cmd("/run/geminux/ccci.sock", "status", out, sizeof(out));
st->cellular_on = strstr(out, "READY") != NULL;
snprintf(st->status_text, sizeof(st->status_text), "CCCI Modem: %s",
out[0] ? out : "Degraded / No MD1 firmware loaded");
const char *mm[] = {"mmcli", "-m", "0", NULL};
if (gemui_run_cmd_timeout(mm, out, sizeof(out), 900) == 0) {
char *save = NULL;
for (char *ln = strtok_r(out, "\n", &save); ln && st->num_rows < 20; ln = strtok_r(NULL, "\n", &save)) {
while (*ln == ' ' || *ln == '|') ln++;
if (!ln[0]) continue;
snprintf(st->rows[st->num_rows].col1, sizeof(st->rows[0].col1), "%s", ln);
st->rows[st->num_rows].col2[0] = '\0';
st->rows[st->num_rows].col3[0] = '\0';
st->num_rows++;
}
}
refresh_cellular(st);
} else if (st->tab == 3) {
refresh_bt(st, prev_key);
} else {
@@ -429,6 +587,16 @@ static void refresh_tab(net_state_t *st) {
static void on_worker_timer(gemui_app_t *app, void *ud);
typedef int (*net_child_fn)(void *ctx);
typedef struct {
char cmd[32];
char arg1[256];
} cell_job_t;
static bool start_worker(net_state_t *st, int kind, const char *label,
int timeout_ms, net_child_fn fn, void *ctx);
static int child_cell_run(void *ctx);
static void cancel_worker(net_state_t *st, const char *toast) {
if (st->worker_pid <= 0) return;
kill(-st->worker_pid, SIGTERM);
@@ -555,6 +723,48 @@ static void on_worker_fd(gemui_app_t *app, int fd, void *ud) {
gemui_show_toast(app, rc == 0 ? "Bluetooth device disconnected" : "Disconnect failed", 2000);
} else if (kind == WORK_BT_REM) {
gemui_show_toast(app, rc == 0 ? "Removed Bluetooth device" : "Remove failed", 2000);
} else if (kind == WORK_ESIM_LIST) {
if (rc == 0) {
parse_esim_list_output(st, st->worker_out);
snprintf(toast, sizeof(toast), "ST33 eUICC: %d profile(s)", st->esim_count);
gemui_show_toast(app, toast, 2200);
} else {
snprintf(toast, sizeof(toast), err[0] ? "eSIM scan: %.175s" : "eSIM scan failed", err);
gemui_show_toast(app, toast, 3200);
}
} else if (kind == WORK_ESIM_DL || kind == WORK_ESIM_USE || kind == WORK_ESIM_DEL) {
if (rc == 0) {
if (kind == WORK_ESIM_DL) memset(st->cell_input, 0, sizeof(st->cell_input));
const char *msg = (kind == WORK_ESIM_DL) ? "eSIM profile installed"
: (kind == WORK_ESIM_DEL) ? "eSIM profile deleted"
: "eSIM profile state updated";
gemui_show_toast(app, msg, 2200);
cell_job_t rjob;
memset(&rjob, 0, sizeof(rjob));
snprintf(rjob.cmd, sizeof(rjob.cmd), "esim-list");
start_worker(st, WORK_ESIM_LIST, "Refreshing eSIM profiles...", 25000, child_cell_run, &rjob);
return;
} else {
snprintf(toast, sizeof(toast), err[0] ? "eSIM error: %.175s" : "eSIM operation failed", err);
gemui_show_toast(app, toast, 3400);
}
} else if (kind == WORK_CELL_DATA) {
if (rc == 0) {
gemui_show_toast(app, "4G LTE data state updated", 2200);
} else {
snprintf(toast, sizeof(toast), err[0] ? "4G error: %.175s" : "4G connection failed", err);
gemui_show_toast(app, toast, 3400);
}
} else if (kind == WORK_CELL_CFG) {
if (rc == 0) {
if (strncmp(st->cell_input, "LPA:", 4) != 0 && strncmp(st->cell_input, "1$", 2) != 0) {
memset(st->cell_input, 0, sizeof(st->cell_input));
}
gemui_show_toast(app, err[0] ? err : "Cellular setting updated", 2200);
} else {
snprintf(toast, sizeof(toast), err[0] ? "Cellular: %.175s" : "Cellular update failed", err);
gemui_show_toast(app, toast, 3200);
}
}
refresh_tab(st);
@@ -584,8 +794,6 @@ static void on_worker_timer(gemui_app_t *app, void *ud) {
gemui_request_redraw(app);
}
typedef int (*net_child_fn)(void *ctx);
static bool start_worker(net_state_t *st, int kind, const char *label,
int timeout_ms, net_child_fn fn, void *ctx) {
if (st->worker_pid > 0) {
@@ -675,8 +883,26 @@ static void wifi_delete_ssid_profiles(const char *ssid) {
}
}
static void ensure_wifi_iface(void) {
char air[16] = {0};
if (gemui_read_file_line("/run/geminux/airplane-mode", air, sizeof(air)) == 0 && air[0] == '1') {
return;
}
if (access("/sys/class/net/wlan0", F_OK) == 0) return;
const char *rst[] = {"doas", "/usr/bin/geminux-power-ctl", "wifi-restore", NULL};
gemui_run_cmd_timeout(rst, NULL, 0, 8000);
for (int i = 0; i < 25 && access("/sys/class/net/wlan0", F_OK) != 0; i++) {
poll(NULL, 0, 100);
}
if (access("/sys/class/net/wlan0", F_OK) == 0) {
const char *on[] = {"nmcli", "radio", "wifi", "on", NULL};
gemui_run_cmd_timeout(on, NULL, 0, 4000);
}
}
static int child_wifi_connect(void *ctx) {
wifi_job_t *j = ctx;
ensure_wifi_iface();
char out[512] = {0};
int cfg_rc = 0;
@@ -740,6 +966,7 @@ static int child_wifi_connect(void *ctx) {
static int child_wifi_rescan(void *ctx) {
(void)ctx;
ensure_wifi_iface();
char out[256] = {0};
const char *argv[] = {"nmcli", "dev", "wifi", "rescan", NULL};
int rc = gemui_run_cmd_timeout(argv, out, sizeof(out), 8000);
@@ -756,6 +983,99 @@ static int child_wifi_disconnect(void *ctx) {
return rc;
}
static int child_cell_run(void *ctx) {
const cell_job_t *j = ctx;
char out[4096] = {0};
const char *argv[5];
int n = 0;
argv[n++] = "doas";
argv[n++] = "/usr/sbin/geminux-cellctl";
argv[n++] = j->cmd;
if (j->arg1[0]) argv[n++] = j->arg1;
argv[n] = NULL;
int rc = gemui_run_cmd_timeout(argv, out, sizeof(out), 95000);
if (out[0]) fputs(out, stdout);
return rc;
}
static void paste_clipboard_into(char *dst, size_t dst_sz) {
char buf[512] = {0};
const char *clip_argv[] = {"xclip", "-o", "-selection", "clipboard", NULL};
if (gemui_run_cmd_timeout(clip_argv, buf, sizeof(buf), 400) != 0 || !buf[0]) {
const char *prim_argv[] = {"xclip", "-o", "-selection", "primary", NULL};
if (gemui_run_cmd_timeout(prim_argv, buf, sizeof(buf), 400) != 0 || !buf[0]) return;
}
size_t w = 0;
for (size_t i = 0; buf[i] && w + 1 < dst_sz; i++) {
unsigned char c = (unsigned char)buf[i];
if (c < 0x20 || c == ' ' || c == '\t') continue;
dst[w++] = (char)c;
}
if (w > 0) dst[w] = '\0';
}
static void trigger_cell_add(net_state_t *st) {
if (!st->cell_input[0]) {
gemui_show_toast(st->app, "Enter an LPA:1$... code or APN first", 1800);
st->focus_cell = true;
gemui_request_redraw(st->app);
return;
}
cell_job_t job;
memset(&job, 0, sizeof(job));
if (strncmp(st->cell_input, "LPA:", 4) == 0 || strncmp(st->cell_input, "lpa:", 4) == 0 ||
strncmp(st->cell_input, "1$", 2) == 0) {
snprintf(job.cmd, sizeof(job.cmd), "esim-download");
snprintf(job.arg1, sizeof(job.arg1), "%s", st->cell_input);
start_worker(st, WORK_ESIM_DL, "Downloading eSIM profile...", 95000, child_cell_run, &job);
} else {
snprintf(job.cmd, sizeof(job.cmd), "apn-set");
snprintf(job.arg1, sizeof(job.arg1), "%s", st->cell_input);
start_worker(st, WORK_CELL_CFG, "Saving cellular APN...", 8000, child_cell_run, &job);
}
}
static void trigger_cell_use(net_state_t *st) {
cell_job_t job;
memset(&job, 0, sizeof(job));
if (st->sel_row == 0) {
snprintf(job.cmd, sizeof(job.cmd), "sim-slot");
snprintf(job.arg1, sizeof(job.arg1), "%s", st->cell_physical_sim ? "esim" : "physical");
start_worker(st, WORK_CELL_CFG, "Switching SIM slot...", 12000, child_cell_run, &job);
} else if (st->sel_row == 1) {
snprintf(job.cmd, sizeof(job.cmd), "%s", st->cell_data_up ? "data-down" : "data-up");
start_worker(st, WORK_CELL_DATA,
st->cell_data_up ? "Disconnecting 4G LTE..." : "Connecting 4G LTE (ccmni0)...",
45000, child_cell_run, &job);
} else if (st->sel_row == 2) {
snprintf(job.cmd, sizeof(job.cmd), "ims-set");
snprintf(job.arg1, sizeof(job.arg1), "%s", st->cell_ims_on ? "off" : "on");
start_worker(st, WORK_CELL_CFG, "Updating IMS / VoLTE...", 12000, child_cell_run, &job);
} else if (st->esim_loaded && st->sel_row >= 3 && st->sel_row < 3 + st->esim_count) {
const esim_ui_row_t *p = &st->esim_profiles[st->sel_row - 3];
snprintf(job.cmd, sizeof(job.cmd), "%s", p->enabled ? "esim-disable" : "esim-enable");
snprintf(job.arg1, sizeof(job.arg1), "%s", p->idx_tag);
start_worker(st, WORK_ESIM_USE,
p->enabled ? "Disabling eSIM profile..." : "Enabling eSIM profile...",
30000, child_cell_run, &job);
} else {
gemui_show_toast(st->app, "Select Slot, 4G Data, IMS, or an eSIM profile", 1800);
}
}
static void trigger_cell_del(net_state_t *st) {
if (!st->esim_loaded || st->sel_row < 3 || st->sel_row >= 3 + st->esim_count) {
gemui_show_toast(st->app, "Select an eSIM profile row to delete", 1800);
return;
}
const esim_ui_row_t *p = &st->esim_profiles[st->sel_row - 3];
cell_job_t job;
memset(&job, 0, sizeof(job));
snprintf(job.cmd, sizeof(job.cmd), "esim-delete");
snprintf(job.arg1, sizeof(job.arg1), "%s", p->idx_tag);
start_worker(st, WORK_ESIM_DEL, "Deleting eSIM profile...", 30000, child_cell_run, &job);
}
typedef struct {
int mode;
char custom[192];
@@ -999,7 +1319,7 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
int pad = 20;
int top = 92;
int tab_w = (w - pad * 2 - 4 * 12) / 5;
static const char *tabs[5] = {"Wi-Fi", "DNS", "4G / CCCI", "Bluetooth", "USB & HDMI"};
static const char *tabs[5] = {"Wi-Fi", "DNS", "4G / eSIM", "Bluetooth", "USB & HDMI"};
for (int i = 0; i < 5; i++) {
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (tab_w + 12), top, tab_w, 66},
tabs[i], HIT_TAB, i, false, st->tab == i, false);
@@ -1022,9 +1342,10 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
dns_act, HIT_ACTION, 1, st->worker_pid == 0, st->worker_pid > 0, false);
} else if (st->tab == 2) {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"MT6797 Modem Active", st->cellular_on, HIT_TOGGLE, 2, false);
"MT6797 Cellular Radio", st->cellular_on, HIT_TOGGLE, 2, false);
const char *esim_act = (st->worker_pid > 0) ? "Cancel Operation" : "Scan eSIM Profiles";
gemui_draw_button(app, cr, (gemui_rect_t){pad + ctrl_w + 12, cy, ctrl_w, 72},
"Reset CCCI Modem", HIT_ACTION, 2, false, false, false);
esim_act, HIT_ACTION, 2, st->worker_pid == 0, st->worker_pid > 0, false);
} else if (st->tab == 3) {
gemui_draw_toggle(app, cr, (gemui_rect_t){pad, cy, ctrl_w, 72},
"Bluetooth Radio", st->bt_on, HIT_TOGGLE, 3, false);
@@ -1039,7 +1360,7 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
"Mirror Primary Display", HIT_ACTION, 4, true, false, false);
}
int foot_h = (st->tab == 0 || st->tab == 1 || st->tab == 3) ? 94 : 0;
int foot_h = (st->tab <= 3) ? 94 : 0;
gemui_rect_t box = {pad, cy + 88, w - pad * 2, h - (cy + 88) - pad - foot_h};
gemui_fill_round(cr, box, 12, t->bg_bar);
gemui_stroke_round(cr, box, 12, 1.5, t->border);
@@ -1093,6 +1414,24 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
st->custom_dns, false, st->focus_dns, HIT_DNS_CUSTOM, 0);
gemui_draw_button(app, cr, (gemui_rect_t){w - pad - aw, h - 92, aw, 72},
"Apply DNS Profile", HIT_DNS_APPLY, 0, true, false, false);
} else if (st->tab == 2) {
int dw = 210;
int rmw = 180;
int usew = 220;
int addw = 210;
int iw = w - pad * 2 - dw - rmw - usew - addw - 48;
gemui_draw_input(app, cr, (gemui_rect_t){pad, h - 92, iw, 72},
"Paste LPA:1$smdp$code (Ctrl+V) or enter APN...",
st->cell_input, false, st->focus_cell, HIT_CELL_INPUT, 0);
gemui_draw_button(app, cr, (gemui_rect_t){pad + iw + 12, h - 92, addw, 72},
"Add eSIM / APN", HIT_CELL_ADD, 0, true, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + iw + addw + 24, h - 92, usew, 72},
"Enable / Toggle", HIT_CELL_USE, 0, false, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + iw + addw + usew + 36, h - 92, rmw, 72},
"Delete eSIM", HIT_CELL_DEL, 0, false, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){w - pad - dw, h - 92, dw, 72},
st->cell_data_up ? "Disconnect 4G" : "Connect 4G",
HIT_CELL_DATA, 0, !st->cell_data_up, st->cell_data_up, false);
} else if (st->tab == 3) {
int bw = (w - pad * 2 - 3 * 12) / 4;
gemui_draw_button(app, cr, (gemui_rect_t){pad, h - 92, bw, 72},
@@ -1114,6 +1453,7 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
st->tab = (st->tab + 1) % 5;
st->focus_psk = false;
st->focus_dns = false;
st->focus_cell = false;
refresh_tab(st);
gemui_request_redraw(app);
} else if (ks == XK_Up && st->num_rows > 0) {
@@ -1129,7 +1469,10 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
} else if (ks == XK_Return || ks == XK_KP_Enter) {
if (st->tab == 0) connect_selected_wifi(st);
else if (st->tab == 1) apply_selected_dns(st);
else if (st->tab == 3) start_bt_dev_action(st, WORK_BT_CONN);
else if (st->tab == 2) {
if (st->focus_cell && st->cell_input[0]) trigger_cell_add(st);
else trigger_cell_use(st);
} else if (st->tab == 3) start_bt_dev_action(st, WORK_BT_CONN);
} else if ((ks == XK_BackSpace || ks == XK_Delete) && st->tab == 0 && (st->focus_psk || st->sel_row >= 0)) {
st->focus_psk = true;
gemui_utf8_pop_char(st->psk);
@@ -1139,6 +1482,10 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
st->sel_row = GEMINUX_DNS_CUSTOM;
gemui_utf8_pop_char(st->custom_dns);
gemui_request_redraw(app);
} else if ((ks == XK_BackSpace || ks == XK_Delete) && st->tab == 2 && (st->focus_cell || st->cell_input[0])) {
st->focus_cell = true;
gemui_utf8_pop_char(st->cell_input);
gemui_request_redraw(app);
} else if ((state & ControlMask) && (ks == XK_u || ks == XK_U) && st->tab == 0) {
st->focus_psk = true;
memset(st->psk, 0, sizeof(st->psk));
@@ -1148,6 +1495,14 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
st->sel_row = GEMINUX_DNS_CUSTOM;
memset(st->custom_dns, 0, sizeof(st->custom_dns));
gemui_request_redraw(app);
} else if ((state & ControlMask) && (ks == XK_u || ks == XK_U) && st->tab == 2) {
st->focus_cell = true;
memset(st->cell_input, 0, sizeof(st->cell_input));
gemui_request_redraw(app);
} else if ((state & ControlMask) && (ks == XK_v || ks == XK_V) && st->tab == 2) {
paste_clipboard_into(st->cell_input, sizeof(st->cell_input));
st->focus_cell = true;
gemui_request_redraw(app);
} else if (st->tab == 0 && (st->focus_psk || st->sel_row >= 0) && utf8 && utf8[0]) {
st->focus_psk = true;
size_t cur = strlen(st->psk), add = strlen(utf8);
@@ -1163,6 +1518,13 @@ static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *
memcpy(st->custom_dns + cur, utf8, add + 1);
gemui_request_redraw(app);
}
} else if (st->tab == 2 && utf8 && utf8[0]) {
st->focus_cell = true;
size_t cur = strlen(st->cell_input), add = strlen(utf8);
if (cur + add < sizeof(st->cell_input)) {
memcpy(st->cell_input + cur, utf8, add + 1);
gemui_request_redraw(app);
}
}
}
@@ -1190,11 +1552,13 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
st->tab = hit->val;
st->focus_psk = false;
st->focus_dns = false;
st->focus_cell = false;
refresh_tab(st);
} else if (hit->id == HIT_ROW) {
st->sel_row = hit->val;
if (st->tab == 0) st->focus_psk = true;
else if (st->tab == 1) st->focus_dns = (hit->val == GEMINUX_DNS_CUSTOM);
else if (st->tab == 2) st->focus_cell = false;
} else if (hit->id == HIT_PSK) {
st->focus_psk = true;
} else if (hit->id == HIT_SHOW_PSK) {
@@ -1212,6 +1576,25 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
} else if (hit->id == HIT_DNS_APPLY) {
apply_selected_dns(st);
return;
} else if (hit->id == HIT_CELL_INPUT) {
st->focus_cell = true;
} else if (hit->id == HIT_CELL_ADD) {
trigger_cell_add(st);
return;
} else if (hit->id == HIT_CELL_USE) {
trigger_cell_use(st);
return;
} else if (hit->id == HIT_CELL_DEL) {
trigger_cell_del(st);
return;
} else if (hit->id == HIT_CELL_DATA) {
cell_job_t job;
memset(&job, 0, sizeof(job));
snprintf(job.cmd, sizeof(job.cmd), "%s", st->cell_data_up ? "data-down" : "data-up");
start_worker(st, WORK_CELL_DATA,
st->cell_data_up ? "Disconnecting 4G LTE..." : "Connecting 4G LTE (ccmni0)...",
45000, child_cell_run, &job);
return;
} else if (hit->id == HIT_BT_CONN) {
start_bt_dev_action(st, WORK_BT_CONN);
return;
@@ -1267,9 +1650,16 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
}
return;
} else if (hit->val == 2) {
gemui_unix_cmd("/run/geminux/ccci.sock", "reset", NULL, 0);
gemui_show_toast(app, "Sent CCCI reset request", 1600);
refresh_tab(st);
if (st->worker_pid > 0) {
cancel_worker(st, "Cancelled operation");
} else {
cell_job_t job;
memset(&job, 0, sizeof(job));
snprintf(job.cmd, sizeof(job.cmd), "esim-list");
start_worker(st, WORK_ESIM_LIST, "Scanning ST33 eUICC profiles...", 25000,
child_cell_run, &job);
}
return;
} else if (hit->val == 3) {
if (st->worker_pid > 0) {
cancel_worker(st, st->worker_kind == WORK_BT_SCAN ? "Bluetooth scan stopped" : "Cancelled");