Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

The modem sees the network: a signal on UMTS once logical slot 1 points at the SIM's slot; the status bar's signal item hooked

shimoku74fe2bf11619f1
diff --git a/docs/cellular.md b/docs/cellular.md
index 23f16dc..66c55a6 100644
--- a/docs/cellular.md
+++ b/docs/cellular.md
@@ -239,3 +239,18 @@ readiness`. Драйвер IPA модема при ініціалізації ч
- Прогони з `modem_step=11` тримають SpringBoard 600 с (телефон стоїть на логотипі Apple);
тепер `tools/modem-cycle.sh` бере `XL_SB_DELAY` з оточення, і прогін 31 — повне завантаження
iOS з модемом у фоні (`modem=1`).
+
+### Прогін 31 (09:12): повне завантаження iOS, перемикання слота, ПЕРШИЙ СИГНАЛ
+
+`XL_SB_DELAY=8` + `modem=1`: SpringBoard стартує одразу (телефон більше не стоїть на логотипі
+Apple під час тестів), модем піднімається у фоні. Після UIM Switch Slot (логічний 1 → фізичний 2)
+картка з'явилась у слоті 1 у стані «detected», і NAS уперше прочитав сигнал: **-80…-87 dBm,
+UMTS** — радіо працює, модем бачить мережу; реєстрації ще нема (помилка 37 на Initiate Network
+Register = `UIM_UNINITIALIZED`: SIM ще ініціалізується після перемикання). Тепер крок 11 раз на
+10 с питає стан картки та NAS Get System Info (0x4d).
+
+Статус-бар: у SpringBoard iOS 16.5 стільникові пункти заповнює `SBStatusBarStateAggregator`
+через `_updateSignalStrengthItem:withData:SIMInfo:barsGetter:barsSetter:` і `_setItem:enabled:`
+(селектори знайдені в кеші dyld). `inject_sb.c` тепер перехоплює цей метод: коли
+`kern.redwood.cellular_registered`, виставляє палички через barsSetter і вмикає пункт; раз на 3 с
+просить пункт оновитися, коли стан у ядрі змінюється; список методів агрегатора пишеться в лог.
diff --git a/userland/src/inject_sb.c b/userland/src/inject_sb.c
index 6b31ec4..1ab951c 100644
--- a/userland/src/inject_sb.c
+++ b/userland/src/inject_sb.c
@@ -260,6 +260,109 @@ battery_power_source(void)
return found;
}
+/* ---- the cellular items of the status bar, from the kernel's modem ------------------------------ */
+
+/*
+ * SpringBoard's SBStatusBarStateAggregator fills the raw status bar data from CoreTelephony, which
+ * has no baseband here. Its item updaters take the data and a getter and setter for the field
+ * (iOS 16.5: -[SBStatusBarStateAggregator _updateSignalStrengthItem:withData:SIMInfo:barsGetter:
+ * barsSetter:], and the like for the service string): the signal one is replaced so that, when the
+ * kernel's modem is registered (sysctl kern.redwood.cellular_registered, _bars: redwood_mpss.c),
+ * the bars are set and the item switched on (-[... _setItem:enabled:]). The aggregator's whole
+ * method list is said once in the log, for the posting to be found; and the signal item is asked
+ * to update itself every few seconds while the kernel's state changes.
+ */
+static void (*original_update_signal_item)(id self, SEL sel, long item, void *data, id sim, void *getter, void *setter);
+static id cellular_aggregator;
+static int cellular_last_bars = -2, cellular_said;
+
+static void
+update_signal_item(id self, SEL sel, long item, void *data, id sim, void *getter, void *setter)
+{
+ int up = sysctl_int("kern.redwood.cellular_up"), registered = sysctl_int("kern.redwood.cellular_registered");
+ int bars = sysctl_int("kern.redwood.cellular_bars");
+
+ cellular_aggregator = self;
+ if (original_update_signal_item) {
+ original_update_signal_item(self, sel, item, data, sim, getter, setter);
+ }
+ if (cellular_said++ < 8) {
+ say("redwood: cellular: signal item %ld: data %p, SIM info %p, getter %p, setter %p; the kernel says up %d registered %d bars %d\n",
+ item, data, (void *)sim, getter, setter, up, registered, bars);
+ }
+ if (up > 0 && registered > 0 && bars >= 0 && bars <= 5 && setter != NULL && data != NULL) {
+ ((void (*)(void *, int))setter)(data, bars);
+ ((void (*)(id, SEL, long, BOOL))objc_msgSend)(self, sel_registerName("_setItem:enabled:"), item, YES);
+ if (bars != cellular_last_bars) {
+ say("redwood: cellular: %d bars shown (item %ld)\n", bars, item);
+ }
+ }
+ cellular_last_bars = bars;
+}
+
+static void
+cellular_hook(void)
+{
+ const char *selector = "_updateSignalStrengthItem:withData:SIMInfo:barsGetter:barsSetter:";
+ Class cls = objc_getClass("SBStatusBarStateAggregator");
+ Method method = cls ? class_getInstanceMethod(cls, sel_registerName(selector)) : NULL;
+
+ if (method == NULL) {
+ say("redwood: cellular: no -[SBStatusBarStateAggregator %s]\n", selector);
+ return;
+ }
+ say("redwood: cellular: -[SBStatusBarStateAggregator %s] at %#lx, types \"%s\": replaced\n", selector,
+ (uintptr_t)method_getImplementation(method) - slide, method_getTypeEncoding(method));
+ original_update_signal_item = (void (*)(id, SEL, long, void *, id, void *, void *))method_getImplementation(method);
+ method_setImplementation(method, (IMP)update_signal_item);
+ {
+ /* the whole class, once: which updaters and posters there are */
+ unsigned count = 0;
+ Method *list = class_copyMethodList(cls, &count);
+ char line[1024] = "";
+ size_t at = 0;
+
+ for (unsigned i = 0; list && i < count; i++) {
+ const char *name = sel_getName(method_getName(list[i]));
+ size_t n = strlen(name);
+
+ if (at + n + 2 > sizeof(line)) {
+ say("redwood: cellular: aggregator methods: %s\n", line);
+ line[0] = 0;
+ at = 0;
+ }
+ memcpy(line + at, name, n);
+ at += n;
+ line[at++] = ' ';
+ line[at] = 0;
+ }
+ if (at) {
+ say("redwood: cellular: aggregator methods: %s\n", line);
+ }
+ free(list);
+ }
+ /* every 3 s: when the kernel's registration or bars change, the item is asked to update itself */
+ dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
+
+ dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), 3 * NSEC_PER_SEC, NSEC_PER_SEC / 2);
+ dispatch_source_set_event_handler(timer, ^{
+ static int last_registered = -2, last_bars = -2;
+ int registered = sysctl_int("kern.redwood.cellular_registered"), bars = sysctl_int("kern.redwood.cellular_bars");
+
+ if ((registered != last_registered || bars != last_bars) && cellular_aggregator != nil) {
+ SEL update = sel_registerName("_updateSignalStrengthItem");
+
+ last_registered = registered;
+ last_bars = bars;
+ if (class_getInstanceMethod(object_getClass(cellular_aggregator), update)) {
+ ((void (*)(id, SEL))objc_msgSend)(cellular_aggregator, update);
+ say("redwood: cellular: the signal item asked to update (registered %d, bars %d)\n", registered, bars);
+ }
+ }
+ });
+ dispatch_resume(timer);
+}
+
/* UIDevice.batteryLevel: 0.0..1.0; -1.0 if monitoring not enabled */
static float
battery_level(id self, SEL sel)
@@ -1098,6 +1201,7 @@ redwood_springboard_init(void)
sysctl_int("kern.redwood.cellular_registered"), sysctl_int("kern.redwood.cellular_bars"),
sysctl_int("kern.redwood.cellular_dbm"), sysctl_int("kern.redwood.cellular_radio"));
}
+ cellular_hook();
say("redwood: battery UI: shows%% %s, set-shows%% %s, bolt %s, chargePercent %s, setChargePercent %s, lockscreen ring %s\n",
original_battery_view_shows_percentage ? "ok" : "NO",
original_battery_view_set_shows_percentage ? "ok" : "NO",
diff --git a/xnu/files/bsd/dev/redwood_mpss.c b/xnu/files/bsd/dev/redwood_mpss.c
index ad0d977..382d035 100644
--- a/xnu/files/bsd/dev/redwood_mpss.c
+++ b/xnu/files/bsd/dev/redwood_mpss.c
@@ -5286,6 +5286,7 @@ static volatile uint32_t sim_slot_ready; /* the physical slot whose card
static volatile bool sim_slot_switched;
#define NAS_INITIATE_NETWORK_REGISTER 0x0022
#define NAS_GET_SYSTEM_SELECTION_PREFERENCE 0x0034
+#define NAS_GET_SYSTEM_INFO 0x004d
static struct redwood_qrtr_port *uim_port, *nas2_port;
static uint32_t uim_node, uim_port_number, nas2_node, nas2_port_number;
@@ -5322,6 +5323,10 @@ uim_receive(__unused void *context, __unused uint32_t node, __unused uint32_t po
return;
}
probe_dump("uim", m, length);
+ if ((m[3] | m[4] << 8) == UIM_SWITCH_SLOT) {
+ tell("mpss: uim: the modem answers the slot switch\n");
+ return;
+ }
if ((m[3] | m[4] << 8) != UIM_GET_CARD_STATUS || (v = qmi_tlv(m, length, 0x10, &size)) == NULL || size < 9) {
return;
}
@@ -5370,8 +5375,6 @@ uim_receive(__unused void *context, __unused uint32_t node, __unused uint32_t po
tell("mpss: uim: LOGICAL SLOT 1 IS POINTED AT PHYSICAL SLOT %u, where the card is ready\n", sim_slot_ready);
qrtr_send(uim_port, uim_node, uim_port_number, sw, sizeof(sw));
}
- } else if ((m[3] | m[4] << 8) == UIM_SWITCH_SLOT) {
- tell("mpss: uim: the modem answers the slot switch\n");
}
}
@@ -5409,6 +5412,25 @@ nas2_receive(__unused void *context, __unused uint32_t node, __unused uint32_t p
emergency, roaming, domain);
} else if ((m[3] | m[4] << 8) == NAS_INITIATE_NETWORK_REGISTER) {
tell("mpss: nas: the modem answers INITIATE NETWORK REGISTER (automatic)\n");
+ } else if ((m[3] | m[4] << 8) == NAS_GET_SYSTEM_INFO) {
+ /* per radio: service status (0 none, 1 limited, 2 available, 3 limited regional, 4 power save), true status, data path;
+ * and the SIM reject reason (0x27: 0 available, 1 not available, 2 CS invalid, 3 CS+PS invalid, 4 PS invalid) */
+ static const char *const radios[] = { "GSM", "WCDMA", "LTE" };
+ static const uint8_t types[] = { 0x12, 0x13, 0x14 };
+ uint32_t reject = ~0u;
+ char line[160] = "";
+ size_t at = 0;
+
+ for (unsigned r = 0; r < 3; r++) {
+ if ((v = qmi_tlv(m, length, types[r], &size)) != NULL && size >= 3) {
+ at += (size_t)snprintf(line + at, sizeof(line) - at, "%s service %u (true %u, data path %u); ", radios[r], v[0], v[1], v[2]);
+ }
+ }
+ if ((v = qmi_tlv(m, length, 0x27, &size)) != NULL && size >= 4) {
+ reject = (uint32_t)(v[0] | v[1] << 8 | v[2] << 16 | v[3] << 24);
+ }
+ tell("mpss: nas: SYSTEM INFO: %sSIM reject %u (0 available, 1 not available, 2 CS invalid, 3 CS and PS invalid, 4 PS invalid)\n",
+ line, reject);
}
}
@@ -5503,7 +5525,7 @@ step_nas(void)
uint32_t wait_seconds = 90, online = 1;
uint64_t began, asked_online = 0;
bool registered = false, is_online = false, probed = option("modem_sim_probe_off"), probed_again = false;
- uint64_t probed_at = 0;
+ uint64_t probed_at = 0, watched_at = 0;
if (!glink.channel[CHANNEL_QRTR].open) {
return false;
@@ -5543,6 +5565,15 @@ step_nas(void)
probed_again = true;
sim_probe();
}
+ if (probed && now_us() - watched_at > 10000000ull && uim_port_number != 0 && nas2_port_number != 0) {
+ /* every ten seconds: the card's state as it initializes, and the system's service status */
+ uint8_t card[7] = { 0, 0x35, 0, UIM_GET_CARD_STATUS & 0xff, UIM_GET_CARD_STATUS >> 8, 0, 0 };
+ uint8_t info[7] = { 0, 0x36, 0, NAS_GET_SYSTEM_INFO & 0xff, NAS_GET_SYSTEM_INFO >> 8, 0, 0 };
+
+ watched_at = now_us();
+ qrtr_send(uim_port, uim_node, uim_port_number, card, sizeof(card));
+ qrtr_send(nas2_port, nas2_node, nas2_port_number, info, sizeof(info));
+ }
if (nas.connected) {
nas_polls += redwood_nas_client_poll(&nas) == 0;
}