Enable MT6797 Wi-Fi/BT, PipeWire audio GUI, cursor autohide, and dev tools

- Add MT6797 CONSYS Wi-Fi/BT factory-firmware patch (0005), native EAPOL TX, 5 GHz NO_IR/regulatory-notifier fixes, TKIP/CCMP admission, initramfs regdb, and geminux-wifi-nvram
- Order OpenRC polkit startup before NetworkManager/ModemManager and harden geminux-net with non-blocking scans, mesh SSID grouping, password masking toggle, and BT A2DP/HFP/LE/HID support
- Add geminux-audio PipeWire/WirePlumber/UCM2 playback & recording control GUI alongside st and dmenu XFixes cursor autohide
- Preinstall requested CLI/dev tools (bash, coreutils, build-base, git, nmtui, perl/SSL, curl-dev, janet, jpm, etc.) and set bash as system-wide default shell
This commit is contained in:
Luxferre committed 2026-11-22 22:31:41 +02:00
1 parent ba7b86e570
commit 6aea73cbeb
92 files changed
+5524 -198

No files matched your search

+6 -2
View File
@@ -22,7 +22,8 @@ BINS = \
geminux-bt-obex \
geminux-leds \
geminux-power-audit \
geminux-checkpw
geminux-checkpw \
geminux-wifi-nvram
all: $(BINS)
@@ -56,12 +57,15 @@ geminux-power-audit: geminux-power-audit.c
geminux-checkpw: geminux-checkpw.c
$(CC) $(CFLAGS) -o $@ $<
geminux-wifi-nvram: geminux-wifi-nvram.c geminux-wifi-nvram-core.c geminux-wifi-nvram-core.h
$(CC) $(CFLAGS) -o $@ geminux-wifi-nvram.c geminux-wifi-nvram-core.c
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/sbin
cp -f geminux-power-ctl geminux-statusd geminux-touchd geminux-modem-ctl \
geminux-bt-obex geminux-power-audit $(DESTDIR)$(PREFIX)/bin/
cp -f geminux-powerd geminux-ccci-daemon geminux-leds \
geminux-checkpw $(DESTDIR)$(PREFIX)/sbin/
geminux-checkpw geminux-wifi-nvram $(DESTDIR)$(PREFIX)/sbin/
chmod 0755 $(DESTDIR)$(PREFIX)/bin/geminux-* $(DESTDIR)$(PREFIX)/sbin/geminux-*
clean:
+132 -4
View File
@@ -1,10 +1,53 @@
#define _POSIX_C_SOURCE 200809L
#include <gio/gio.h>
#include <inttypes.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define GEMINUX_BT_AGENT_PATH "/org/geminux/bt_agent"
static GMainLoop *g_loop = NULL;
static GDBusConnection *g_sys = NULL;
static GDBusNodeInfo *g_agent_introspection = NULL;
static guint g_agent_reg_id = 0;
static const gchar g_agent_xml[] =
"<node>"
" <interface name='org.bluez.Agent1'>"
" <method name='Release'/>"
" <method name='RequestPinCode'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='s' name='pincode' direction='out'/>"
" </method>"
" <method name='DisplayPinCode'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='s' name='pincode' direction='in'/>"
" </method>"
" <method name='RequestPasskey'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='u' name='passkey' direction='out'/>"
" </method>"
" <method name='DisplayPasskey'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='u' name='passkey' direction='in'/>"
" <arg type='q' name='entered' direction='in'/>"
" </method>"
" <method name='RequestConfirmation'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='u' name='passkey' direction='in'/>"
" </method>"
" <method name='RequestAuthorization'>"
" <arg type='o' name='device' direction='in'/>"
" </method>"
" <method name='AuthorizeService'>"
" <arg type='o' name='device' direction='in'/>"
" <arg type='s' name='uuid' direction='in'/>"
" </method>"
" <method name='Cancel'/>"
" </interface>"
"</node>";
static void notify_event(const char *title, const char *body) {
const char *argv[] = {"notify-send", title, body, NULL};
@@ -12,6 +55,78 @@ static void notify_event(const char *title, const char *body) {
NULL, NULL, NULL, NULL);
}
static void on_agent_call(GDBusConnection *conn, const gchar *sender,
const gchar *obj_path, const gchar *iface_name,
const gchar *method_name, GVariant *params,
GDBusMethodInvocation *inv, gpointer ud) {
(void)conn; (void)sender; (void)obj_path; (void)iface_name; (void)ud;
if (strcmp(method_name, "RequestPinCode") == 0) {
notify_event("Bluetooth Pairing", "Using PIN 0000 for device pairing");
g_dbus_method_invocation_return_value(inv, g_variant_new("(s)", "0000"));
} else if (strcmp(method_name, "DisplayPinCode") == 0) {
const gchar *dev = NULL, *pin = NULL;
g_variant_get(params, "(&o&s)", &dev, &pin);
char msg[160];
snprintf(msg, sizeof(msg), "Type PIN %s + Enter on device", pin ? pin : "0000");
notify_event("Bluetooth Pairing PIN", msg);
g_dbus_method_invocation_return_value(inv, NULL);
} else if (strcmp(method_name, "RequestPasskey") == 0) {
g_dbus_method_invocation_return_value(inv, g_variant_new("(u)", (guint32)0));
} else if (strcmp(method_name, "DisplayPasskey") == 0) {
const gchar *dev = NULL;
guint32 passkey = 0;
guint16 entered = 0;
g_variant_get(params, "(&ouq)", &dev, &passkey, &entered);
if (entered == 0) {
char msg[160];
snprintf(msg, sizeof(msg), "Type passkey %06" PRIu32 " + Enter on device", passkey);
notify_event("Bluetooth Passkey", msg);
}
g_dbus_method_invocation_return_value(inv, NULL);
} else if (strcmp(method_name, "RequestConfirmation") == 0) {
const gchar *dev = NULL;
guint32 passkey = 0;
g_variant_get(params, "(&ou)", &dev, &passkey);
char msg[160];
snprintf(msg, sizeof(msg), "Confirmed pairing passkey %06" PRIu32, passkey);
notify_event("Bluetooth Pairing", msg);
g_dbus_method_invocation_return_value(inv, NULL);
} else {
if (strcmp(method_name, "Cancel") == 0) {
notify_event("Bluetooth Pairing", "Pairing cancelled");
}
g_dbus_method_invocation_return_value(inv, NULL);
}
}
static const GDBusInterfaceVTable g_agent_vtable = {
.method_call = on_agent_call,
};
static void on_agent_registered(GObject *src, GAsyncResult *res, gpointer ud) {
(void)ud;
GVariant *ret = g_dbus_connection_call_finish(G_DBUS_CONNECTION(src), res, NULL);
if (ret) {
g_variant_unref(ret);
g_dbus_connection_call(
G_DBUS_CONNECTION(src), "org.bluez", "/org/bluez",
"org.bluez.AgentManager1", "RequestDefaultAgent",
g_variant_new("(o)", GEMINUX_BT_AGENT_PATH), NULL,
G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL, NULL);
}
}
static void on_bluez_appeared(GDBusConnection *conn, const gchar *name,
const gchar *owner, gpointer ud) {
(void)name; (void)owner; (void)ud;
if (!g_agent_reg_id) return;
g_dbus_connection_call(
conn, "org.bluez", "/org/bluez",
"org.bluez.AgentManager1", "RegisterAgent",
g_variant_new("(os)", GEMINUX_BT_AGENT_PATH, "KeyboardDisplay"), NULL,
G_DBUS_CALL_FLAGS_NONE, 3000, NULL, on_agent_registered, NULL);
}
static void on_bluez_props(GDBusConnection *conn, const gchar *sender,
const gchar *obj_path, const gchar *iface_name,
const gchar *signal_name, GVariant *params,
@@ -55,10 +170,20 @@ int main(void) {
signal(SIGCHLD, SIG_IGN);
g_loop = g_main_loop_new(NULL, FALSE);
GDBusConnection *sys = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
if (sys) {
g_sys = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
guint watch_id = 0;
if (g_sys) {
g_agent_introspection = g_dbus_node_info_new_for_xml(g_agent_xml, NULL);
if (g_agent_introspection) {
g_agent_reg_id = g_dbus_connection_register_object(
g_sys, GEMINUX_BT_AGENT_PATH, g_agent_introspection->interfaces[0],
&g_agent_vtable, NULL, NULL, NULL);
}
watch_id = g_bus_watch_name_on_connection(
g_sys, "org.bluez", G_BUS_NAME_WATCHER_FLAGS_NONE,
on_bluez_appeared, NULL, NULL, NULL);
g_dbus_connection_signal_subscribe(
sys, "org.bluez", "org.freedesktop.DBus.Properties",
g_sys, "org.bluez", "org.freedesktop.DBus.Properties",
"PropertiesChanged", NULL, "org.bluez.Device1",
G_DBUS_SIGNAL_FLAGS_NONE, on_bluez_props, NULL, NULL);
}
@@ -71,7 +196,10 @@ int main(void) {
}
g_main_loop_run(g_loop);
if (sys) g_object_unref(sys);
if (watch_id) g_bus_unwatch_name(watch_id);
if (g_sys && g_agent_reg_id) g_dbus_connection_unregister_object(g_sys, g_agent_reg_id);
if (g_agent_introspection) g_dbus_node_info_unref(g_agent_introspection);
if (g_sys) g_object_unref(g_sys);
if (ses) g_object_unref(ses);
g_main_loop_unref(g_loop);
return 0;
@@ -0,0 +1,105 @@
#include "geminux-wifi-nvram-core.h"
#include <string.h>
static uint16_t read_le16(const uint8_t *p) {
return (uint16_t)p[0] | ((uint16_t)p[1] << 8);
}
uint8_t geminux_wifi_nvram_checksum(const uint8_t *rec512) {
uint8_t check = 0;
for (size_t i = 0; i < GEMINUX_WIFI_RECORD_BYTES; i++) {
check = (uint8_t)((i & 1U) ? (check ^ rec512[i]) : (check + rec512[i]));
}
return check;
}
bool geminux_wifi_nvram_has_valid_mac(const uint8_t *rec512) {
if (!rec512) return false;
/* Multicast bit must be clear (unicast address required by IEEE 802.11). */
if (rec512[4] & 0x01U) return false;
uint8_t or_acc = 0;
uint8_t and_acc = 0xffU;
for (size_t i = 4; i < 10; i++) {
or_acc |= rec512[i];
and_acc &= rec512[i];
}
return or_acc != 0 && and_acc != 0xffU;
}
bool geminux_wifi_nvram_valid_record(const uint8_t *buf, size_t len, bool require_mac) {
if (!buf || len != GEMINUX_WIFI_STORAGE_BYTES) return false;
if (buf[512] != 0xaaU) return false;
if (geminux_wifi_nvram_checksum(buf) != buf[513]) return false;
if (read_le16(buf + 2) > 0x0200U || read_le16(buf + 258) > 0x0200U) return false;
if (buf[83] || buf[104] || buf[155] || buf[266]) return false;
if (require_mac && !geminux_wifi_nvram_has_valid_mac(buf)) return false;
return true;
}
void geminux_wifi_nvram_apply_fallback_mac(uint8_t buf514[GEMINUX_WIFI_STORAGE_BYTES],
const char *seed_str) {
uint64_t h = 14695981039346656037ULL;
if (seed_str && seed_str[0]) {
for (const unsigned char *p = (const unsigned char *)seed_str; *p; p++) {
h ^= (uint64_t)(*p);
h *= 1099511628211ULL;
}
} else {
h ^= 0x6797a115ULL;
}
buf514[4] = 0x02U;
buf514[5] = (uint8_t)(h >> 8);
buf514[6] = (uint8_t)(h >> 16);
buf514[7] = (uint8_t)(h >> 24);
buf514[8] = (uint8_t)(h >> 32);
buf514[9] = (uint8_t)(h >> 40);
if ((buf514[5] | buf514[6] | buf514[7] | buf514[8] | buf514[9]) == 0) {
buf514[5] = 0x67U;
buf514[9] = 0x97U;
}
buf514[512] = 0xaaU;
buf514[513] = geminux_wifi_nvram_checksum(buf514);
}
bool geminux_wifi_nvram_scan_blob(const uint8_t *blob, size_t blob_len,
uint8_t out514[GEMINUX_WIFI_STORAGE_BYTES],
bool *has_valid_mac_out) {
if (has_valid_mac_out) *has_valid_mac_out = false;
if (!blob || !out514 || blob_len < GEMINUX_WIFI_STORAGE_BYTES) return false;
if (blob_len >= (size_t)GEMINUX_WIFI_NVRAM_FAST_OFFSET + GEMINUX_WIFI_STORAGE_BYTES) {
const uint8_t *fast = blob + GEMINUX_WIFI_NVRAM_FAST_OFFSET;
if (fast[0] == 0x06U && fast[1] == 0x01U &&
geminux_wifi_nvram_valid_record(fast, GEMINUX_WIFI_STORAGE_BYTES, true)) {
memcpy(out514, fast, GEMINUX_WIFI_STORAGE_BYTES);
if (has_valid_mac_out) *has_valid_mac_out = true;
return true;
}
}
bool have_backup = false;
uint8_t backup[GEMINUX_WIFI_STORAGE_BYTES];
size_t limit = blob_len - GEMINUX_WIFI_STORAGE_BYTES;
for (size_t off = 0; off <= limit; off++) {
const uint8_t *cand = blob + off;
if (cand[0] != 0x06U || cand[1] != 0x01U || cand[512] != 0xaaU) continue;
if (geminux_wifi_nvram_valid_record(cand, GEMINUX_WIFI_STORAGE_BYTES, true)) {
memcpy(out514, cand, GEMINUX_WIFI_STORAGE_BYTES);
if (has_valid_mac_out) *has_valid_mac_out = true;
return true;
}
if (!have_backup &&
geminux_wifi_nvram_valid_record(cand, GEMINUX_WIFI_STORAGE_BYTES, false)) {
memcpy(backup, cand, GEMINUX_WIFI_STORAGE_BYTES);
have_backup = true;
}
}
if (have_backup) {
memcpy(out514, backup, GEMINUX_WIFI_STORAGE_BYTES);
if (has_valid_mac_out) *has_valid_mac_out = false;
return true;
}
return false;
}
@@ -0,0 +1,21 @@
#ifndef GEMINUX_WIFI_NVRAM_CORE_H
#define GEMINUX_WIFI_NVRAM_CORE_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define GEMINUX_WIFI_RECORD_BYTES 512U
#define GEMINUX_WIFI_STORAGE_BYTES 514U
#define GEMINUX_WIFI_NVRAM_FAST_OFFSET 0x40042U
uint8_t geminux_wifi_nvram_checksum(const uint8_t *rec512);
bool geminux_wifi_nvram_has_valid_mac(const uint8_t *rec512);
bool geminux_wifi_nvram_valid_record(const uint8_t *buf, size_t len, bool require_mac);
void geminux_wifi_nvram_apply_fallback_mac(uint8_t buf514[GEMINUX_WIFI_STORAGE_BYTES],
const char *seed_str);
bool geminux_wifi_nvram_scan_blob(const uint8_t *blob, size_t blob_len,
uint8_t out514[GEMINUX_WIFI_STORAGE_BYTES],
bool *has_valid_mac_out);
#endif
+311
View File
@@ -0,0 +1,311 @@
#define _POSIX_C_SOURCE 200809L
#include "geminux-wifi-nvram-core.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <unistd.h>
#define MAX_NVRAM_READ_BYTES (8U * 1024U * 1024U)
#define DEFAULT_OUTPUT_PATH "/lib/firmware/mediatek/mt6797/WIFI.storage"
#define DEFAULT_BT_OUTPUT_PATH "/lib/firmware/mediatek/mt6797/BT.storage"
#define GEMINUX_BT_STORAGE_BYTES 66U
static int read_fd_exact_or_cap(int fd, uint8_t *buf, size_t cap, size_t *out_len) {
size_t total = 0;
while (total < cap) {
ssize_t r = read(fd, buf + total, cap - total);
if (r < 0) {
if (errno == EINTR) continue;
return -1;
}
if (r == 0) break;
total += (size_t)r;
}
*out_len = total;
return 0;
}
static bool read_file_exact(const char *path, uint8_t *buf, size_t cap, size_t *out_len) {
int fd = open(path, O_RDONLY);
if (fd < 0) return false;
int rc = read_fd_exact_or_cap(fd, buf, cap, out_len);
close(fd);
return rc == 0;
}
static bool find_partition_device(const char *partname, char *dev_out, size_t dev_sz) {
DIR *d = opendir("/sys/class/block");
if (!d) return false;
bool found = false;
struct dirent *de;
while ((de = readdir(d)) != NULL) {
if (de->d_name[0] == '.') continue;
char uevent_path[320];
snprintf(uevent_path, sizeof(uevent_path), "/sys/class/block/%s/uevent", de->d_name);
FILE *f = fopen(uevent_path, "r");
if (!f) continue;
char devname[128] = {0};
char pname[128] = {0};
char line[256];
while (fgets(line, sizeof(line), f)) {
size_t n = strlen(line);
while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = '\0';
if (strncmp(line, "DEVNAME=", 8) == 0) {
snprintf(devname, sizeof(devname), "%s", line + 8);
} else if (strncmp(line, "PARTNAME=", 9) == 0) {
snprintf(pname, sizeof(pname), "%s", line + 9);
}
}
fclose(f);
if (strcmp(pname, partname) == 0 && devname[0]) {
snprintf(dev_out, dev_sz, "/dev/%s", devname);
found = true;
break;
}
}
closedir(d);
return found;
}
static int mkdir_p(const char *dir) {
char tmp[512];
snprintf(tmp, sizeof(tmp), "%s", dir);
size_t len = strlen(tmp);
if (len == 0) return 0;
if (tmp[len - 1] == '/') tmp[len - 1] = '\0';
for (char *p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
if (mkdir(tmp, 0755) != 0 && errno != EEXIST) return -1;
*p = '/';
}
}
if (mkdir(tmp, 0755) != 0 && errno != EEXIST) return -1;
return 0;
}
static int write_atomic_bytes(const char *out_path, const uint8_t *rec, size_t len) {
char dir[512];
snprintf(dir, sizeof(dir), "%s", out_path);
char *slash = strrchr(dir, '/');
if (slash) {
*slash = '\0';
if (dir[0] && mkdir_p(dir) != 0) return -1;
}
char tmp_path[560];
snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", out_path);
int fd = open(tmp_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) return -1;
size_t off = 0;
while (off < len) {
ssize_t w = write(fd, rec + off, len - off);
if (w < 0) {
if (errno == EINTR) continue;
close(fd);
unlink(tmp_path);
return -1;
}
off += (size_t)w;
}
fchmod(fd, 0644);
fsync(fd);
close(fd);
if (rename(tmp_path, out_path) != 0) {
unlink(tmp_path);
return -1;
}
return 0;
}
static bool bt_addr_nonzero(const uint8_t *buf, size_t len) {
if (len < 6) return false;
bool all_zero = true, all_ff = true;
for (size_t i = 0; i < 6; i++) {
if (buf[i] != 0x00) all_zero = false;
if (buf[i] != 0xff) all_ff = false;
}
return !all_zero && !all_ff;
}
static int mount_nvdata_ro(char *mnt_out, size_t mnt_sz) {
char dev_path[256] = "/dev/mmcblk0p6";
find_partition_device("nvdata", dev_path, sizeof(dev_path));
const char *mnt = "/run/geminux-nvdata-mnt";
if (mkdir_p("/run") != 0 || (mkdir(mnt, 0700) != 0 && errno != EEXIST)) {
mnt = "/tmp/geminux-nvdata-mnt";
if (mkdir(mnt, 0700) != 0 && errno != EEXIST) return -1;
}
if (mount(dev_path, mnt, "ext4", MS_RDONLY, "noload") != 0) {
rmdir(mnt);
return -1;
}
snprintf(mnt_out, mnt_sz, "%s", mnt);
return 0;
}
static bool try_nvram_partition(uint8_t rec_out[GEMINUX_WIFI_STORAGE_BYTES],
bool *has_mac_out) {
char dev_path[256] = "/dev/mmcblk0p19";
find_partition_device("nvram", dev_path, sizeof(dev_path));
int fd = open(dev_path, O_RDONLY);
if (fd < 0) return false;
uint8_t *buf = malloc(MAX_NVRAM_READ_BYTES);
if (!buf) {
close(fd);
return false;
}
size_t got = 0;
int rc = read_fd_exact_or_cap(fd, buf, MAX_NVRAM_READ_BYTES, &got);
close(fd);
bool ok = (rc == 0) && geminux_wifi_nvram_scan_blob(buf, got, rec_out, has_mac_out);
memset(buf, 0, got);
free(buf);
return ok;
}
static bool try_nvdata_partition(uint8_t rec_out[GEMINUX_WIFI_STORAGE_BYTES],
bool *has_mac_out) {
char mnt[128];
if (mount_nvdata_ro(mnt, sizeof(mnt)) != 0) return false;
char rec_path[320];
snprintf(rec_path, sizeof(rec_path), "%s/APCFG/APRDEB/WIFI", mnt);
uint8_t cand[GEMINUX_WIFI_STORAGE_BYTES];
size_t len = 0;
bool ok = read_file_exact(rec_path, cand, sizeof(cand), &len) &&
geminux_wifi_nvram_valid_record(cand, len, false);
if (ok) {
memcpy(rec_out, cand, GEMINUX_WIFI_STORAGE_BYTES);
*has_mac_out = geminux_wifi_nvram_has_valid_mac(cand);
}
memset(cand, 0, sizeof(cand));
umount2(mnt, MNT_DETACH);
rmdir(mnt);
return ok;
}
static void provision_bt_storage(const char *out_path) {
uint8_t existing[GEMINUX_BT_STORAGE_BYTES];
size_t existing_len = 0;
if (read_file_exact(out_path, existing, sizeof(existing), &existing_len) &&
existing_len == GEMINUX_BT_STORAGE_BYTES && bt_addr_nonzero(existing, existing_len)) {
memset(existing, 0, sizeof(existing));
return;
}
memset(existing, 0, sizeof(existing));
char mnt[128];
if (mount_nvdata_ro(mnt, sizeof(mnt)) != 0) return;
char bt_path[320];
snprintf(bt_path, sizeof(bt_path), "%s/APCFG/APRDEB/BT_Addr", mnt);
uint8_t cand[GEMINUX_BT_STORAGE_BYTES];
size_t len = 0;
bool ok = read_file_exact(bt_path, cand, sizeof(cand), &len) &&
len == GEMINUX_BT_STORAGE_BYTES && bt_addr_nonzero(cand, len);
umount2(mnt, MNT_DETACH);
rmdir(mnt);
if (ok && write_atomic_bytes(out_path, cand, GEMINUX_BT_STORAGE_BYTES) == 0) {
printf("geminux-wifi-nvram: provisioned %s (%u bytes)\n",
out_path, GEMINUX_BT_STORAGE_BYTES);
}
memset(cand, 0, sizeof(cand));
}
static void read_seed_string(char *seed, size_t sz) {
memset(seed, 0, sz);
size_t n = 0;
uint8_t raw[128] = {0};
if (read_file_exact("/etc/machine-id", raw, sizeof(raw) - 1, &n) && n > 0) {
while (n > 0 && (raw[n - 1] == '\n' || raw[n - 1] == '\r')) raw[--n] = '\0';
snprintf(seed, sz, "%s", (const char *)raw);
return;
}
if (read_file_exact("/sys/block/mmcblk0/device/cid", raw, sizeof(raw) - 1, &n) && n > 0) {
while (n > 0 && (raw[n - 1] == '\n' || raw[n - 1] == '\r')) raw[--n] = '\0';
snprintf(seed, sz, "%s", (const char *)raw);
return;
}
snprintf(seed, sz, "geminux-mt6797");
}
int main(int argc, char **argv) {
const char *out_path = (argc > 1 && argv[1][0]) ? argv[1] : DEFAULT_OUTPUT_PATH;
if (argc <= 1) {
provision_bt_storage(DEFAULT_BT_OUTPUT_PATH);
}
uint8_t existing[GEMINUX_WIFI_STORAGE_BYTES];
size_t existing_len = 0;
if (read_file_exact(out_path, existing, sizeof(existing), &existing_len) &&
geminux_wifi_nvram_valid_record(existing, existing_len, true)) {
memset(existing, 0, sizeof(existing));
return 0;
}
memset(existing, 0, sizeof(existing));
uint8_t chosen[GEMINUX_WIFI_STORAGE_BYTES];
bool have_rec = false;
bool have_mac = false;
if (try_nvram_partition(chosen, &have_mac)) {
have_rec = true;
}
if (!have_rec || !have_mac) {
uint8_t nvdata_rec[GEMINUX_WIFI_STORAGE_BYTES];
bool nvdata_mac = false;
if (try_nvdata_partition(nvdata_rec, &nvdata_mac)) {
if (!have_rec || nvdata_mac) {
memcpy(chosen, nvdata_rec, sizeof(chosen));
have_rec = true;
have_mac = nvdata_mac;
}
memset(nvdata_rec, 0, sizeof(nvdata_rec));
}
}
if (!have_rec) {
fprintf(stderr, "geminux-wifi-nvram: no valid NVRAM/nvdata WIFI record found\n");
return 1;
}
if (!have_mac) {
char seed[128];
read_seed_string(seed, sizeof(seed));
geminux_wifi_nvram_apply_fallback_mac(chosen, seed);
memset(seed, 0, sizeof(seed));
}
int wrc = write_atomic_bytes(out_path, chosen, GEMINUX_WIFI_STORAGE_BYTES);
memset(chosen, 0, sizeof(chosen));
if (wrc != 0) {
fprintf(stderr, "geminux-wifi-nvram: failed to write %s (%s)\n",
out_path, strerror(errno));
return 1;
}
printf("geminux-wifi-nvram: provisioned %s (%u bytes)\n",
out_path, GEMINUX_WIFI_STORAGE_BYTES);
return 0;
}