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 serving network's name reaches SpringBoard: NAS's current PLMN into kern.redwood.cellular_operator; the service item of the status bar looked at

shimoku74bbb6bedaaeec
diff --git a/userland/src/inject_sb.c b/userland/src/inject_sb.c
index 1ab951c..d50005f 100644
--- a/userland/src/inject_sb.c
+++ b/userland/src/inject_sb.c
@@ -300,9 +300,47 @@ update_signal_item(id self, SEL sel, long item, void *data, id sim, void *getter
cellular_last_bars = bars;
}
+static void (*original_update_service_item)(id self, SEL sel, long item, void *data, id sim, id other, void *g1, void *s1, void *g2, void *s2,
+ void *g3, void *s3, void *g4, void *s4);
+
+/* The service item ("No SIM", the network's name): looked at first; its string setter is for the next step. */
+static void
+update_service_item(id self, SEL sel, long item, void *data, id sim, id other, void *g1, void *s1, void *g2, void *s2, void *g3, void *s3,
+ void *g4, void *s4)
+{
+ static int said;
+
+ if (original_update_service_item) {
+ original_update_service_item(self, sel, item, data, sim, other, g1, s1, g2, s2, g3, s3, g4, s4);
+ }
+ if (said++ < 4) {
+ char name[64] = "";
+ size_t size = sizeof(name) - 1;
+
+ sysctlbyname("kern.redwood.cellular_operator", name, &size, NULL, 0);
+ say("redwood: cellular: service item %ld: data %p, SIM info %p, other %p; string getter %p setter %p, content type getter %p "
+ "setter %p; the kernel's network \"%s\"\n", item, data, (void *)sim, (void *)other, g1, s1, g3, s3, name);
+ }
+}
+
static void
cellular_hook(void)
{
+ {
+ const char *service_selector = "_updateServiceItem:withData:SIMInfo:otherSIMInfo:serviceStringGetter:serviceStringSetter:"
+ "serviceCrossfadeStringGetter:serviceCrossfadeStringSetter:serviceContentTypeGetter:serviceContentTypeSetter:"
+ "serviceBadgeStringGetter:serviceBadgeStringSetter:";
+ Class cls = objc_getClass("SBStatusBarStateAggregator");
+ Method method = cls ? class_getInstanceMethod(cls, sel_registerName(service_selector)) : NULL;
+
+ if (method) {
+ say("redwood: cellular: -[SBStatusBarStateAggregator %s] at %#lx, types \"%s\": looked at\n", service_selector,
+ (uintptr_t)method_getImplementation(method) - slide, method_getTypeEncoding(method));
+ original_update_service_item = (void (*)(id, SEL, long, void *, id, id, void *, void *, void *, void *, void *, void *, void *,
+ void *))method_getImplementation(method);
+ method_setImplementation(method, (IMP)update_service_item);
+ }
+ }
const char *selector = "_updateSignalStrengthItem:withData:SIMInfo:barsGetter:barsSetter:";
Class cls = objc_getClass("SBStatusBarStateAggregator");
Method method = cls ? class_getInstanceMethod(cls, sel_registerName(selector)) : NULL;
diff --git a/xnu/files/bsd/dev/redwood_mpss.c b/xnu/files/bsd/dev/redwood_mpss.c
index f7c21b1..54bdc99 100644
--- a/xnu/files/bsd/dev/redwood_mpss.c
+++ b/xnu/files/bsd/dev/redwood_mpss.c
@@ -5105,6 +5105,7 @@ static volatile uint32_t dms_answers;
static volatile uint32_t dms_result, dms_error;
static uint16_t dms_transaction;
static int cellular_up, cellular_registered, cellular_bars, cellular_dbm, cellular_radio;
+static char cellular_operator[40]; /* "MCC MNC name" of the serving network; "" when none */
static uint32_t nas_polls, nas_changes;
SYSCTL_DECL(_kern_redwood);
@@ -5113,6 +5114,8 @@ SYSCTL_INT(_kern_redwood, OID_AUTO, cellular_up, CTLFLAG_RD | CTLFLAG_LOCKED, &c
SYSCTL_INT(_kern_redwood, OID_AUTO, cellular_registered, CTLFLAG_RD | CTLFLAG_LOCKED, &cellular_registered, 0,
"registered with a network");
SYSCTL_INT(_kern_redwood, OID_AUTO, cellular_bars, CTLFLAG_RD | CTLFLAG_LOCKED, &cellular_bars, 0, "signal, 0 to 4 bars");
+SYSCTL_STRING(_kern_redwood, OID_AUTO, cellular_operator, CTLFLAG_RD | CTLFLAG_LOCKED, cellular_operator, 0,
+ "the serving network: its name as the modem gives it; empty when none");
SYSCTL_INT(_kern_redwood, OID_AUTO, cellular_dbm, CTLFLAG_RD | CTLFLAG_LOCKED, &cellular_dbm, 0, "signal, dBm; 0: none read");
SYSCTL_INT(_kern_redwood, OID_AUTO, cellular_radio, CTLFLAG_RD | CTLFLAG_LOCKED, &cellular_radio, 0,
"the radio (QMI NAS): 4 GSM, 5 UMTS, 8 LTE, 12 NR");
@@ -5129,10 +5132,12 @@ nas_changed(__unused void *context, const struct redwood_nas_state *state)
{
nas_changes++;
cellular_registered = state->registered;
+ snprintf(cellular_operator, sizeof(cellular_operator), "%s", state->registered ? state->operator_name : "");
cellular_bars = state->bars;
cellular_dbm = state->has_signal ? state->dbm : 0;
cellular_radio = state->has_signal ? state->radio_interface : 0;
- tell("mpss: nas: %s; signal %s%d dBm (%s): %u bars\n", state->registered ? "REGISTERED WITH A NETWORK" : "not registered",
+ tell("mpss: nas: %s%s%s (%u-%u); signal %s%d dBm (%s): %u bars\n", state->registered ? "REGISTERED WITH A NETWORK" : "not registered",
+ state->operator_name[0] ? ", network " : "", state->operator_name, state->mcc, state->mnc,
state->has_signal ? "" : "none read, ", state->has_signal ? state->dbm : 0, radio_name(state->radio_interface), state->bars);
}
diff --git a/xnu/files/bsd/dev/redwood_nas.c b/xnu/files/bsd/dev/redwood_nas.c
index 4ea9105..634210f 100644
--- a/xnu/files/bsd/dev/redwood_nas.c
+++ b/xnu/files/bsd/dev/redwood_nas.c
@@ -71,6 +71,14 @@ redwood_nas_apply(struct redwood_nas_state *state, const void *frame, size_t len
next.bars = 0;
}
serving = true;
+ } else if (message == 0x24 && type == 0x10 && size >= 5 && size >= (size_t)5 + value[4]) {
+ /* the current PLMN: MCC, MNC (16 bits each), the description's length and bytes */
+ unsigned n = value[4] < sizeof(next.operator_name) - 1 ? value[4] : sizeof(next.operator_name) - 1;
+
+ next.mcc = le16(value);
+ next.mnc = le16(value + 2);
+ memcpy(next.operator_name, value + 5, n);
+ next.operator_name[n] = 0;
} else if ((message == 0x4f || message == 0x51) && type == 0x17 && size >= 4) {
level = (int16_t)le16(value); radio = 12; signal = true;
} else if ((message == 0x4f || message == 0x51) && type == 0x14 && size >= 6 && radio != 12) {
@@ -89,7 +97,8 @@ redwood_nas_apply(struct redwood_nas_state *state, const void *frame, size_t len
next.bars = next.registered ? bars_for(level) : 0;
}
if (!serving && !signal) return 0;
- if (next.registered == state->registered && next.has_signal == state->has_signal &&
+ if (next.registered == state->registered && next.has_signal == state->has_signal && next.mcc == state->mcc && next.mnc == state->mnc &&
+ strcmp(next.operator_name, state->operator_name) == 0 &&
next.radio_interface == state->radio_interface && next.dbm == state->dbm && next.bars == state->bars) return 0;
*state = next;
return 1;
diff --git a/xnu/files/bsd/sys/redwood_nas.h b/xnu/files/bsd/sys/redwood_nas.h
index 9fe7677..0315bea 100644
--- a/xnu/files/bsd/sys/redwood_nas.h
+++ b/xnu/files/bsd/sys/redwood_nas.h
@@ -12,6 +12,8 @@ struct redwood_nas_state {
uint8_t radio_interface; /* QMI NAS: 4 GSM, 5 UMTS, 8 LTE, 12 NR */
int16_t dbm; /* LTE/NR RSRP; GSM/UMTS RSSI */
uint8_t bars; /* 0 until registration and a valid signal reading */
+ uint16_t mcc, mnc; /* the current PLMN (serving system TLV 0x10); 0: none told */
+ char operator_name[32]; /* its description, as the network gives it; "" when none */
};
/* Apply one complete QMI NAS frame. 1: state changed; 0: ignored; -1: malformed. */