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

Settings shows Wi-Fi: the kernel side, exported, and the prebuilt kernel

vcvkk5bd73c1eb826
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMS
index c3e0435..4d216ef 100644
--- a/prebuilt/SHA256SUMS
+++ b/prebuilt/SHA256SUMS
@@ -1,6 +1,6 @@
-Built 2026-10-13 22:29 from this tree.
+Built 2026-10-14 19:03 from this tree.
-92fadbfdde4a9cf449284a2c1e8ed2290aa5d25b5704bd41a1535f7e28360196 prebuilt/mach.development.bcm2837
+fda2d8f8cee1c9f6a50b82a88f082baa5a61bde78cbaa39abab126f14ef17a2b prebuilt/mach.development.bcm2837
1332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efi
d2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child
1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_test
diff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837
index 68b1bf6..b3e759b 100755
Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differ
diff --git a/xnu/files/bsd/dev/redwood_apple80211.c b/xnu/files/bsd/dev/redwood_apple80211.c
new file mode 100644
index 0000000..6d4fdf9
--- /dev/null
+++ b/xnu/files/bsd/dev/redwood_apple80211.c
@@ -0,0 +1,609 @@
+/*
+ * Darwin-on-redwood: Apple80211, answered in the kernel.
+ *
+ * iOS's Wi-Fi side -- wifid, and through it Settings and the status bar -- talks to a Wi-Fi
+ * driver in requests that were once ioctls and are, where the driver offers no user client,
+ * ioctls still: SIOCGA80211 and SIOCSA80211 on any socket, with a struct apple80211req that
+ * names the interface, a request type, a value, and a buffer in the caller's memory
+ * (IO80211.framework: Apple80211Get/Set and their kin all end there). XNU hands an interface
+ * ioctl it does not know to the interface, so they arrive in bsd/dev/redwood_net.c, which
+ * passes them here when its link is a radio.
+ *
+ * What is asked is answered from the station boundary (sys/redwood_sta.h): the radio's power,
+ * its channels, a scan and what it heard, the network joined. What happens there by itself is
+ * told to iOS the way a driver tells it: kernel events of class 6 (IEEE 802.11), subclass 1,
+ * whose code is Apple80211's own event number and whose data begins with the interface's name
+ * in 16 bytes (IO80211.framework reads them from a PF_SYSTEM socket and compares the name).
+ *
+ * Every request is still written to the log -- who asks, get or set, the type, the value, the
+ * length -- because which of them wifid needs is found that way. Never what a request carries:
+ * a network's name or its key may be in there.
+ *
+ * The request types and the layouts are Apple's. The old ones are as the headers of its open
+ * IO80211 sources once described them (apple80211_ioctl.h, apple80211_var.h); where iOS 16.5
+ * differs the layout was read out of IO80211.framework of 16.5, which fills and reads the same
+ * structures on the other side (Apple80211GetWithIOCTL, _getScanData, _addScanResultToList).
+ */
+#include <kern/kalloc.h>
+#include <kern/locks.h>
+#include <libkern/libkern.h>
+#include <sys/errno.h>
+#include <sys/kern_event.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/redwood_input.h>
+#include <sys/redwood_net.h>
+#include <sys/redwood_sta.h>
+#include <sys/sockio.h>
+#include <sys/systm.h>
+
+#define SIOCSA80211 0x802869c8u /* _IOW('i', 200, struct apple80211req) */
+#define SIOCGA80211 0xc02869c9u /* _IOWR('i', 201, struct apple80211req) */
+
+struct apple80211req {
+ char req_if_name[16];
+ int32_t req_type;
+ int32_t req_val;
+ uint32_t req_len;
+ user_addr_t req_data __attribute__((aligned(8)));
+};
+
+/* (as far as they have come by: the names help reading the log) */
+static const char *
+type_name(int32_t type)
+{
+ static const struct {
+ int32_t type;
+ const char *name;
+ } names[] = {
+ { 1, "SSID" }, { 2, "AUTH_TYPE" }, { 3, "CIPHER_KEY" }, { 4, "CHANNEL" }, { 5, "POWERSAVE" }, { 6, "PROTMODE" },
+ { 7, "TXPOWER" }, { 8, "RATE" }, { 9, "BSSID" }, { 10, "SCAN_REQ" }, { 11, "SCAN_RESULT" }, { 12, "CARD_CAPABILITIES" },
+ { 13, "STATE" }, { 14, "PHY_MODE" }, { 15, "OP_MODE" }, { 16, "RSSI" }, { 17, "NOISE" }, { 18, "INT_MIT" }, { 19, "POWER" },
+ { 20, "ASSOCIATE" }, { 21, "ASSOCIATE_RESULT" }, { 22, "DISASSOCIATE" }, { 23, "STATUS_DEV_NAME" }, { 24, "IBSS_MODE" },
+ { 25, "HOST_AP_MODE" }, { 26, "AP_MODE" }, { 27, "SUPPORTED_CHANNELS" }, { 28, "LOCALE" }, { 29, "DEAUTH" },
+ { 30, "COUNTERMEASURES" }, { 32, "RATE_SET" }, { 42, "STATION_LIST" }, { 43, "DRIVER_VERSION" },
+ { 44, "HARDWARE_VERSION" }, { 46, "RSN_IE" }, { 47, "BACKGROUND_SCAN" }, { 48, "AP_IE_LIST" }, { 49, "STATS" },
+ { 50, "ASSOCIATION_STATUS" }, { 51, "COUNTRY_CODE" }, { 54, "RADIO_INFO" }, { 57, "MCS" }, { 66, "MCS_INDEX_SET" },
+ { 79, "STA_STATS" }, { 80, "ROAM_THRESH" }, { 85, "IE" }, { 86, "SCAN_REQ_MULTIPLE" }, { 87, "BTCOEX_MODE" },
+ { 90, "SCANCACHE_CLEAR" }, { 94, "VIRTUAL_IF_CREATE" }, { 95, "VIRTUAL_IF_DELETE" }, { 103, "CURRENT_NETWORK" },
+ { 106, "RSSI_BOUNDS" }, { 107, "ROAM" }, { 207, "CHANNELS_INFO" }, { 254, "HW_SUPPORTED_CHANNELS" },
+ };
+
+ for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
+ if (names[i].type == type) {
+ return names[i].name;
+ }
+ }
+ return "?";
+}
+
+/* ---- the layouts ------------------------------------------------------------------------------------------ */
+
+#define CHANNEL_20MHZ 0x2u
+#define CHANNEL_2GHZ 0x8u
+#define CHANNEL_5GHZ 0x10u
+#define CHANNEL_ACTIVE 0x80u /* the radio may send there */
+#define CHANNEL_DFS 0x100u
+
+struct apple80211_channel {
+ uint32_t version, channel, flags;
+};
+
+/* SUPPORTED_CHANNELS (27) and HW_SUPPORTED_CHANNELS (254): 4824 bytes */
+struct apple80211_channels {
+ uint32_t version, count;
+ struct apple80211_channel channels[401];
+ uint32_t unused;
+};
+
+/* CHANNELS_INFO (207): 10016 bytes; of each channel a byte in each of several rows, and a word of flags */
+struct apple80211_channels_info {
+ uint8_t unknown_0[12];
+ uint16_t count;
+ uint8_t unknown_1[800];
+ uint8_t number[400], indoor[400], dfs[400], passive[400], wide_40[400], wide_80[400];
+ uint8_t unknown_2[1602];
+ uint32_t flags[400];
+ uint8_t unknown_3[3600];
+} __attribute__((packed));
+
+/* SCAN_REQ (10): 5456 bytes */
+struct apple80211_scan_request {
+ uint32_t version, bss_type;
+ uint8_t bssid[6], unused_0[2];
+ uint32_t ssid_length;
+ uint8_t ssid[32];
+ uint32_t scan_type; /* 1: asking, 2: listening only */
+ uint32_t phy_mode;
+ uint16_t dwell_ms, unused_1;
+ uint32_t rest_ms;
+ uint32_t channel_count;
+ struct apple80211_channel channels[400];
+ uint64_t flags;
+ uint32_t unused_2;
+ uint32_t name_count; /* networks asked for by name, each in 56 bytes */
+ uint8_t names[10][56];
+ uint32_t short_ssid, unused_3;
+};
+
+/* SCAN_RESULT (11) and CURRENT_NETWORK (103): 1164 bytes */
+struct apple80211_scan_result {
+ uint32_t version;
+ struct apple80211_channel channel;
+ uint16_t noise_known;
+ int16_t noise, snr, rssi;
+ uint16_t beacon_interval, capability;
+ uint8_t bssid[6];
+ uint8_t rate_count, unused_0;
+ uint32_t rates[15]; /* Mbit/s */
+ uint8_t ssid_length, ssid[32], unused_1[3];
+ uint32_t age_ms;
+ uint8_t flags, unused_2;
+ uint16_t elements_length; /* comes in as the room there is */
+ uint8_t elements[1024];
+};
+
+_Static_assert(sizeof(struct apple80211_channels) == 4824, "the channel list as iOS 16.5 has it");
+_Static_assert(sizeof(struct apple80211_channels_info) == 10016 && offsetof(struct apple80211_channels_info, number) == 0x32e &&
+ offsetof(struct apple80211_channels_info, flags) == 0x12d0, "the channels' description as iOS 16.5 has it");
+_Static_assert(sizeof(struct apple80211_scan_request) == 5456 && offsetof(struct apple80211_scan_request, channels) == 0x48 &&
+ offsetof(struct apple80211_scan_request, flags) == 0x1308 && offsetof(struct apple80211_scan_request, names) == 0x1318,
+ "the scan request as iOS 16.5 has it");
+_Static_assert(sizeof(struct apple80211_scan_result) == 1164 && offsetof(struct apple80211_scan_result, ssid_length) == 0x60 &&
+ offsetof(struct apple80211_scan_result, age_ms) == 0x84 && offsetof(struct apple80211_scan_result, elements) == 0x8c,
+ "a scan's result as iOS 16.5 has it");
+
+/* Apple80211's events (APPLE80211_M_...) */
+enum { EVENT_POWER_CHANGED = 1, EVENT_SSID_CHANGED = 2, EVENT_BSSID_CHANGED = 3, EVENT_LINK_CHANGED = 4, EVENT_ASSOC_DONE = 9,
+ EVENT_SCAN_DONE = 10 };
+
+static const char interface_name[16] = "en0"; /* (bsd/dev/redwood_net.c makes one interface, and that is its name) */
+
+static LCK_GRP_DECLARE(apple80211_lock_group, "redwood-apple80211");
+static LCK_MTX_DECLARE(apple80211_lock, &apple80211_lock_group);
+static unsigned result_next; /* which of what the last scan heard a SCAN_RESULT request gets next */
+
+/* ---- channels ---------------------------------------------------------------------------------------- */
+
+static unsigned
+channel_number(unsigned frequency)
+{
+ return frequency == 2484 ? 14 : frequency < 4000 ? (frequency - 2407) / 5 : (frequency - 5000) / 5;
+}
+
+static unsigned
+channel_frequency(const struct apple80211_channel *channel)
+{
+ bool low = channel->flags & CHANNEL_2GHZ ? true : channel->flags & CHANNEL_5GHZ ? false : channel->channel <= 14;
+
+ if (channel->channel == 0 || channel->channel > 196 || (channel->flags & 0x2000)) { /* (0x2000: 6 GHz) */
+ return 0;
+ }
+ return low ? (channel->channel == 14 ? 2484 : 2407 + 5 * channel->channel) : 5000 + 5 * channel->channel;
+}
+
+static void
+channel_fill(struct apple80211_channel *channel, unsigned frequency, unsigned flags)
+{
+ channel->version = 1;
+ channel->channel = channel_number(frequency);
+ channel->flags = CHANNEL_20MHZ | (frequency < 4000 ? CHANNEL_2GHZ : CHANNEL_5GHZ) | (flags & REDWOOD_STA_CHANNEL_PASSIVE ?
+ 0 : CHANNEL_ACTIVE) | (flags & REDWOOD_STA_CHANNEL_RADAR ? CHANNEL_DFS : 0);
+}
+
+/* ---- what the caller is given back ------------------------------------------------------------------- */
+
+/* At most as many bytes as it has room for. */
+static int
+give(const struct apple80211req *request, const void *data, size_t length)
+{
+ return request->req_data == USER_ADDR_NULL ? 0 : copyout(data, request->req_data, length < request->req_len ? length :
+ request->req_len);
+}
+
+/* An access point in the form a scan's result has; the caller has said how much room for elements there is. */
+static int
+give_network(const struct apple80211req *request, const struct redwood_sta_bss *bss)
+{
+ struct apple80211_scan_result *result = kalloc_data(sizeof(*result), Z_WAITOK | Z_ZERO);
+ unsigned room = sizeof(result->elements);
+ int error;
+
+ if (result == NULL) {
+ return ENOMEM;
+ }
+ if (request->req_len >= sizeof(*result) && copyin(request->req_data, result, offsetof(struct apple80211_scan_result,
+ elements)) == 0 && result->elements_length < room) {
+ room = result->elements_length;
+ }
+ bzero(result, sizeof(*result));
+ result->version = 1;
+ channel_fill(&result->channel, bss->frequency, 0);
+ result->rssi = bss->rssi;
+ result->beacon_interval = bss->beacon_interval;
+ result->capability = bss->capability;
+ memcpy(result->bssid, bss->bssid, sizeof(result->bssid));
+ result->ssid_length = bss->ssid_length;
+ memcpy(result->ssid, bss->ssid, bss->ssid_length);
+ result->age_ms = bss->age_ms;
+ result->elements_length = (uint16_t)(bss->elements_length <= room ? bss->elements_length : 0);
+ memcpy(result->elements, bss->elements, result->elements_length);
+ /* the rates it says it has (elements 1 and 50: units of 500 kbit/s, the top bit marks the ones everybody must have) */
+ for (unsigned at = 0; at + 2 <= bss->elements_length && at + 2 + bss->elements[at + 1] <= bss->elements_length;
+ at += 2 + bss->elements[at + 1]) {
+ for (unsigned i = 0; (bss->elements[at] == 1 || bss->elements[at] == 50) && i < bss->elements[at + 1]; i++) {
+ unsigned rate = (bss->elements[at + 2 + i] & 0x7f) / 2;
+
+ if (rate != 0 && rate <= 54 && result->rate_count < 15) {
+ result->rates[result->rate_count++] = rate;
+ }
+ }
+ }
+ error = give(request, result, sizeof(*result));
+ kfree_data(result, sizeof(*result));
+ return error;
+}
+
+/* ---- get ---------------------------------------------------------------------------------------------- */
+
+static int
+get(struct apple80211req *request)
+{
+ struct redwood_sta_state *state;
+ int error = 0;
+
+ switch (request->req_type) {
+ case 43: { /* the driver's name: a version, a length, the text */
+ static const char name[] = "redwood: ath11k for the WCN6750";
+ struct {
+ uint32_t version;
+ uint16_t length;
+ char text[256];
+ } __attribute__((packed)) answer = { .version = 1, .length = sizeof(name) - 1 };
+
+ memcpy(answer.text, name, sizeof(name));
+ return give(request, &answer, sizeof(answer));
+ }
+ case 12: { /* what the card can do, a bit each (apple80211_var.h: APPLE80211_CAP_*) */
+ struct {
+ uint32_t version;
+ uint8_t bits[9];
+ } __attribute__((packed)) answer = { .version = 1 };
+ static const uint8_t has[] = { 2, 3, 6, 9, 10, 14, 17, 19 }; /* AES, AES-CCM, power management, short slot
+ * and preamble, WPA2, WME, short guard at 20 MHz */
+
+ for (unsigned i = 0; i < sizeof(has); i++) {
+ answer.bits[has[i] / 8] |= (uint8_t)(1u << (has[i] % 8));
+ }
+ return give(request, &answer, sizeof(answer));
+ }
+ case 19: { /* the radio's power: one radio. Until the driver is up it counts as on: it */
+ struct { /* is being brought up, and iOS asks this once, early */
+ uint32_t version, radios, state[4];
+ } answer = { .version = 1, .radios = 1, .state = { !redwood_sta_present() || redwood_sta_powered() } };
+
+ return give(request, &answer, sizeof(answer));
+ }
+ case 15: /* the mode: a station (APPLE80211_M_STA) */
+ request->req_val = 1;
+ return 0;
+ case 27:
+ case 254: { /* the channels the radio may tune to */
+ struct apple80211_channels *answer;
+ struct redwood_sta_channel channels[96];
+ unsigned count = redwood_sta_channels(channels, 96);
+
+ if (count == 0 || (answer = kalloc_data(sizeof(*answer), Z_WAITOK | Z_ZERO)) == NULL) {
+ return count == 0 ? ENXIO : ENOMEM;
+ }
+ answer->version = 1;
+ answer->count = count;
+ for (unsigned i = 0; i < count; i++) {
+ channel_fill(&answer->channels[i], channels[i].frequency, channels[i].flags);
+ }
+ error = give(request, answer, sizeof(*answer));
+ kfree_data(answer, sizeof(*answer));
+ return error;
+ }
+ case 207: { /* ... and more of each */
+ struct apple80211_channels_info *answer;
+ struct redwood_sta_channel channels[96];
+ unsigned count = redwood_sta_channels(channels, 96);
+
+ if (count == 0 || (answer = kalloc_data(sizeof(*answer), Z_WAITOK | Z_ZERO)) == NULL) {
+ return count == 0 ? ENXIO : ENOMEM;
+ }
+ answer->count = (uint16_t)count;
+ for (unsigned i = 0; i < count; i++) {
+ struct apple80211_channel channel;
+
+ channel_fill(&channel, channels[i].frequency, channels[i].flags);
+ answer->number[i] = (uint8_t)channel.channel;
+ answer->dfs[i] = (channels[i].flags & REDWOOD_STA_CHANNEL_RADAR) != 0;
+ answer->passive[i] = (channels[i].flags & REDWOOD_STA_CHANNEL_PASSIVE) != 0;
+ answer->flags[i] = channel.flags;
+ }
+ error = give(request, answer, sizeof(*answer));
+ kfree_data(answer, sizeof(*answer));
+ return error;
+ }
+ case 11: { /* what the last scan heard, one access point a request; EIO: that was all */
+ struct redwood_sta_bss *bss = kalloc_data(sizeof(*bss), Z_WAITOK);
+ unsigned index;
+ bool there;
+
+ if (bss == NULL) {
+ return ENOMEM;
+ }
+ lck_mtx_lock(&apple80211_lock);
+ index = result_next++;
+ lck_mtx_unlock(&apple80211_lock);
+ there = redwood_sta_heard(index, bss);
+ error = there ? give_network(request, bss) : EIO;
+ kfree_data(bss, sizeof(*bss));
+ return error;
+ }
+ default:
+ break;
+ }
+
+ /* the rest is about the network joined, and there is none unless the station says so */
+ if ((state = kalloc_data(sizeof(*state), Z_WAITOK)) == NULL) {
+ return ENOMEM;
+ }
+ redwood_sta_state(state);
+ switch (request->req_type) {
+ case 13: /* the state: APPLE80211_S_INIT 0, _SCAN 1, _AUTH 2, _ASSOC 3, _RUN 4 */
+ request->req_val = state->phase == REDWOOD_STA_JOINED ? 4 : state->phase == REDWOOD_STA_JOINING ? 2 :
+ state->phase == REDWOOD_STA_SCANNING ? 1 : 0;
+ break;
+ case 1: /* its name; the length goes back in the request */
+ if (state->phase != REDWOOD_STA_JOINED) {
+ error = ENXIO;
+ } else if ((error = give(request, state->bss.ssid, state->bss.ssid_length)) == 0) {
+ request->req_len = state->bss.ssid_length;
+ }
+ break;
+ case 9: /* its access point's address */
+ error = state->phase != REDWOOD_STA_JOINED ? ENXIO : give(request, state->bss.bssid, 6);
+ break;
+ case 4: { /* its channel */
+ struct {
+ uint32_t version;
+ struct apple80211_channel channel;
+ } answer = { .version = 1 };
+
+ if (state->phase != REDWOOD_STA_JOINED) {
+ error = ENXIO;
+ } else {
+ channel_fill(&answer.channel, state->bss.frequency, 0);
+ error = give(request, &answer, sizeof(answer));
+ }
+ break;
+ }
+ case 16: { /* how strongly it is heard: dBm, per radio and all together, twice over */
+ struct {
+ uint32_t version, radios, unit;
+ int32_t each[4], all, each_ext[4], all_ext;
+ } answer = { .version = 1, .radios = 1, .each = { state->bss.rssi }, .all = state->bss.rssi,
+ .each_ext = { state->bss.rssi }, .all_ext = state->bss.rssi };
+
+ error = state->phase != REDWOOD_STA_JOINED ? ENXIO : give(request, &answer, sizeof(answer));
+ break;
+ }
+ case 103: /* all of it, as a scan's result */
+ error = state->phase != REDWOOD_STA_JOINED ? ENXIO : give_network(request, &state->bss);
+ break;
+ default:
+ error = EOPNOTSUPP;
+ break;
+ }
+ kfree_data(state, sizeof(*state));
+ return error;
+}
+
+/* ---- set ---------------------------------------------------------------------------------------------- */
+
+static int
+set_scan(const struct apple80211req *request, char *said, size_t said_size)
+{
+ struct apple80211_scan_request *asked;
+ struct redwood_sta_scan *what;
+ unsigned unknown = 0;
+ int error;
+
+ if (request->req_len != sizeof(*asked)) {
+ return EINVAL;
+ }
+ if (!redwood_sta_present()) {
+ return EBUSY; /* (the radio is still being brought up: the framework tries again) */
+ }
+ asked = kalloc_data(sizeof(*asked), Z_WAITOK);
+ what = kalloc_data(sizeof(*what), Z_WAITOK | Z_ZERO);
+ if (asked == NULL || what == NULL || (error = copyin(request->req_data, asked, sizeof(*asked))) != 0) {
+ error = asked == NULL || what == NULL ? ENOMEM : error;
+ goto out;
+ }
+ if (asked->ssid_length <= sizeof(what->ssid)) {
+ what->ssid_length = (uint8_t)asked->ssid_length;
+ memcpy(what->ssid, asked->ssid, asked->ssid_length);
+ }
+ what->passive = asked->scan_type == 2;
+ what->dwell_ms = asked->dwell_ms;
+ /* (more channels than there is room to name: every channel) */
+ for (unsigned i = 0; i < asked->channel_count && i < 400 && asked->channel_count <= 64; i++) {
+ unsigned frequency = channel_frequency(&asked->channels[i]);
+
+ if (frequency != 0) {
+ what->frequencies[what->frequency_count++] = (uint16_t)frequency;
+ } else {
+ unknown++;
+ }
+ }
+ snprintf(said, said_size, " (a scan: type %u, %u channels of which %u are not the radio's, %u ms on each, a name of %u bytes, "
+ "%u more names, flags %#llx)", asked->scan_type, asked->channel_count, unknown, asked->dwell_ms, asked->ssid_length,
+ asked->name_count, asked->flags);
+ if (asked->channel_count != 0 && asked->channel_count <= 64 && what->frequency_count == 0) {
+ error = EINVAL; /* (nothing of what is asked for is a channel of this radio's) */
+ } else {
+ lck_mtx_lock(&apple80211_lock);
+ result_next = 0;
+ lck_mtx_unlock(&apple80211_lock);
+ error = redwood_sta_ask_scan(what);
+ }
+out:
+ if (asked != NULL) {
+ kfree_data(asked, sizeof(*asked));
+ }
+ if (what != NULL) {
+ kfree_data(what, sizeof(*what));
+ }
+ return error;
+}
+
+static int
+set(const struct apple80211req *request, char *said, size_t said_size)
+{
+ switch (request->req_type) {
+ case 19: { /* the radio's power */
+ struct {
+ uint32_t version, radios, state[4];
+ } asked;
+ int error;
+
+ if (request->req_len < sizeof(asked) || (error = copyin(request->req_data, &asked, sizeof(asked))) != 0) {
+ return request->req_len < sizeof(asked) ? EINVAL : error;
+ }
+ snprintf(said, said_size, " (power: %s)", asked.state[0] ? "on" : "off");
+ return redwood_sta_ask_power(asked.state[0] != 0);
+ }
+ case 10:
+ return set_scan(request, said, said_size);
+ default:
+ return EOPNOTSUPP;
+ }
+}
+
+/* ---- events -------------------------------------------------------------------------------------------- */
+
+static void
+post(uint32_t code, const void *data, uint32_t length)
+{
+ struct kev_msg message = { .vendor_code = KEV_VENDOR_APPLE, .kev_class = KEV_IEEE80211_CLASS, .kev_subclass = 1,
+ .event_code = code };
+ char name[16];
+
+ memcpy(name, interface_name, sizeof(name));
+ message.dv[0].data_length = sizeof(name);
+ message.dv[0].data_ptr = name;
+ if (length != 0) {
+ message.dv[1].data_length = length;
+ message.dv[1].data_ptr = __DECONST(void *, data);
+ }
+ kev_post_msg(&message);
+}
+
+/* What the station side says has happened (bsd/dev/redwood_sta.c calls this, on its thread or the station's). */
+void
+redwood_apple80211_event(enum redwood_sta_event event, int status)
+{
+ static unsigned said;
+
+ if (said < 200) {
+ said++;
+ printf("apple80211: the station says: %s, %d\n", event == REDWOOD_STA_POWER ? "power" : event == REDWOOD_STA_SCAN_DONE ?
+ "a scan is over" : event == REDWOOD_STA_JOIN_DONE ? "a join is over" : "the link", status);
+ }
+ switch (event) {
+ case REDWOOD_STA_POWER:
+ post(EVENT_POWER_CHANGED, NULL, 0);
+ break;
+ case REDWOOD_STA_SCAN_DONE:
+ lck_mtx_lock(&apple80211_lock);
+ result_next = 0;
+ lck_mtx_unlock(&apple80211_lock);
+ post(EVENT_SCAN_DONE, NULL, 0);
+ break;
+ case REDWOOD_STA_JOIN_DONE:
+ break;
+ case REDWOOD_STA_LINK:
+ post(EVENT_SSID_CHANGED, NULL, 0);
+ post(EVENT_BSSID_CHANGED, NULL, 0);
+ post(EVENT_LINK_CHANGED, NULL, 0);
+ break;
+ }
+}
+
+/* ---- the requests as they arrive --------------------------------------------------------------------- */
+
+/*
+ * How often each kind of request came and how it fared: said when the run ends, because the
+ * lines said along the way can be lost with the middle of a long log.
+ */
+static struct {
+ int32_t type;
+ bool set;
+ unsigned times, answered;
+ int last_error;
+} kinds[96];
+static unsigned kind_count;
+
+static void
+note(const struct apple80211req *request, bool is_set, int error)
+{
+ unsigned i;
+
+ lck_mtx_lock(&apple80211_lock);
+ for (i = 0; i < kind_count && !(kinds[i].type == request->req_type && kinds[i].set == is_set); i++) {
+ }
+ if (i < sizeof(kinds) / sizeof(kinds[0])) {
+ if (i == kind_count) {
+ kinds[kind_count++] = (typeof(kinds[0])) { .type = request->req_type, .set = is_set };
+ }
+ kinds[i].times++;
+ kinds[i].answered += error == 0;
+ kinds[i].last_error = error != 0 ? error : kinds[i].last_error;
+ }
+ lck_mtx_unlock(&apple80211_lock);
+}
+
+void
+redwood_apple80211_summary(void)
+{
+ for (unsigned i = 0; i < kind_count; i++) {
+ printf("apple80211: in this run: %s %d (%s) %u times, answered %u times%s", kinds[i].set ? "set" : "get", kinds[i].type,
+ type_name(kinds[i].type), kinds[i].times, kinds[i].answered, kinds[i].last_error == 0 ? "\n" : "");
+ if (kinds[i].last_error != 0) {
+ printf("; the last refusal: %d%s\n", kinds[i].last_error, kinds[i].last_error == EOPNOTSUPP ? " (not built)" : "");
+ }
+ }
+}
+
+/* An Apple80211 request for the radio's interface, from the process that is running now. */
+errno_t
+redwood_apple80211_ioctl(u_long command, void *data)
+{
+ static unsigned said;
+ struct apple80211req *request = data;
+ char who[32] = "?", what[200] = "";
+ bool is_set = command == SIOCSA80211;
+ int error;
+
+ if (command != SIOCSA80211 && command != SIOCGA80211) {
+ return EOPNOTSUPP;
+ }
+ proc_selfname(who, sizeof(who));
+ error = is_set ? set(request, what, sizeof(what)) : get(request);
+ note(request, is_set, error);
+ /* (a request that is repeated for ever is said a few hundred times) */
+ if (said < 800) {
+ said++;
+ printf("apple80211: %s %s %d (%s), value %d, %u bytes%s: %s", who, is_set ? "sets" : "gets", request->req_type,
+ type_name(request->req_type), request->req_val, request->req_len, what, error == 0 ? "answered\n" : error ==
+ EOPNOTSUPP ? "REFUSED\n" : "");
+ if (error != 0 && error != EOPNOTSUPP) {
+ printf("error %d\n", error);
+ }
+ }
+ return error;
+}
diff --git a/xnu/files/bsd/dev/redwood_lx.c b/xnu/files/bsd/dev/redwood_lx.c
index 39612e7..0cea23b 100644
--- a/xnu/files/bsd/dev/redwood_lx.c
+++ b/xnu/files/bsd/dev/redwood_lx.c
@@ -331,6 +331,21 @@ lx_os_net_attach(const unsigned char *address)
"nowhere");
}
+/*
+ * With wifi=1 the interface is made when the kernel starts, before the radio is up: iOS's Wi-Fi
+ * side looks for it and for its registry entry as soon as it runs, once, and a radio that
+ * turns up twelve seconds later is one it has already failed to open.
+ */
+void
+redwood_lx_net_early(void)
+{
+ uint8_t address[6];
+
+ if (redwood_wifi_radio_address(address)) {
+ lx_os_net_attach(address);
+ }
+}
+
void
lx_os_net_link(int up)
{
@@ -347,6 +362,20 @@ lx_os_net_input(const unsigned char *frame, unsigned long length)
}
}
+/* ---- the station (sys/redwood_sta.h) --------------------------------------------------------------------- */
+
+void
+lx_os_station(const struct redwood_sta_ops *ops)
+{
+ redwood_sta_attach(ops);
+}
+
+void
+lx_os_station_lost(int error)
+{
+ redwood_sta_lost(error);
+}
+
/* ---- the driver ---------------------------------------------------------------------------------------- */
/* The object has its own; this is the one of a kernel built without it. */
diff --git a/xnu/files/bsd/dev/redwood_net.c b/xnu/files/bsd/dev/redwood_net.c
index c12efb6..50728c4 100644
--- a/xnu/files/bsd/dev/redwood_net.c
+++ b/xnu/files/bsd/dev/redwood_net.c
@@ -27,10 +27,13 @@
#include <pexpert/pexpert.h>
#include <sys/kern_event.h>
#include <sys/kpi_mbuf.h>
+#include <sys/proc.h>
#include <sys/redwood_net.h>
#include <sys/sockio.h>
#include <sys/systm.h>
+extern void RedwoodWLANStart(const char *interface); /* iokit/Kernel/RedwoodWLAN.cpp */
+
static LCK_GRP_DECLARE(net_lck_grp, "redwood-net");
static LCK_MTX_DECLARE(net_tx_lock, &net_lck_grp);
static const struct redwood_net_link *net_link;
@@ -173,15 +176,28 @@ redwood_net_input(const uint8_t *frame, size_t length)
ifnet_input(net_ifp, packet, &stats);
}
+static unsigned net_ioctls_said;
+
static errno_t
net_ioctl(ifnet_t ifp, u_long command, void *data)
{
- static const int media[] = { IFM_ETHER | IFM_AUTO };
+ /* (a radio says it is one here too: IO80211.framework lists the interfaces whose media is 802.11) */
+ const int media[] = { (net_link->wireless ? IFM_IEEE80211 : IFM_ETHER) | IFM_AUTO };
struct ifreq *request = data;
struct ifmediareq *media_request = data;
user_addr_t list;
errno_t error = 0;
+ if (net_link->wireless && net_ioctls_said < 80) {
+ char who[32] = "?";
+
+ /* (while iOS's Wi-Fi side is being got to talk to this: who asks the interface what) */
+ proc_selfname(who, sizeof(who));
+ if (strcmp(who, "configd") != 0) {
+ net_ioctls_said++;
+ printf("net: en0 is asked %#lx by %s\n", command, who);
+ }
+ }
switch (command) {
case SIOCSIFADDR:
ifnet_set_flags(ifp, IFF_UP, IFF_UP);
@@ -215,7 +231,8 @@ net_ioctl(ifnet_t ifp, u_long command, void *data)
case SIOCDELMULTI:
break; /* the link hands us everything anyway */
default:
- error = EOPNOTSUPP;
+ /* what iOS's Wi-Fi side asks of a radio's interface: bsd/dev/redwood_apple80211.c */
+ error = net_link->wireless ? redwood_apple80211_ioctl(command, data) : EOPNOTSUPP;
break;
}
return error;
@@ -337,9 +354,14 @@ redwood_net_attach(const struct redwood_net_link *link)
if (net_link_up) {
net_link_event(ifp, KEV_DL_LINK_ON);
}
- printf("net: en0 attached on %s%s, address %02x:%02x:%02x:%02x:%02x:%02x, link %s\n", link->name,
- link->wireless ? " (a radio)" : "", address[0], address[1], address[2], address[3], address[4], address[5],
- net_link_up ? "up" : "down");
+ if (link->wireless) {
+ /* (a radio's address is the phone's own: not for the log; and iOS's Wi-Fi side finds the interface by a service) */
+ printf("net: en0 attached on %s (a radio), link %s\n", link->name, net_link_up ? "up" : "down");
+ RedwoodWLANStart("en0");
+ } else {
+ printf("net: en0 attached on %s, address %02x:%02x:%02x:%02x:%02x:%02x, link %s\n", link->name, address[0],
+ address[1], address[2], address[3], address[4], address[5], net_link_up ? "up" : "down");
+ }
if (kernel_thread_start(net_thread, NULL, &thread) == KERN_SUCCESS) {
thread_deallocate(thread);
}
diff --git a/xnu/files/bsd/dev/redwood_sta.c b/xnu/files/bsd/dev/redwood_sta.c
new file mode 100644
index 0000000..a8d4b33
--- /dev/null
+++ b/xnu/files/bsd/dev/redwood_sta.c
@@ -0,0 +1,321 @@
+/*
+ * Darwin-on-redwood: what stands between the two sides of the station boundary
+ * (sys/redwood_sta.h).
+ *
+ * Whoever wants a network asks from wherever it happens to be: an ioctl of wifid's, the thread
+ * that brings the radio up. The station side wants to be called by one thread, one call at a
+ * time, and a scan or a join takes seconds. So what is asked for is noted here and done by a
+ * thread of this file's; the asker returns at once and hears the outcome as an event. One
+ * request of each kind can wait: a second scan asked for while the first has not begun
+ * replaces it, as does a second join.
+ *
+ * What the last scan heard is kept here, so that it can be read without entering the station
+ * side, and so is the list of channels.
+ */
+#include <kern/kalloc.h>
+#include <kern/locks.h>
+#include <kern/sched_prim.h>
+#include <kern/thread.h>
+#include <libkern/libkern.h>
+#include <mach/mach_types.h>
+#include <sys/errno.h>
+#include <sys/redwood_input.h>
+#include <sys/redwood_sta.h>
+#include <sys/systm.h>
+
+extern void thread_set_thread_name(thread_t thread, const char *name);
+
+#define HEARD_MOST 128
+#define CHANNELS_MOST 96
+
+static LCK_GRP_DECLARE(sta_lock_group, "redwood-sta");
+static LCK_MTX_DECLARE(sta_lock, &sta_lock_group);
+
+static const struct redwood_sta_ops *sta_ops; /* the station side, while there is one */
+static bool sta_thread_made;
+static bool sta_calls; /* the thread is in a call of the station side's */
+static unsigned sta_reads; /* ... and so many others are in its state() */
+static bool sta_on; /* the radio's power, as last asked for */
+
+/* what has been asked for and not begun */
+static bool asked_power, asked_power_on, asked_scan, asked_join, asked_leave;
+static struct redwood_sta_scan asked_scan_what;
+static struct redwood_sta_join asked_join_what;
+
+static struct redwood_sta_bss *heard; /* by the last scan that came to an end */
+static unsigned heard_count;
+static struct redwood_sta_channel channels[CHANNELS_MOST];
+static unsigned channel_count;
+
+static void
+heard_one(const struct redwood_sta_bss *bss, __unused void *context)
+{
+ /* (only the thread writes the list, and it reads the count without the lock) */
+ if (heard_count < HEARD_MOST) {
+ lck_mtx_lock(&sta_lock);
+ heard[heard_count++] = *bss;
+ lck_mtx_unlock(&sta_lock);
+ }
+}
+
+static void
+sta_runs(__unused void *parameter, __unused wait_result_t result)
+{
+ static struct redwood_sta_scan scan;
+ static struct redwood_sta_join join;
+
+ for (;;) {
+ const struct redwood_sta_ops *ops;
+ bool power = false, power_on = false, leave = false, do_join = false, do_scan = false;
+ int error = 0;
+
+ lck_mtx_lock(&sta_lock);
+ while (sta_ops == NULL || !(asked_power || asked_leave || asked_join || asked_scan)) {
+ lck_mtx_sleep(&sta_lock, LCK_SLEEP_DEFAULT, (event_t)&sta_ops, THREAD_UNINT);
+ }
+ ops = sta_ops;
+ /* one thing at a time, in the order that makes sense when several wait */
+ if (asked_power) {
+ power = true;
+ power_on = asked_power_on;
+ asked_power = false;
+ } else if (asked_leave) {
+ leave = true;
+ asked_leave = false;
+ } else if (asked_join) {
+ do_join = true;
+ join = asked_join_what;
+ bzero(&asked_join_what, sizeof(asked_join_what));
+ asked_join = false;
+ } else {
+ do_scan = true;
+ scan = asked_scan_what;
+ asked_scan = false;
+ }
+ sta_calls = true;
+ lck_mtx_unlock(&sta_lock);
+
+ if (power) {
+ error = ops->power(power_on);
+ redwood_apple80211_event(REDWOOD_STA_POWER, error == 0 ? power_on : !power_on);
+ } else if (leave) {
+ ops->leave();
+ redwood_apple80211_event(REDWOOD_STA_LINK, 0);
+ } else if (do_join) {
+ error = ops->join(&join);
+ bzero(&join, sizeof(join));
+ redwood_apple80211_event(REDWOOD_STA_JOIN_DONE, error);
+ if (error == 0) {
+ redwood_apple80211_event(REDWOOD_STA_LINK, 1);
+ }
+ } else if (do_scan) {
+ error = ops->scan(&scan);
+ lck_mtx_lock(&sta_lock);
+ heard_count = 0;
+ lck_mtx_unlock(&sta_lock);
+ ops->heard(heard_one, NULL);
+ redwood_apple80211_event(REDWOOD_STA_SCAN_DONE, error);
+ }
+
+ lck_mtx_lock(&sta_lock);
+ sta_calls = false;
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_calls);
+ }
+}
+
+/* ---- the station side ---------------------------------------------------------------------------------- */
+
+void
+redwood_sta_attach(const struct redwood_sta_ops *ops)
+{
+ thread_t thread;
+
+ if (ops == NULL) {
+ lck_mtx_lock(&sta_lock);
+ sta_ops = NULL;
+ asked_power = asked_scan = asked_join = asked_leave = false;
+ while (sta_calls || sta_reads != 0) {
+ lck_mtx_sleep(&sta_lock, LCK_SLEEP_DEFAULT, (event_t)&sta_calls, THREAD_UNINT);
+ }
+ heard_count = channel_count = 0;
+ lck_mtx_unlock(&sta_lock);
+ return;
+ }
+ if (heard == NULL) {
+ heard = kalloc_data(HEARD_MOST * sizeof(*heard), Z_WAITOK | Z_ZERO);
+ }
+ if (heard == NULL) {
+ redwood_wifi_tell("wifi: no memory for what a scan hears: nobody can ask the radio for a network\n");
+ return;
+ }
+ if (!sta_thread_made) {
+ if (kernel_thread_start(sta_runs, NULL, &thread) != KERN_SUCCESS) {
+ redwood_wifi_tell("wifi: no thread for the station: nobody can ask the radio for a network\n");
+ return;
+ }
+ thread_set_thread_name(thread, "wifi-station");
+ thread_deallocate(thread);
+ sta_thread_made = true;
+ }
+ channel_count = ops->channels(channels, CHANNELS_MOST);
+ lck_mtx_lock(&sta_lock);
+ sta_ops = ops;
+ sta_on = true;
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_ops);
+ redwood_apple80211_event(REDWOOD_STA_POWER, 1);
+}
+
+void
+redwood_sta_lost(__unused int error)
+{
+ redwood_apple80211_event(REDWOOD_STA_LINK, 0);
+}
+
+/* ---- who wants a network ------------------------------------------------------------------------------- */
+
+bool
+redwood_sta_present(void)
+{
+ return sta_ops != NULL;
+}
+
+bool
+redwood_sta_powered(void)
+{
+ return sta_ops != NULL && sta_on;
+}
+
+bool
+redwood_sta_busy(void)
+{
+ bool busy;
+
+ lck_mtx_lock(&sta_lock);
+ busy = sta_ops != NULL && (sta_calls || asked_power || asked_leave || asked_join || asked_scan);
+ lck_mtx_unlock(&sta_lock);
+ return busy;
+}
+
+int
+redwood_sta_ask_power(bool on)
+{
+ lck_mtx_lock(&sta_lock);
+ if (sta_ops == NULL) {
+ lck_mtx_unlock(&sta_lock);
+ return ENXIO;
+ }
+ sta_on = on;
+ asked_power = true;
+ asked_power_on = on;
+ if (!on) {
+ asked_scan = asked_join = asked_leave = false;
+ }
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_ops);
+ return 0;
+}
+
+int
+redwood_sta_ask_scan(const struct redwood_sta_scan *what)
+{
+ lck_mtx_lock(&sta_lock);
+ if (sta_ops == NULL || !sta_on) {
+ lck_mtx_unlock(&sta_lock);
+ return sta_ops == NULL ? ENXIO : ENETDOWN;
+ }
+ asked_scan_what = *what;
+ asked_scan = true;
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_ops);
+ return 0;
+}
+
+int
+redwood_sta_ask_join(const struct redwood_sta_join *what)
+{
+ lck_mtx_lock(&sta_lock);
+ if (sta_ops == NULL || !sta_on) {
+ lck_mtx_unlock(&sta_lock);
+ return sta_ops == NULL ? ENXIO : ENETDOWN;
+ }
+ asked_join_what = *what;
+ asked_join = true;
+ asked_leave = false;
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_ops);
+ return 0;
+}
+
+int
+redwood_sta_ask_leave(void)
+{
+ lck_mtx_lock(&sta_lock);
+ if (sta_ops == NULL) {
+ lck_mtx_unlock(&sta_lock);
+ return ENXIO;
+ }
+ asked_leave = true;
+ asked_join = false;
+ bzero(&asked_join_what, sizeof(asked_join_what));
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_ops);
+ return 0;
+}
+
+bool
+redwood_sta_heard(unsigned index, struct redwood_sta_bss *bss)
+{
+ bool there;
+
+ lck_mtx_lock(&sta_lock);
+ if ((there = index < heard_count)) {
+ *bss = heard[index];
+ }
+ lck_mtx_unlock(&sta_lock);
+ return there;
+}
+
+void
+redwood_sta_state(struct redwood_sta_state *state)
+{
+ const struct redwood_sta_ops *ops;
+
+ bzero(state, sizeof(*state));
+ lck_mtx_lock(&sta_lock);
+ if ((ops = sta_ops) != NULL) {
+ sta_reads++;
+ }
+ lck_mtx_unlock(&sta_lock);
+ if (ops != NULL) {
+ ops->state(state);
+ lck_mtx_lock(&sta_lock);
+ sta_reads--;
+ lck_mtx_unlock(&sta_lock);
+ thread_wakeup((event_t)&sta_calls);
+ }
+}
+
+unsigned
+redwood_sta_channels(struct redwood_sta_channel *out, unsigned most)
+{
+ unsigned count;
+
+ lck_mtx_lock(&sta_lock);
+ count = channel_count < most ? channel_count : most;
+ memcpy(out, channels, count * sizeof(*out));
+ lck_mtx_unlock(&sta_lock);
+ return count;
+}
+
+bool
+redwood_sta_address(uint8_t *address)
+{
+ const struct redwood_sta_ops *ops = sta_ops;
+
+ if (ops != NULL) {
+ memcpy(address, ops->address, 6);
+ }
+ return ops != NULL;
+}
diff --git a/xnu/files/bsd/dev/redwood_wifi.c b/xnu/files/bsd/dev/redwood_wifi.c
index 663d8d1..256e3b4 100644
--- a/xnu/files/bsd/dev/redwood_wifi.c
+++ b/xnu/files/bsd/dev/redwood_wifi.c
@@ -79,13 +79,15 @@
* Nothing here switches a supply rail or changes a pin.
*
* wifi=1 is all of it for whoever uses the phone: the steps that are needed (not the ones that
- * only look), ath11k as step 15 for real, the network of fw/network joined, and everything left
- * running while the system does -- on a thread of its own, so that the system's start does not
- * wait for it, and without a word in the log but the outcome (what the steps say is kept, and
- * shown if the radio does not come up). Without the radio's firmware or without a network to
- * join in the small image it says so in a line and does nothing. (wifi_loud=1 with it: nothing
- * is kept back, for looking into a start that goes wrong.) The rest of this comment is
- * about the steps one by one, wifi_step=N, which is how all this was found out.
+ * only look), ath11k as step 15 for real, its station given to the rest of the kernel to ask
+ * (sys/redwood_sta.h: iOS's Wi-Fi side does, through bsd/dev/redwood_apple80211.c), the network
+ * of fw/network joined if the small image has that file, and everything left running while the
+ * system does -- on a thread of its own, so that the system's start does not wait for it, and
+ * without a word in the log but the outcome (what the steps say is kept, and shown if the radio
+ * does not come up). Without the radio's firmware in the small image it says so in a line and
+ * does nothing. (wifi_loud=1 with it: nothing is kept back, for looking into a start that goes
+ * wrong.) The rest of this comment is about the steps one by one, wifi_step=N, which is how
+ * all this was found out.
*
* More boot-args, for wifi_step=N:
* wifi_new=K steps K and later have not been seen to work (default: the last one)
@@ -124,6 +126,8 @@
* the small image (redwood_wifi_network() below) and the driver stays
* up as the link behind en0; with wifi_keep=1 while the system runs,
* else until the steps are over (wifi_hold=S: S seconds longer)
+ * wifi_station=1 with wifi_lx=2: the driver stays up and its station is the kernel's to
+ * ask (sys/redwood_sta.h); nothing is joined by the driver itself
* wifi_lx_step=MS the driver's start says each stub it comes to and waits MS there: for
* a run that ends without a word (follow it with XL_FOLLOW=2)
* wifi_lx=1 step 15 is ath11k's own instead of the stand-in (redwood_lx.c), with
@@ -156,6 +160,7 @@
#include <sys/errno.h>
#include <sys/redwood_input.h>
#include <sys/redwood_qrtr.h>
+#include <sys/redwood_sta.h>
#include <sys/stat.h>
#include <sys/systm.h>
#include <vm/vm_kern.h>
@@ -323,7 +328,7 @@ redwood_wifi_option(const char *name)
static const struct {
const char *name;
uint32_t value;
- } stands_for[] = { { "wifi_lx", 2 }, { "wifi_smmu", 2 }, { "wifi_join", 1 }, { "wifi_keep", 1 } };
+ } stands_for[] = { { "wifi_lx", 2 }, { "wifi_smmu", 2 }, { "wifi_station", 1 }, { "wifi_keep", 1 } };
uint32_t value = 0;
for (unsigned i = 0; whole && i < sizeof(stands_for) / sizeof(stands_for[0]); i++) {
@@ -3982,7 +3987,7 @@ redwood_wifi_network(uint8_t *name, unsigned *name_length, uint8_t *passphrase,
uint8_t *where[2] = { name, passphrase };
if (file == NULL) {
- printf("wifi: %u: the driver asks which network to join: none was given (fw/network of the small image)\n", step);
+ printf("wifi: %u: which network to join: none was given (fw/network of the small image)\n", step);
return false;
}
for (unsigned n = 0; n < 2 && line < end; n++) {
@@ -3999,7 +4004,7 @@ redwood_wifi_network(uint8_t *name, unsigned *name_length, uint8_t *passphrase,
}
line = stop + 1;
}
- printf("wifi: %u: the driver asks which network to join: a name of %u bytes and a passphrase of %u bytes were given%s\n", step,
+ printf("wifi: %u: which network to join: a name of %u bytes and a passphrase of %u bytes were given%s\n", step,
lengths[0], lengths[1], lengths[0] == 0 || lengths[1] < 8 || lengths[1] > 63 ? ": NOT A NAME OF 1 TO 32 BYTES AND A "
"PASSPHRASE OF 8 TO 63" : "");
if (lengths[0] == 0 || lengths[1] < 8 || lengths[1] > 63) {
@@ -4029,6 +4034,7 @@ redwood_wifi_stop(void)
for (unsigned ms = 0; whole_runs && ms < 40000; ms += 10) {
sleep_ms(10);
}
+ redwood_apple80211_summary();
lck_mtx_lock(&dsp_lock);
if (dsp_started && !dirty) {
bool down = dsp_shutdown("the run is about to end");
@@ -4082,6 +4088,51 @@ steps_over(uint32_t done)
lck_mtx_unlock(&dsp_lock);
}
+/*
+ * The network of the file, joined the way anybody joins one: by asking the station. iOS's Wi-Fi
+ * side may ask for another later, or for none.
+ */
+static void
+join_given(uint64_t began)
+{
+ static struct redwood_sta_join what;
+ struct redwood_sta_state *state;
+ unsigned name_length = sizeof(what.ssid), passphrase_length = sizeof(what.passphrase);
+ uint64_t size = 0;
+ int error;
+
+ if (image_file("network", &size) == NULL) {
+ tell("wifi: no network to join was given (fw-wifi/network, see the README): the radio waits to be asked\n");
+ return;
+ }
+ bzero(&what, sizeof(what));
+ if (!redwood_wifi_network(what.ssid, &name_length, what.passphrase, &passphrase_length)) {
+ tell("wifi: the network given in fw/network is not a name and a passphrase: nothing is joined\n");
+ return;
+ }
+ what.ssid_length = (uint8_t)name_length;
+ what.passphrase_length = (uint8_t)passphrase_length;
+ what.security = REDWOOD_STA_WPA2_PSK;
+ error = redwood_sta_ask_join(&what);
+ bzero(&what, sizeof(what));
+ for (unsigned waited = 0; error == 0 && redwood_sta_busy() && waited < 300; waited++) {
+ sleep_ms(100);
+ }
+ if ((state = kalloc_data(sizeof(*state), Z_WAITOK)) == NULL) {
+ return;
+ }
+ redwood_sta_state(state);
+ if (state->phase == REDWOOD_STA_JOINED) {
+ tell("wifi: THE NETWORK OF THE FILE IS JOINED, %llu.%llu s after the kernel began on the radio\n", (now_us() - began) /
+ 1000000, (now_us() - began) / 100000 % 10);
+ } else {
+ tell("wifi: THE NETWORK OF THE FILE IS NOT JOINED (%d, %d): the radio waits to be asked. The last of what was said:\n",
+ error, state->last_error);
+ say_kept();
+ }
+ kfree_data(state, sizeof(*state));
+}
+
/*
* wifi=1: the whole of it on a thread of its own, so that the system starts meanwhile (the
* firmware's calibration alone takes seven seconds). The steps that only look are left out.
@@ -4112,8 +4163,9 @@ whole_thread(__unused void *parameter, __unused wait_result_t result)
}
last_step = needed[sizeof(needed) - 1];
if (failed == 0) {
- tell("wifi: THE RADIO IS UP AND ITS NETWORK JOINED, %llu.%llu s after the kernel began on it\n", (now_us() - began) /
- 1000000, (now_us() - began) / 100000 % 10);
+ tell("wifi: THE RADIO IS UP, %llu.%llu s after the kernel began on it\n", (now_us() - began) / 1000000,
+ (now_us() - began) / 100000 % 10);
+ join_given(began);
} else {
tell("wifi: THE RADIO DID NOT COME UP: step %u failed, %llu s in. The last of what was said on the way:\n", failed,
(now_us() - began) / 1000000);
@@ -4161,12 +4213,9 @@ redwood_wifi_init(void)
printf("wifi: wifi=1, but the radio's firmware is not in the small image (fw-wifi/, see the README): no Wi-Fi\n");
return;
}
- if (image_file("network", &size) == NULL) {
- printf("wifi: wifi=1, but no network to join was given (fw-wifi/network, see the README): the radio stays off\n");
- return;
- }
whole = whole_runs = true;
quiet = !(PE_parse_boot_argn("wifi_loud", &back, sizeof(back)) && back);
+ redwood_lx_net_early();
pause_ms = watch_seconds = 0;
new_from = STEPS + 1;
if (kernel_thread_start(whole_thread, NULL, &thread) != KERN_SUCCESS) {
diff --git a/xnu/files/bsd/sys/redwood_input.h b/xnu/files/bsd/sys/redwood_input.h
index d0bc20c..551a263 100644
--- a/xnu/files/bsd/sys/redwood_input.h
+++ b/xnu/files/bsd/sys/redwood_input.h
@@ -62,6 +62,7 @@ void redwood_wifi_quiesce(void); /* on the way back to the loader: the Wi
int redwood_lx_start(void); /* the driver brought up on the radio as far as it is built: 0 or an errno */
void redwood_lx_stop(void); /* ... and down again, if it stayed up (a network joined) */
int redwood_lx_prepare(void); /* before all that: the memory the radio will be shown, taken; 0 or an errno */
+void redwood_lx_net_early(void); /* ... and en0 made on the radio now, if the kernel was given its address */
bool redwood_wifi_dsp_is_up(void); /* the DSP that runs the radio's firmware has been started and has a link */
const uint8_t *redwood_wifi_driver_file(const char *name, uint64_t *size); /* a file by the name Linux has for it */
bool redwood_wifi_radio_map(uint64_t physical, uint64_t size, unsigned long long *address); /* memory shown to the radio */
diff --git a/xnu/files/bsd/sys/redwood_lx.h b/xnu/files/bsd/sys/redwood_lx.h
index 6e79f02..1564128 100644
--- a/xnu/files/bsd/sys/redwood_lx.h
+++ b/xnu/files/bsd/sys/redwood_lx.h
@@ -2,7 +2,8 @@
* The whole of what the Wi-Fi driver's object asks of the kernel it is linked into. That object
* (tools/mk-ath11k.sh in the repository: Linux's ath11k on FreeBSD's LinuxKPI headers and our
* wifi/lx) is compiled as FreeBSD kernel code, bsd/dev/redwood_lx.c on this side as XNU's;
- * neither sees the other's headers, so nothing but C's own types crosses. Everything the
+ * neither sees the other's headers, so nothing but C's own types crosses (and the station
+ * boundary's, redwood_sta.h, which is written for both). Everything the
* driver's side knows of locks, timers, work queues and buffers is built in wifi/lx/src on the
* few calls here.
*
@@ -12,6 +13,8 @@
#ifndef _SYS_REDWOOD_LX_H_
#define _SYS_REDWOOD_LX_H_
+#include "redwood_sta.h"
+
/* ---- memory ---- */
void *lx_os_alloc(unsigned long size); /* zeroed; NULL when there is none */
void lx_os_free(void *memory, unsigned long size);
@@ -66,6 +69,10 @@ void lx_os_net_attach(const unsigned char *address); /* there is a radio, and t
void lx_os_net_link(int up); /* frames can pass now (a network is joined) / no longer */
void lx_os_net_input(const unsigned char *frame, unsigned long length); /* an Ethernet frame has arrived */
+/* ---- the station: scanning and joining, for whoever asks the kernel (redwood_sta.h) ---- */
+void lx_os_station(const struct redwood_sta_ops *ops); /* here it is, to be asked; NULL: no longer (returns when no call is under way) */
+void lx_os_station_lost(int error); /* the network joined is gone by itself */
+
/*
* ---- the names the object shows the kernel. lx_start(): bring the driver up on the radio and
* do what the kernel's options ask (scan; join a network). 0, or an errno. Returns when that is
diff --git a/xnu/files/bsd/sys/redwood_net.h b/xnu/files/bsd/sys/redwood_net.h
index 293d285..41550ce 100644
--- a/xnu/files/bsd/sys/redwood_net.h
+++ b/xnu/files/bsd/sys/redwood_net.h
@@ -55,6 +55,8 @@ void redwood_net_input(const uint8_t *frame, size_t length);
void redwood_net_link_state(bool up);
void redwood_net_init(void); /* the links there are: each looks for its hardware (or its boot-arg) */
+/* an Apple80211 request (SIOCGA80211, SIOCSA80211) for the interface of a radio: redwood_apple80211.c */
+errno_t redwood_apple80211_ioctl(u_long command, void *data);
void redwood_virtio_net_init(void); /* boot-arg virtio_net=1: QEMU's virtio network device */
#endif /* KERNEL */
diff --git a/xnu/files/bsd/sys/redwood_sta.h b/xnu/files/bsd/sys/redwood_sta.h
new file mode 100644
index 0000000..5a8d955
--- /dev/null
+++ b/xnu/files/bsd/sys/redwood_sta.h
@@ -0,0 +1,119 @@
+/*
+ * Darwin-on-redwood: the station boundary.
+ *
+ * On one side whatever does the scanning and the joining with a radio: the station logic over
+ * ath11k on the phone (wifi/lx in the repository). On the other whoever wants a network: the
+ * Apple80211 requests of iOS's Wi-Fi side, answered in bsd/dev/redwood_apple80211.c, and the
+ * kernel's own join of the network it was given in a file (bsd/dev/redwood_wifi.c). Frames do
+ * not pass here, and neither does "the link is up": those go through bsd/sys/redwood_net.h,
+ * which the station side calls itself.
+ *
+ * Between the two stands bsd/dev/redwood_sta.c: one thread, on which every call into the station
+ * side is made, one at a time, and what the last scan heard, kept for whoever asks.
+ *
+ * Nothing but C's own types here: the station side is not compiled as XNU's code.
+ */
+#ifndef _SYS_REDWOOD_STA_H_
+#define _SYS_REDWOOD_STA_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define REDWOOD_STA_ELEMENTS_MOST 1024
+
+/* One access point, as a scan heard it. */
+struct redwood_sta_bss {
+ uint8_t bssid[6];
+ uint8_t ssid[32], ssid_length;
+ uint16_t frequency; /* MHz */
+ int16_t rssi; /* dBm */
+ uint16_t beacon_interval; /* in units of 1024 microseconds */
+ uint16_t capability; /* the beacon's capability field */
+ uint32_t age_ms; /* how long ago it was last heard */
+ uint16_t elements_length; /* the beacon's information elements as received: who asks */
+ uint8_t elements[REDWOOD_STA_ELEMENTS_MOST]; /* reads the network's protection out of them itself */
+};
+
+/* What to scan for. All zero: every channel, the radio's own way. */
+struct redwood_sta_scan {
+ uint8_t ssid[32], ssid_length; /* ask for this network by name (a hidden one answers only then) */
+ uint16_t frequencies[64], frequency_count; /* only these channels */
+ bool passive; /* only listen */
+ uint16_t dwell_ms; /* on each channel; 0: the radio's own */
+};
+
+enum { REDWOOD_STA_OPEN, REDWOOD_STA_WPA2_PSK };
+
+struct redwood_sta_join {
+ uint8_t ssid[32], ssid_length;
+ uint8_t bssid[6]; /* all zero: the access point of that name heard best */
+ int security;
+ uint8_t pmk[32]; /* WPA2 with a passphrase: the key made of the passphrase and the name ... */
+ uint8_t passphrase[64], passphrase_length; /* ... or, if this is not empty, the passphrase itself */
+};
+
+enum redwood_sta_phase { REDWOOD_STA_OFF, REDWOOD_STA_IDLE, REDWOOD_STA_SCANNING, REDWOOD_STA_JOINING, REDWOOD_STA_JOINED };
+
+struct redwood_sta_state {
+ enum redwood_sta_phase phase;
+ struct redwood_sta_bss bss; /* the network joined or being joined */
+ int last_error; /* why the last join failed or the network was lost (an errno); 0: it was not */
+};
+
+#define REDWOOD_STA_CHANNEL_PASSIVE 1u /* the radio may only listen there */
+#define REDWOOD_STA_CHANNEL_RADAR 2u /* ... and has to look out for radar */
+
+struct redwood_sta_channel {
+ uint16_t frequency; /* MHz */
+ uint16_t flags;
+};
+
+/*
+ * What the station side supplies. All but state() are called on one thread, one at a time, and
+ * may take as long as the thing takes: scan() returns when the scan is over, join() when frames
+ * can pass or it is known why not. Each gives 0 or an errno.
+ */
+struct redwood_sta_ops {
+ int (*power)(bool on); /* off: leave the network, stop the radio; on: start it */
+ int (*scan)(const struct redwood_sta_scan *what);
+ void (*heard)(void (*each)(const struct redwood_sta_bss *bss, void *context), void *context); /* by the last scan */
+ int (*join)(const struct redwood_sta_join *what);
+ int (*leave)(void);
+ void (*state)(struct redwood_sta_state *state); /* on any thread; does not sleep */
+ unsigned (*channels)(struct redwood_sta_channel *channels, unsigned most); /* what the radio may tune to */
+ uint8_t address[6];
+};
+
+/* What happens, said to whoever listens (the Apple80211 side). */
+enum redwood_sta_event {
+ REDWOOD_STA_POWER, /* status: 1 on, 0 off */
+ REDWOOD_STA_SCAN_DONE, /* status: 0, or the scan's errno */
+ REDWOOD_STA_JOIN_DONE, /* status: 0, or the join's errno */
+ REDWOOD_STA_LINK, /* status: 1 a network is joined, 0 it has been left or lost */
+};
+
+#ifdef KERNEL
+/* ---- the station side ---- */
+void redwood_sta_attach(const struct redwood_sta_ops *ops); /* NULL: it is going away (waits for a call under way) */
+void redwood_sta_lost(int error); /* the network joined is gone by itself */
+
+/* ---- who wants a network: each asks and returns; the outcome is an event. 0, or an errno ---- */
+bool redwood_sta_present(void);
+int redwood_sta_ask_power(bool on);
+int redwood_sta_ask_scan(const struct redwood_sta_scan *what);
+int redwood_sta_ask_join(const struct redwood_sta_join *what);
+int redwood_sta_ask_leave(void);
+bool redwood_sta_busy(void); /* something asked for is not over yet */
+bool redwood_sta_powered(void);
+/* the `index`th access point the last scan heard: true, or false when there are not that many */
+bool redwood_sta_heard(unsigned index, struct redwood_sta_bss *bss);
+void redwood_sta_state(struct redwood_sta_state *state);
+unsigned redwood_sta_channels(struct redwood_sta_channel *channels, unsigned most);
+bool redwood_sta_address(uint8_t *address);
+
+/* ---- the listener: bsd/dev/redwood_apple80211.c ---- */
+void redwood_apple80211_event(enum redwood_sta_event event, int status);
+void redwood_apple80211_summary(void); /* what was asked in this run, to the log */
+#endif
+
+#endif
diff --git a/xnu/files/iokit/Kernel/GenericARMPE.cpp b/xnu/files/iokit/Kernel/GenericARMPE.cpp
index 0f3e578..4ed7f0f 100644
--- a/xnu/files/iokit/Kernel/GenericARMPE.cpp
+++ b/xnu/files/iokit/Kernel/GenericARMPE.cpp
@@ -272,6 +272,7 @@ GenericARMPE::start(IOService * provider)
MiniIOSurfaceStart(this);
MiniIOMobileFramebufferStart(this);
MiniAppleKeyStoreStart();
+ MiniIONetworkStackStart();
return true;
}
diff --git a/xnu/files/iokit/Kernel/MiniDrivers.h b/xnu/files/iokit/Kernel/MiniDrivers.h
index ed58101..1a35381 100644
--- a/xnu/files/iokit/Kernel/MiniDrivers.h
+++ b/xnu/files/iokit/Kernel/MiniDrivers.h
@@ -6,6 +6,7 @@
* MiniIOSurface.cpp IOSurface: pixel buffers shared between processes
* MiniIOMobileFramebuffer.cpp IOMobileFramebuffer: the display (the boot framebuffer)
* MiniAppleKeyStore.cpp AppleKeyStore: the keybag of a device without a passcode
+ * MiniIONetworkStack.cpp IONetworkStack: what configd's interface namer waits for
*/
#ifndef _IOKIT_MINIDRIVERS_H
#define _IOKIT_MINIDRIVERS_H
@@ -15,5 +16,6 @@
void MiniIOSurfaceStart(IOService * provider);
void MiniIOMobileFramebufferStart(IOService * provider);
void MiniAppleKeyStoreStart(void);
+void MiniIONetworkStackStart(void);
#endif /* _IOKIT_MINIDRIVERS_H */
diff --git a/xnu/files/iokit/Kernel/MiniIONetworkStack.cpp b/xnu/files/iokit/Kernel/MiniIONetworkStack.cpp
new file mode 100644
index 0000000..a2b963c
--- /dev/null
+++ b/xnu/files/iokit/Kernel/MiniIONetworkStack.cpp
@@ -0,0 +1,114 @@
+/*
+ * MiniIONetworkStack: a stand-in for IONetworkStack of Apple's IONetworkingFamily, as seen by
+ * configd's interface namer.
+ *
+ * The real one gives the BSD names (en0, en1, ...) to the IONetworkInterface objects of the
+ * drivers, when the interface namer asks. Here interfaces are made with the BSD interface KPI
+ * (bsd/dev/redwood_net.c) and are born with their names, so there is never anything to name.
+ * But the namer wants this object all the same: until it has opened it, it does not say in
+ * configd's store that the registry has gone quiet (the key Plugin:InterfaceNamer, "*QUIET*"),
+ * and gives up only after five minutes ("*TIMEOUT*"). SystemConfiguration's
+ * SCNetworkInterfaceCopyAll() waits for one of the two, and with it whoever asks for the list of
+ * interfaces: wifid as soon as it has a device, and behind wifid SpringBoard.
+ *
+ * So: the service, a user client that can be opened, and a refusal of the naming request.
+ */
+
+#include <IOKit/IOLib.h>
+#include <IOKit/IOKitKeys.h>
+#include <IOKit/IOService.h>
+#include <IOKit/IOUserClient.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include "MiniDrivers.h"
+
+class IONetworkStack : public IOService
+{
+ OSDeclareDefaultStructors(IONetworkStack);
+
+public:
+ virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE;
+};
+
+OSDefineMetaClassAndStructors(IONetworkStack, IOService);
+
+bool
+IONetworkStack::start(IOService * provider)
+{
+ if (!IOService::start(provider)) {
+ return false;
+ }
+ setProperty(kIOUserClientClassKey, "IONetworkStackUserClient");
+ setName("IONetworkStack");
+ registerService();
+ return true;
+}
+
+class IONetworkStackUserClient : public IOUserClient
+{
+ OSDeclareDefaultStructors(IONetworkStackUserClient);
+
+public:
+ virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE;
+ virtual IOReturn clientClose(void) APPLE_KEXT_OVERRIDE;
+ virtual IOReturn setProperties(OSObject * properties) APPLE_KEXT_OVERRIDE;
+};
+
+OSDefineMetaClassAndStructors(IONetworkStackUserClient, IOUserClient);
+
+bool
+IONetworkStackUserClient::start(IOService * provider)
+{
+ char who[32] = "?";
+
+ if (!IOUserClient::start(provider)) {
+ return false;
+ }
+ /* whether the registry is quiet at this moment is what the namer goes on to ask */
+ proc_selfname(who, sizeof(who));
+ IOLog("MiniIONetworkStack: opened by %s; the registry's busy state is %u\n", who,
+ (unsigned) IOService::getServiceRoot()->getBusyState());
+ return true;
+}
+
+IOReturn
+IONetworkStackUserClient::clientClose(void)
+{
+ if (!isInactive()) {
+ terminate();
+ }
+ return kIOReturnSuccess;
+}
+
+/* "Name this interface" (a dictionary: IONetworkStackUserCommand, IOPathMatch, IOInterfaceUnit). */
+IOReturn
+IONetworkStackUserClient::setProperties(OSObject * properties)
+{
+ static unsigned said;
+
+ if (said++ < 4) {
+ IOLog("MiniIONetworkStack: asked to name an interface: there are none of that kind\n");
+ }
+ return kIOReturnUnsupported;
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+void
+MiniIONetworkStackStart(void)
+{
+ /* where the real one is: IOService:/IOResources/IONetworkStack */
+ IOService * resources = IOService::getResourceService();
+ IONetworkStack * stack = OSTypeAlloc(IONetworkStack);
+
+ if (resources == NULL || stack == NULL || !stack->init() || !stack->attach(resources)) {
+ OSSafeReleaseNULL(stack);
+ IOLog("MiniIONetworkStack: cannot create the service\n");
+ return;
+ }
+ if (!stack->start(resources)) {
+ stack->detach(resources);
+ }
+ stack->release();
+}
diff --git a/xnu/files/iokit/Kernel/RedwoodWLAN.cpp b/xnu/files/iokit/Kernel/RedwoodWLAN.cpp
new file mode 100644
index 0000000..c0676fa
--- /dev/null
+++ b/xnu/files/iokit/Kernel/RedwoodWLAN.cpp
@@ -0,0 +1,65 @@
+/*
+ * RedwoodWLAN: the registry entry by which iOS finds the Wi-Fi interface.
+ *
+ * en0 is made with the BSD interface KPI (bsd/dev/redwood_net.c) and has no IOKit object behind
+ * it; iOS's Wi-Fi side looks for one before anything else. wifid's device is whatever service
+ * has the property IO80211InterfaceRole = "Infrastructure", and IO80211.framework binds to an
+ * interface through a service whose IOInterfaceName is the interface's name. This is that
+ * service and nothing more: properties. It has no user client, on purpose: the framework's
+ * attempt to open one fails, it says "Falling back to IOCTL path", and from then on every
+ * request is an ioctl on a socket, which bsd/dev/redwood_apple80211.c answers.
+ */
+
+#include <IOKit/IOLib.h>
+#include <IOKit/IOPlatformExpert.h>
+#include <IOKit/IOService.h>
+#include <IOKit/IOUserClient.h>
+
+extern "C" void RedwoodWLANStart(const char * interface);
+
+class RedwoodWLAN : public IOService
+{
+ OSDeclareDefaultStructors(RedwoodWLAN);
+
+public:
+ virtual IOReturn newUserClient(task_t owningTask, void * securityID, UInt32 type, OSDictionary * properties,
+ IOUserClient ** handler) APPLE_KEXT_OVERRIDE;
+};
+
+OSDefineMetaClassAndStructors(RedwoodWLAN, IOService);
+
+/* There is none (see the top); that somebody asked shows that the service was found. */
+IOReturn
+RedwoodWLAN::newUserClient(task_t owningTask, void * securityID, UInt32 type, OSDictionary * properties, IOUserClient ** handler)
+{
+ static unsigned said;
+
+ if (said++ < 8) {
+ IOLog("RedwoodWLAN: a user client of type %u is asked for: there is none\n", (unsigned) type);
+ }
+ return kIOReturnUnsupported;
+}
+
+/* Once, when the interface of a radio exists. */
+void
+RedwoodWLANStart(const char * interface)
+{
+ IOService * provider = IOService::getPlatform();
+ RedwoodWLAN * wlan = OSTypeAlloc(RedwoodWLAN);
+
+ if (wlan == NULL || provider == NULL || !wlan->init() || !wlan->attach(provider)) {
+ OSSafeReleaseNULL(wlan);
+ IOLog("RedwoodWLAN: cannot create the service\n");
+ return;
+ }
+ wlan->setName("RedwoodWLAN");
+ wlan->setProperty("IOInterfaceName", interface);
+ wlan->setProperty("IO80211InterfaceRole", "Infrastructure");
+ if (!wlan->start(provider)) {
+ wlan->detach(provider);
+ IOLog("RedwoodWLAN: the service did not start\n");
+ } else {
+ wlan->registerService();
+ }
+ wlan->release();
+}
diff --git a/xnu/redwood.patch b/xnu/redwood.patch
index f120b1e..040f203 100644
--- a/xnu/redwood.patch
+++ b/xnu/redwood.patch
@@ -46,10 +46,10 @@ index 222158a93918..68bb0f3e56bf 100755
######################################################################
# HISTORY
diff --git a/bsd/conf/files b/bsd/conf/files
-index 44274016a4cf..9666e7866eed 100644
+index 44274016a4cf..4ca9899feb85 100644
--- a/bsd/conf/files
+++ b/bsd/conf/files
-@@ -109,6 +109,18 @@ bsd/dev/munge.c optional config_requires_u32_munging
+@@ -109,6 +109,20 @@ bsd/dev/munge.c optional config_requires_u32_munging
bsd/dev/unix_startup.c standard
bsd/dev/monotonic.c optional monotonic
@@ -59,16 +59,18 @@ index 44274016a4cf..9666e7866eed 100644
+bsd/dev/redwood_buttons.c standard
+bsd/dev/redwood_net.c standard
+bsd/dev/redwood_virtio_net.c standard
++bsd/dev/redwood_apple80211.c standard
+bsd/dev/redwood_cpufreq.c standard
+bsd/dev/redwood_adreno.c standard
+bsd/dev/redwood_wifi.c standard
+bsd/dev/redwood_qmi.c standard
+bsd/dev/redwood_wlfw.c standard
+bsd/dev/redwood_lx.c standard
++bsd/dev/redwood_sta.c standard
bsd/dev/dev_perfmon.c optional config_perfmon
bsd/libkern/crc32.c standard
-@@ -155,6 +167,10 @@ bsd/miscfs/devfs/devfs_vfsops.c optional devfs
+@@ -155,6 +169,10 @@ bsd/miscfs/devfs/devfs_vfsops.c optional devfs
bsd/miscfs/mockfs/mockfs_fsnode.c optional mockfs
bsd/miscfs/mockfs/mockfs_vfsops.c optional mockfs
bsd/miscfs/mockfs/mockfs_vnops.c optional mockfs
@@ -79,7 +81,7 @@ index 44274016a4cf..9666e7866eed 100644
bsd/miscfs/routefs/routefs_ops.c optional routefs
-@@ -361,6 +377,7 @@ bsd/security/audit/audit_syscalls.c standard
+@@ -361,6 +379,7 @@ bsd/security/audit/audit_syscalls.c standard
bsd/security/audit/audit_worker.c optional config_audit
bsd/pthread/pthread_shims.c standard
@@ -87,7 +89,7 @@ index 44274016a4cf..9666e7866eed 100644
bsd/pthread/pthread_priority.c standard
bsd/pthread/pthread_workqueue.c standard
-@@ -383,6 +400,7 @@ bsd/kern/kern_debug.c standard
+@@ -383,6 +402,7 @@ bsd/kern/kern_debug.c standard
bsd/kern/kern_symfile.c standard
bsd/kern/kern_descrip.c standard
bsd/kern/kern_guarded.c standard
@@ -1394,10 +1396,10 @@ index 5219fb0d9ed6..29978e9cff43 100644
}
}
diff --git a/iokit/conf/files b/iokit/conf/files
-index 5fb0a52062e0..5edb1f225d18 100644
+index 5fb0a52062e0..f90b663607f3 100644
--- a/iokit/conf/files
+++ b/iokit/conf/files
-@@ -79,6 +79,11 @@ iokit/Kernel/IOSubMemoryDescriptor.cpp optional iokitcpp
+@@ -79,6 +79,13 @@ iokit/Kernel/IOSubMemoryDescriptor.cpp optional iokitcpp
iokit/Kernel/IOGuardPageMemoryDescriptor.cpp optional iokitcpp
iokit/Kernel/IOPlatformExpert.cpp optional iokitcpp
@@ -1405,7 +1407,9 @@ index 5fb0a52062e0..5edb1f225d18 100644
+iokit/Kernel/MiniIOSurface.cpp optional iokitcpp
+iokit/Kernel/MiniIOMobileFramebuffer.cpp optional iokitcpp
+iokit/Kernel/RedwoodGPU.cpp optional iokitcpp
++iokit/Kernel/RedwoodWLAN.cpp optional iokitcpp
+iokit/Kernel/MiniAppleKeyStore.cpp optional iokitcpp
++iokit/Kernel/MiniIONetworkStack.cpp optional iokitcpp
iokit/Kernel/IOPlatformIO.cpp optional iokitcpp
iokit/Kernel/IOCPU.cpp optional iokitcpp