Add geminux-imsd (VoLTE/VoWiFi/SMS), kernel XFRM, and hardware Airplane Mode (Fn+F)
This commit is contained in:
1 parent
92a31539e6
commit
ac76431621
84 files changed
+4209
-103
No files matched your search
@@ -10,6 +10,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -22,6 +23,9 @@
|
||||
|
||||
#define MODEM_SOCK "/run/geminux/modem.sock"
|
||||
#define MODEM_SOCK_FALLBACK "/tmp/geminux-modem.sock"
|
||||
#define IMS_SOCK_PATH "/run/geminux/ims.sock"
|
||||
#define IMS_STATE_FILE "/run/geminux/ims-state"
|
||||
#define AIRPLANE_RUN_FILE "/run/geminux/airplane-mode"
|
||||
#define STATE_FILE "/run/geminux/modem-state"
|
||||
#define MD1_STATE_SYSFS "/sys/class/mt6797_ccci/md1/state"
|
||||
#define AT_SECONDARY_DEV "/dev/ttyC2"
|
||||
@@ -146,11 +150,65 @@ static bool ccmni0_has_ip(void) {
|
||||
return up && has_ip;
|
||||
}
|
||||
|
||||
static bool is_airplane_active(void) {
|
||||
int fd = open(AIRPLANE_RUN_FILE, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return false;
|
||||
char buf[8] = {0};
|
||||
ssize_t n = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
return (n > 0 && buf[0] == '1');
|
||||
}
|
||||
|
||||
static bool ims_is_registered(char *mode_out, size_t sz) {
|
||||
if (mode_out && sz > 0) mode_out[0] = '\0';
|
||||
if (is_airplane_active()) return false;
|
||||
int fd = open(IMS_STATE_FILE, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return false;
|
||||
char buf[32] = {0};
|
||||
ssize_t n = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if (n <= 0) return false;
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) buf[--n] = '\0';
|
||||
if (strcmp(buf, "VoLTE") == 0 || strcmp(buf, "VoWiFi") == 0) {
|
||||
if (mode_out && sz > 0) snprintf(mode_out, sz, "%s", buf);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int ims_send_cmd(const char *cmd, char *resp, size_t resp_sz) {
|
||||
if (resp && resp_sz > 0) resp[0] = '\0';
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM | O_CLOEXEC, 0);
|
||||
if (fd < 0) return -1;
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", IMS_SOCK_PATH);
|
||||
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
dprintf(fd, "%s\n", cmd);
|
||||
shutdown(fd, SHUT_WR);
|
||||
char buf[256] = {0};
|
||||
ssize_t r = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if (r <= 0) return -1;
|
||||
while (r > 0 && (buf[r - 1] == '\n' || buf[r - 1] == '\r')) buf[--r] = '\0';
|
||||
if (resp && resp_sz > 0) snprintf(resp, resp_sz, "%s", buf);
|
||||
return (strncmp(buf, "OK", 2) == 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
static void write_state(modem_ctx_t *ctx) {
|
||||
char next[96];
|
||||
if (ctx->in_call) {
|
||||
char ims_mode[32] = {0};
|
||||
if (is_airplane_active()) {
|
||||
snprintf(next, sizeof(next), "AIRPLANE\n");
|
||||
} else if (ctx->in_call) {
|
||||
snprintf(next, sizeof(next), "CALL:%s\n",
|
||||
ctx->active_peer[0] ? ctx->active_peer : "ACTIVE");
|
||||
} else if (ims_is_registered(ims_mode, sizeof(ims_mode))) {
|
||||
snprintf(next, sizeof(next), "4G:%s\n", ims_mode);
|
||||
} else if (ccmni0_has_ip()) {
|
||||
snprintf(next, sizeof(next), "4G:LTE\n");
|
||||
} else if (md1_is_ready() || ctx->at_fd >= 0) {
|
||||
@@ -460,38 +518,44 @@ static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "add", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
apply_call_audio(ctx);
|
||||
if (ctx->at_fd >= 0) {
|
||||
char at[96];
|
||||
snprintf(at, sizeof(at), "ATD%s;", ctx->active_peer);
|
||||
send_at(ctx, at);
|
||||
} else {
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"p=$(mmcli -m any --voice-create-call=\"number=$1\" 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p' | head -n1); "
|
||||
"[ -n \"$p\" ] && mmcli -o \"$p\" --start >/dev/null 2>&1",
|
||||
"geminux-dial", ctx->active_peer, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
bool via_ims = ims_is_registered(NULL, 0) && (ims_send_cmd(buf, NULL, 0) == 0);
|
||||
if (!via_ims) {
|
||||
if (ctx->at_fd >= 0) {
|
||||
char at[96];
|
||||
snprintf(at, sizeof(at), "ATD%s;", ctx->active_peer);
|
||||
send_at(ctx, at);
|
||||
} else {
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"p=$(mmcli -m any --voice-create-call=\"number=$1\" 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p' | head -n1); "
|
||||
"[ -n \"$p\" ] && mmcli -o \"$p\" --start >/dev/null 2>&1",
|
||||
"geminux-dial", ctx->active_peer, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
}
|
||||
}
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK dialing %s\n", ctx->active_peer);
|
||||
dprintf(cfd, "OK dialing %s%s\n", ctx->active_peer, via_ims ? " (IMS)" : "");
|
||||
} else if (strcmp(buf, "answer") == 0) {
|
||||
ctx->in_call = true;
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "add", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
apply_call_audio(ctx);
|
||||
if (ctx->at_fd >= 0) {
|
||||
send_at(ctx, "ATA");
|
||||
} else {
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"for p in $(mmcli -m any --voice-list-calls 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p'); do "
|
||||
"mmcli -o \"$p\" --accept >/dev/null 2>&1; done",
|
||||
NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
bool via_ims = (ims_send_cmd("answer", NULL, 0) == 0);
|
||||
if (!via_ims) {
|
||||
if (ctx->at_fd >= 0) {
|
||||
send_at(ctx, "ATA");
|
||||
} else {
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"for p in $(mmcli -m any --voice-list-calls 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p'); do "
|
||||
"mmcli -o \"$p\" --accept >/dev/null 2>&1; done",
|
||||
NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
}
|
||||
}
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK answered\n");
|
||||
@@ -499,6 +563,7 @@ static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
ctx->in_call = false;
|
||||
ctx->active_peer[0] = '\0';
|
||||
ctx->last_call_path[0] = '\0';
|
||||
(void)ims_send_cmd("hangup", NULL, 0);
|
||||
if (ctx->at_fd >= 0) {
|
||||
send_at(ctx, "ATH");
|
||||
} else {
|
||||
@@ -513,28 +578,32 @@ static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
dprintf(cfd, "OK hangup\n");
|
||||
} else if (strcmp(buf, "mute on") == 0 || strcmp(buf, "mute off") == 0) {
|
||||
ctx->muted = (strcmp(buf, "mute on") == 0);
|
||||
(void)ims_send_cmd(buf, NULL, 0);
|
||||
const char *m[] = {"wpctl", "set-mute", "@DEFAULT_AUDIO_SOURCE@", ctx->muted ? "1" : "0", NULL};
|
||||
spawn_bg(m);
|
||||
dprintf(cfd, "OK mute=%d\n", ctx->muted ? 1 : 0);
|
||||
} else if (strcmp(buf, "speaker on") == 0 || strcmp(buf, "speaker off") == 0) {
|
||||
ctx->speaker = (strcmp(buf, "speaker on") == 0);
|
||||
(void)ims_send_cmd(buf, NULL, 0);
|
||||
if (ctx->in_call) apply_call_audio(ctx);
|
||||
dprintf(cfd, "OK speaker=%d\n", ctx->speaker ? 1 : 0);
|
||||
} else if (strncmp(buf, "dtmf ", 5) == 0 && buf[5]) {
|
||||
if (ctx->at_fd >= 0) {
|
||||
char at[32];
|
||||
snprintf(at, sizeof(at), "AT+VTS=\"%c\"", buf[5]);
|
||||
send_at(ctx, at);
|
||||
} else {
|
||||
char digit[2] = {buf[5], '\0'};
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"for p in $(mmcli -m any --voice-list-calls 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p'); do "
|
||||
"mmcli -o \"$p\" --send-dtmf=\"$1\" >/dev/null 2>&1; done",
|
||||
"geminux-dtmf", digit, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
if (ims_send_cmd(buf, NULL, 0) != 0) {
|
||||
if (ctx->at_fd >= 0) {
|
||||
char at[32];
|
||||
snprintf(at, sizeof(at), "AT+VTS=\"%c\"", buf[5]);
|
||||
send_at(ctx, at);
|
||||
} else {
|
||||
char digit[2] = {buf[5], '\0'};
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"for p in $(mmcli -m any --voice-list-calls 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/Call/[0-9]*\\).*|\\1|p'); do "
|
||||
"mmcli -o \"$p\" --send-dtmf=\"$1\" >/dev/null 2>&1; done",
|
||||
"geminux-dtmf", digit, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
}
|
||||
}
|
||||
dprintf(cfd, "OK dtmf\n");
|
||||
} else if (strncmp(buf, "sms-send ", 9) == 0) {
|
||||
@@ -543,19 +612,52 @@ static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
dprintf(cfd, "ERR usage sms-send <num> <text>\n");
|
||||
return;
|
||||
}
|
||||
char raw_cmd[512];
|
||||
snprintf(raw_cmd, sizeof(raw_cmd), "sms-send %s", buf + 9);
|
||||
*sp = '\0';
|
||||
const char *peer = buf + 9;
|
||||
const char *text = sp + 1;
|
||||
save_sms_row("OUT", peer, text);
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"p=$(mmcli -m any --messaging-create-sms=\"number=$1,text=$2\" 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/SMS/[0-9]*\\).*|\\1|p' | head -n1); "
|
||||
"[ -n \"$p\" ] && mmcli -s \"$p\" --send >/dev/null 2>&1",
|
||||
"geminux-sms", peer, text, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
if (!ims_is_registered(NULL, 0) || ims_send_cmd(raw_cmd, NULL, 0) != 0) {
|
||||
const char *mm[] = {
|
||||
"sh", "-c",
|
||||
"p=$(mmcli -m any --messaging-create-sms=\"number=$1,text=$2\" 2>/dev/null | "
|
||||
"sed -n 's|.*\\(/org/freedesktop/ModemManager1/SMS/[0-9]*\\).*|\\1|p' | head -n1); "
|
||||
"[ -n \"$p\" ] && mmcli -s \"$p\" --send >/dev/null 2>&1",
|
||||
"geminux-sms", peer, text, NULL
|
||||
};
|
||||
spawn_bg(mm);
|
||||
}
|
||||
dprintf(cfd, "OK sms queued\n");
|
||||
} else if (strncmp(buf, "ims-ring ", 9) == 0) {
|
||||
snprintf(ctx->active_peer, sizeof(ctx->active_peer), "%.*s",
|
||||
(int)(sizeof(ctx->active_peer) - 1), buf + 9);
|
||||
const char *ntf[] = {"notify-send", "Incoming IMS Call",
|
||||
ctx->active_peer[0] ? ctx->active_peer : "Unknown", NULL};
|
||||
spawn_bg(ntf);
|
||||
const char *cs[] = {"geminux-callscreen",
|
||||
ctx->active_peer[0] ? ctx->active_peer : "Unknown",
|
||||
"--incoming", NULL};
|
||||
spawn_bg(cs);
|
||||
dprintf(cfd, "OK\n");
|
||||
} else if (strncmp(buf, "ims-sms ", 8) == 0) {
|
||||
char *sp = strchr(buf + 8, ' ');
|
||||
const char *peer = sp ? (buf + 8) : "unknown";
|
||||
if (sp) *sp = '\0';
|
||||
const char *text = (sp && sp[1]) ? (sp + 1) : (buf + 8);
|
||||
save_sms_row("IN", peer, text);
|
||||
const char *ntf[] = {"notify-send", peer, text, NULL};
|
||||
spawn_bg(ntf);
|
||||
dprintf(cfd, "OK\n");
|
||||
} else if (strcmp(buf, "ims-ended") == 0) {
|
||||
ctx->in_call = false;
|
||||
ctx->active_peer[0] = '\0';
|
||||
stop_hostless_speech(ctx);
|
||||
restore_hifi_audio();
|
||||
const char *inh[] = {"geminux-power-ctl", "inhibit", "del", "call", NULL};
|
||||
spawn_bg(inh);
|
||||
write_state(ctx);
|
||||
dprintf(cfd, "OK\n");
|
||||
} else if (strcmp(buf, "status") == 0) {
|
||||
dprintf(cfd, "in_call=%d at_dev=%d peer=%s\n",
|
||||
ctx->in_call ? 1 : 0, (md1_is_ready() || ctx->at_fd >= 0) ? 1 : 0,
|
||||
@@ -631,6 +733,11 @@ int main(void) {
|
||||
ctx.dbus_fd = -1;
|
||||
ctx.dbus_pid = -1;
|
||||
mkdir("/run/geminux", 0755);
|
||||
int lock_fd = open("/tmp/geminux-modem-ctl.lock", O_CREAT | O_RDWR | O_CLOEXEC, 0600);
|
||||
if (lock_fd >= 0 && flock(lock_fd, LOCK_EX | LOCK_NB) != 0) {
|
||||
close(lock_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
|
||||
Reference in new issue
Block a user