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 joins a network: the kernel side, exported, and the prebuilt kernel

vcvkk86e3064edcf5
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMS
index 8684bac..8d130aa 100644
--- a/prebuilt/SHA256SUMS
+++ b/prebuilt/SHA256SUMS
@@ -1,6 +1,6 @@
-Built 2026-10-14 19:13 from this tree.
+Built 2026-10-14 20:38 from this tree.
-25c35e26543477619e0169c1801fc0f14f9637c7d8fadd223a77241e373b19a5 prebuilt/mach.development.bcm2837
+09231dbf122b9be00b55450a89827ef0042a7b52f5e3adc2872ccc6dfbc72485 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 b46a1ab..d10167f 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
index 6d4fdf9..8ad60b4 100644
--- a/xnu/files/bsd/dev/redwood_apple80211.c
+++ b/xnu/files/bsd/dev/redwood_apple80211.c
@@ -22,7 +22,14 @@
* 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).
+ * structures on the other side (Apple80211GetWithIOCTL, _getScanData, _addScanResultToList,
+ * _performAssociation, _dispatchAsyncAssocEvent, _dispatchLinkChangedEvent).
+ *
+ * A join: ASSOCIATE (20) carries the network's name, perhaps its access point, and the
+ * passphrase as typed (the framework does not make the key of it), and is answered at once;
+ * when the station has joined or failed, event 9 says so, and ASSOCIATE_RESULT (21) gives the
+ * outcome as one of Apple80211's result numbers, which the framework turns into its errors:
+ * 1 success, 21 "invalid PMK" (a wrong passphrase), 9 a timeout, 2 anything else.
*/
#include <kern/kalloc.h>
#include <kern/locks.h>
@@ -143,6 +150,37 @@ struct apple80211_scan_result {
uint8_t elements[1024];
};
+/* ASSOCIATE (20): 592 bytes; of what follows the key (the RSN element wifid built, flags) nothing is used */
+struct apple80211_assoc {
+ uint32_t version;
+ uint16_t mode, auth_lower, auth_upper, unused_0;
+ uint32_t ssid_length;
+ uint8_t ssid[32];
+ uint8_t bssid[6], unused_1[2];
+ uint32_t key_version, key_length, key_cipher; /* cipher 10: a passphrase as typed; 6: the key (from 64 hex digits) */
+ uint16_t key_flags, key_index;
+ uint8_t key[64];
+ uint8_t rest[0x250 - 0x88];
+};
+
+#define CIPHER_PMK 6
+#define CIPHER_PASSPHRASE 10
+
+/* the link event's data (at least 32 bytes, or the framework drops the event) */
+struct apple80211_link_changed {
+ uint8_t down, unused_0[3];
+ int32_t rssi;
+ uint16_t snr, noise;
+ uint8_t unused_1[4];
+ uint8_t involuntary, unused_2[3];
+ uint32_t reason, subreason;
+ uint8_t unused_3[4];
+};
+
+_Static_assert(sizeof(struct apple80211_assoc) == 592 && offsetof(struct apple80211_assoc, key) == 0x48,
+ "the association request as iOS 16.5 has it");
+_Static_assert(sizeof(struct apple80211_link_changed) == 32 && offsetof(struct apple80211_link_changed, reason) == 0x14,
+ "the link event as iOS 16.5 reads it");
_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");
@@ -162,6 +200,7 @@ static const char interface_name[16] = "en0"; /* (bsd/dev/redwood_net.c makes
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 */
+static uint32_t join_result; /* of the last join asked for: 0 while it runs, then Apple80211's number */
/* ---- channels ---------------------------------------------------------------------------------------- */
@@ -327,6 +366,11 @@ get(struct apple80211req *request)
kfree_data(answer, sizeof(*answer));
return error;
}
+ case 21: /* how the last join went (0: not over yet) */
+ lck_mtx_lock(&apple80211_lock);
+ request->req_val = (int32_t)join_result;
+ lck_mtx_unlock(&apple80211_lock);
+ return 0;
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;
@@ -394,6 +438,14 @@ get(struct apple80211req *request)
case 103: /* all of it, as a scan's result */
error = state->phase != REDWOOD_STA_JOINED ? ENXIO : give_network(request, &state->bss);
break;
+ case 2: { /* how it was joined: open system, then WPA2 with a passphrase */
+ struct {
+ uint32_t version, lower, upper, extended;
+ } answer = { .version = 1, .lower = 1, .upper = 8 };
+
+ error = state->phase != REDWOOD_STA_JOINED ? ENXIO : give(request, &answer, sizeof(answer));
+ break;
+ }
default:
error = EOPNOTSUPP;
break;
@@ -461,10 +513,70 @@ out:
return error;
}
+static int
+set_join(const struct apple80211req *request, char *said, size_t said_size)
+{
+ struct apple80211_assoc *asked;
+ struct redwood_sta_join *what;
+ int error;
+
+ if (request->req_len < offsetof(struct apple80211_assoc, rest)) {
+ return EINVAL;
+ }
+ asked = kalloc_data(sizeof(*asked), Z_WAITOK | Z_ZERO);
+ what = kalloc_data(sizeof(*what), Z_WAITOK | Z_ZERO);
+ if (asked == NULL || what == NULL || (error = copyin(request->req_data, asked, offsetof(struct apple80211_assoc, rest))) != 0) {
+ error = asked == NULL || what == NULL ? ENOMEM : error;
+ goto out;
+ }
+ /* (lengths and kinds only: the name, the access point and the key stay out of the log) */
+ snprintf(said, said_size, " (a join: a name of %u bytes, %s access point, authentication %#x/%#x, a key of %u bytes of kind %u)",
+ asked->ssid_length, asked->bssid[0] | asked->bssid[1] | asked->bssid[2] | asked->bssid[3] | asked->bssid[4] |
+ asked->bssid[5] ? "a given" : "any", asked->auth_lower, asked->auth_upper, asked->key_length, asked->key_cipher);
+ if (asked->ssid_length == 0 || asked->ssid_length > sizeof(what->ssid)) {
+ error = EINVAL;
+ goto out;
+ }
+ what->ssid_length = (uint8_t)asked->ssid_length;
+ memcpy(what->ssid, asked->ssid, asked->ssid_length);
+ memcpy(what->bssid, asked->bssid, sizeof(what->bssid));
+ if (asked->key_length == 0) {
+ what->security = REDWOOD_STA_OPEN;
+ } else if (asked->key_cipher == CIPHER_PASSPHRASE && asked->key_length >= 8 && asked->key_length <= 63) {
+ what->security = REDWOOD_STA_WPA2_PSK;
+ what->passphrase_length = (uint8_t)asked->key_length;
+ memcpy(what->passphrase, asked->key, asked->key_length);
+ } else if (asked->key_cipher == CIPHER_PMK && asked->key_length == sizeof(what->pmk)) {
+ what->security = REDWOOD_STA_WPA2_PSK;
+ memcpy(what->pmk, asked->key, sizeof(what->pmk));
+ } else {
+ error = EINVAL;
+ goto out;
+ }
+ lck_mtx_lock(&apple80211_lock);
+ join_result = 0;
+ lck_mtx_unlock(&apple80211_lock);
+ error = redwood_sta_ask_join(what);
+out:
+ if (asked != NULL) {
+ memset_s(asked, sizeof(*asked), 0, sizeof(*asked));
+ kfree_data(asked, sizeof(*asked));
+ }
+ if (what != NULL) {
+ memset_s(what, sizeof(*what), 0, sizeof(*what));
+ 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 20:
+ return set_join(request, said, said_size);
+ case 22: /* leave the network */
+ return redwood_sta_ask_leave();
case 19: { /* the radio's power */
struct {
uint32_t version, radios, state[4];
@@ -525,13 +637,27 @@ redwood_apple80211_event(enum redwood_sta_event event, int status)
post(EVENT_SCAN_DONE, NULL, 0);
break;
case REDWOOD_STA_JOIN_DONE:
+ lck_mtx_lock(&apple80211_lock);
+ join_result = status == 0 ? 1 : status == EAUTH ? 21 : status == ETIMEDOUT ? 9 : 2;
+ lck_mtx_unlock(&apple80211_lock);
+ post(EVENT_ASSOC_DONE, NULL, 0);
break;
- case REDWOOD_STA_LINK:
+ case REDWOOD_STA_LINK: {
+ struct apple80211_link_changed link = { .down = status != 1, .involuntary = status != 1 && status != 0,
+ .reason = status != 1 && status != 0 ? 4 : 0 }; /* (4: gone, not asked) */
+ struct redwood_sta_state *state = kalloc_data(sizeof(*state), Z_WAITOK | Z_ZERO);
+
+ if (state != NULL) {
+ redwood_sta_state(state);
+ link.rssi = status == 1 ? state->bss.rssi : 0;
+ kfree_data(state, sizeof(*state));
+ }
post(EVENT_SSID_CHANGED, NULL, 0);
post(EVENT_BSSID_CHANGED, NULL, 0);
- post(EVENT_LINK_CHANGED, NULL, 0);
+ post(EVENT_LINK_CHANGED, &link, sizeof(link));
break;
}
+ }
}
/* ---- the requests as they arrive --------------------------------------------------------------------- */
diff --git a/xnu/files/bsd/dev/redwood_net.c b/xnu/files/bsd/dev/redwood_net.c
index 50728c4..27a8e03 100644
--- a/xnu/files/bsd/dev/redwood_net.c
+++ b/xnu/files/bsd/dev/redwood_net.c
@@ -32,7 +32,7 @@
#include <sys/sockio.h>
#include <sys/systm.h>
-extern void RedwoodWLANStart(const char *interface); /* iokit/Kernel/RedwoodWLAN.cpp */
+extern void RedwoodWLANStart(const char *interface, const uint8_t *address); /* iokit/Kernel/RedwoodWLAN.cpp */
static LCK_GRP_DECLARE(net_lck_grp, "redwood-net");
static LCK_MTX_DECLARE(net_tx_lock, &net_lck_grp);
@@ -357,7 +357,7 @@ redwood_net_attach(const struct redwood_net_link *link)
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");
+ RedwoodWLANStart("en0", address);
} 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");
diff --git a/xnu/files/bsd/dev/redwood_sta.c b/xnu/files/bsd/dev/redwood_sta.c
index a8d4b33..f4e0490 100644
--- a/xnu/files/bsd/dev/redwood_sta.c
+++ b/xnu/files/bsd/dev/redwood_sta.c
@@ -11,6 +11,11 @@
*
* 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.
+ *
+ * The network the kernel was given in a file is a standing request: joined at the start, and
+ * again whenever the radio is turned back on (Settings' switch), until somebody asks for
+ * another network -- as iOS itself rejoins the networks it knows. If that other network cannot
+ * be joined (a wrong passphrase), the standing one is joined again.
*/
#include <kern/kalloc.h>
#include <kern/locks.h>
@@ -41,6 +46,8 @@ static bool sta_on; /* the radio's power, as last as
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_join standing; /* the network joined whenever the radio comes on (ssid_length 0: none) */
+static struct redwood_sta_join fallback; /* ... as it was before a join that has not come through yet */
static struct redwood_sta_bss *heard; /* by the last scan that came to an end */
static unsigned heard_count;
@@ -96,8 +103,25 @@ sta_runs(__unused void *parameter, __unused wait_result_t result)
lck_mtx_unlock(&sta_lock);
if (power) {
+ struct redwood_sta_state *state = kalloc_data(sizeof(*state), Z_WAITOK | Z_ZERO);
+ bool was_joined = false;
+
+ if (state != NULL) {
+ ops->state(state);
+ was_joined = state->phase == REDWOOD_STA_JOINED;
+ kfree_data(state, sizeof(*state));
+ }
error = ops->power(power_on);
+ if (!power_on && was_joined) {
+ redwood_apple80211_event(REDWOOD_STA_LINK, 0);
+ }
redwood_apple80211_event(REDWOOD_STA_POWER, error == 0 ? power_on : !power_on);
+ lck_mtx_lock(&sta_lock);
+ if (error == 0 && power_on && standing.ssid_length != 0 && !asked_join) {
+ asked_join_what = standing;
+ asked_join = true;
+ }
+ lck_mtx_unlock(&sta_lock);
} else if (leave) {
ops->leave();
redwood_apple80211_event(REDWOOD_STA_LINK, 0);
@@ -108,6 +132,14 @@ sta_runs(__unused void *parameter, __unused wait_result_t result)
if (error == 0) {
redwood_apple80211_event(REDWOOD_STA_LINK, 1);
}
+ /* a join that did not come through (a wrong passphrase) leaves things as they were: the standing network again */
+ lck_mtx_lock(&sta_lock);
+ if (error != 0 && fallback.ssid_length != 0 && !asked_join && !asked_leave && !asked_power) {
+ standing = asked_join_what = fallback;
+ asked_join = true;
+ }
+ bzero(&fallback, sizeof(fallback));
+ lck_mtx_unlock(&sta_lock);
} else if (do_scan) {
error = ops->scan(&scan);
lck_mtx_lock(&sta_lock);
@@ -168,9 +200,9 @@ redwood_sta_attach(const struct redwood_sta_ops *ops)
}
void
-redwood_sta_lost(__unused int error)
+redwood_sta_lost(int error)
{
- redwood_apple80211_event(REDWOOD_STA_LINK, 0);
+ redwood_apple80211_event(REDWOOD_STA_LINK, error != 0 ? error : ECONNRESET);
}
/* ---- who wants a network ------------------------------------------------------------------------------- */
@@ -232,6 +264,19 @@ redwood_sta_ask_scan(const struct redwood_sta_scan *what)
return 0;
}
+int
+redwood_sta_ask_join_standing(const struct redwood_sta_join *what)
+{
+ int error = redwood_sta_ask_join(what);
+
+ lck_mtx_lock(&sta_lock);
+ if (error == 0) {
+ standing = *what;
+ }
+ lck_mtx_unlock(&sta_lock);
+ return error;
+}
+
int
redwood_sta_ask_join(const struct redwood_sta_join *what)
{
@@ -240,6 +285,10 @@ redwood_sta_ask_join(const struct redwood_sta_join *what)
lck_mtx_unlock(&sta_lock);
return sta_ops == NULL ? ENXIO : ENETDOWN;
}
+ if (standing.ssid_length != 0) {
+ fallback = standing;
+ }
+ bzero(&standing, sizeof(standing)); /* (whoever asks for a network now has the say) */
asked_join_what = *what;
asked_join = true;
asked_leave = false;
@@ -259,6 +308,7 @@ redwood_sta_ask_leave(void)
asked_leave = true;
asked_join = false;
bzero(&asked_join_what, sizeof(asked_join_what));
+ bzero(&fallback, sizeof(fallback));
lck_mtx_unlock(&sta_lock);
thread_wakeup((event_t)&sta_ops);
return 0;
diff --git a/xnu/files/bsd/dev/redwood_wifi.c b/xnu/files/bsd/dev/redwood_wifi.c
index 256e3b4..0890565 100644
--- a/xnu/files/bsd/dev/redwood_wifi.c
+++ b/xnu/files/bsd/dev/redwood_wifi.c
@@ -128,6 +128,7 @@
* 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_file=0 with wifi=1: the network of fw/network is not joined at the start
* 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
@@ -4099,12 +4100,17 @@ join_given(uint64_t began)
struct redwood_sta_state *state;
unsigned name_length = sizeof(what.ssid), passphrase_length = sizeof(what.passphrase);
uint64_t size = 0;
+ uint32_t given = 1;
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;
}
+ if (PE_parse_boot_argn("wifi_file", &given, sizeof(given)) && given == 0) {
+ tell("wifi: the network of the file is not joined at the start (wifi_file=0): 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");
@@ -4113,7 +4119,7 @@ join_given(uint64_t began)
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);
+ error = redwood_sta_ask_join_standing(&what);
bzero(&what, sizeof(what));
for (unsigned waited = 0; error == 0 && redwood_sta_busy() && waited < 300; waited++) {
sleep_ms(100);
diff --git a/xnu/files/bsd/sys/redwood_sta.h b/xnu/files/bsd/sys/redwood_sta.h
index 5a8d955..c5ed067 100644
--- a/xnu/files/bsd/sys/redwood_sta.h
+++ b/xnu/files/bsd/sys/redwood_sta.h
@@ -89,7 +89,8 @@ 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 */
+ REDWOOD_STA_LINK, /* status: 1 a network is joined, 0 it has been left when asked,
+ * an errno: it was lost (the access point showed us the door) */
};
#ifdef KERNEL
@@ -102,6 +103,8 @@ 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);
+/* ... and joined again whenever the radio is turned on, until some other network is asked for */
+int redwood_sta_ask_join_standing(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);
diff --git a/xnu/files/iokit/Kernel/RedwoodWLAN.cpp b/xnu/files/iokit/Kernel/RedwoodWLAN.cpp
index c0676fa..89d8840 100644
--- a/xnu/files/iokit/Kernel/RedwoodWLAN.cpp
+++ b/xnu/files/iokit/Kernel/RedwoodWLAN.cpp
@@ -1,23 +1,52 @@
/*
- * RedwoodWLAN: the registry entry by which iOS finds the Wi-Fi interface.
+ * RedwoodWLAN: the registry entries 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.
+ * it of its own; iOS looks for two, as IO80211Family would have made them:
+ *
+ * - 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. The service 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.
+ * - SystemConfiguration (SCNetworkInterfaceCopyAll) lists the network interfaces it finds as
+ * objects of the class IONetworkInterface, and calls one a Wi-Fi interface when its parent
+ * is of the class IO80211Controller; type, unit, name and built-in-ness are properties of
+ * the interface, the hardware address one of the controller. configd makes a network
+ * service (DHCP and the rest) for an interface it has listed, and only an interface with a
+ * service can be the one the system routes through -- which wifid waits for after a join
+ * ("failed to become routable interface") before Settings ticks the network.
+ *
+ * So: a controller of the class IO80211Controller under the platform, and below it one object
+ * that is both, an IONetworkInterface with wifid's properties. Both classes are ours, named as
+ * IO80211Family and IONetworkingFamily name theirs; neither has anything but properties.
*/
#include <IOKit/IOLib.h>
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/IOService.h>
#include <IOKit/IOUserClient.h>
+#include <libkern/c++/OSData.h>
+#include <libkern/c++/OSNumber.h>
+
+extern "C" void RedwoodWLANStart(const char * interface, const uint8_t * address);
+
+class IO80211Controller : public IOService
+{
+ OSDeclareDefaultStructors(IO80211Controller);
+};
-extern "C" void RedwoodWLANStart(const char * interface);
+OSDefineMetaClassAndStructors(IO80211Controller, IOService);
-class RedwoodWLAN : public IOService
+class IONetworkInterface : public IOService
+{
+ OSDeclareDefaultStructors(IONetworkInterface);
+};
+
+OSDefineMetaClassAndStructors(IONetworkInterface, IOService);
+
+class RedwoodWLAN : public IONetworkInterface
{
OSDeclareDefaultStructors(RedwoodWLAN);
@@ -26,7 +55,7 @@ public:
IOUserClient ** handler) APPLE_KEXT_OVERRIDE;
};
-OSDefineMetaClassAndStructors(RedwoodWLAN, IOService);
+OSDefineMetaClassAndStructors(RedwoodWLAN, IONetworkInterface);
/* There is none (see the top); that somebody asked shows that the service was found. */
IOReturn
@@ -40,26 +69,69 @@ RedwoodWLAN::newUserClient(task_t owningTask, void * securityID, UInt32 type, OS
return kIOReturnUnsupported;
}
+/* attach, start, register: the service, or NULL */
+static IOService *
+publish(IOService * service, IOService * provider, const char * name)
+{
+ if (service == NULL || !service->attach(provider)) {
+ OSSafeReleaseNULL(service);
+ return NULL;
+ }
+ service->setName(name);
+ if (!service->start(provider)) {
+ service->detach(provider);
+ service->release();
+ return NULL;
+ }
+ service->registerService();
+ return service;
+}
+
/* Once, when the interface of a radio exists. */
void
-RedwoodWLANStart(const char * interface)
+RedwoodWLANStart(const char * interface, const uint8_t * address)
{
- IOService * provider = IOService::getPlatform();
+ IOService * platform = IOService::getPlatform();
+ IO80211Controller * controller = OSTypeAlloc(IO80211Controller);
RedwoodWLAN * wlan = OSTypeAlloc(RedwoodWLAN);
+ OSData * mac;
+ OSNumber * number;
- if (wlan == NULL || provider == NULL || !wlan->init() || !wlan->attach(provider)) {
+ if (platform == NULL || controller == NULL || wlan == NULL || !controller->init() || !wlan->init()) {
+ OSSafeReleaseNULL(controller);
OSSafeReleaseNULL(wlan);
- IOLog("RedwoodWLAN: cannot create the service\n");
+ IOLog("RedwoodWLAN: cannot create the services\n");
+ return;
+ }
+ if ((mac = OSData::withBytes(address, 6)) != NULL) {
+ controller->setProperty("IOMACAddress", mac);
+ mac->release();
+ }
+ controller->setProperty("IOBuiltin", true);
+ if ((controller = (IO80211Controller *) publish(controller, platform, "RedwoodWLANController")) == NULL) {
+ wlan->release();
+ IOLog("RedwoodWLAN: the controller did not start\n");
return;
}
- wlan->setName("RedwoodWLAN");
+
wlan->setProperty("IOInterfaceName", interface);
+ wlan->setProperty("BSD Name", interface);
+ wlan->setProperty("IOInterfaceNamePrefix", "en");
+ if ((number = OSNumber::withNumber(6ULL, 32)) != NULL) { /* IFT_ETHER */
+ wlan->setProperty("IOInterfaceType", number);
+ number->release();
+ }
+ if ((number = OSNumber::withNumber((unsigned long long) (interface[2] - '0'), 32)) != NULL) {
+ wlan->setProperty("IOInterfaceUnit", number);
+ number->release();
+ }
+ wlan->setProperty("IOBuiltin", true);
+ wlan->setProperty("IOPrimaryInterface", true);
wlan->setProperty("IO80211InterfaceRole", "Infrastructure");
- if (!wlan->start(provider)) {
- wlan->detach(provider);
+ if (publish(wlan, controller, "RedwoodWLAN") == NULL) {
IOLog("RedwoodWLAN: the service did not start\n");
} else {
- wlan->registerService();
+ wlan->release();
}
- wlan->release();
+ controller->release();
}