Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inner value of CWPHYMode appears to change between integer and bitflags index between macOS versions #662

Open
keabarnes opened this issue Oct 14, 2024 · 5 comments
Labels
A-framework Affects the framework crates and the translator for them bug Something isn't working

Comments

@keabarnes
Copy link

keabarnes commented Oct 14, 2024

In the code below, the inner value of CWPHYMode which is returned by interface.activePHYMode() differs based on the macOS version.

unsafe {
  let client = CWWiFiClient::sharedWiFiClient();

  let interface = client.interface().unwrap();

  let phy_mode = interface.activePHYMode();
}

From observation I've noticed that

  • on macOS 14.5 the inner value is represented by an integer that maps well to the const ... Self(n) constants on the enum
  • on macOS 15.0 it seems like the value represents the naive conversion from a bitflag to an integer
    • 802.11n is returned as CWPHYMode(16) but should be CWPHYMode(4)
    • 802.11ax is returned as CWPHYMode(64) but should be CWPHYMode(6)

Cargo.toml for context

objc2 = { version = "0.5", features = ["apple"] }
objc2-foundation = { version = "0.2", features = ["apple"] }
objc2-core-wlan = { version = "0.2", features = [
  "CWInterface",
  "CWNetwork",
  "CWWiFiClient",
  "CWChannel",
  "CoreWLANTypes",
] }
@simlay
Copy link
Collaborator

simlay commented Oct 16, 2024

Huh. This is interesting. I ran the example code. I'm on macOS 15 with an 802.11ac network. I get a CWPHYMode(32) when I presume it should be CWPHYMode(5). I get the same incorrect result mentioned above with an 802.11n network.

The mapping looks like:

  • CWPHYMode(4) is returned as CWPHYMode(16)
  • CWPHYMode(5) is returned as CWPHYMode(32)
  • CWPHYMode(6) is returned as CWPHYMode(64).

Looks like the pattern is a bitmask rather than an integer?

@madsmtm
Copy link
Owner

madsmtm commented Oct 21, 2024

I'm still on macOS 14.7, and can't test this in a virtual machine (since the virtual machines don't have WiFi), so could I get one of you to test the following:

  1. RUSTFLAGS="-Clinker-flavor=ld" cargo run (in case this is dependent on the minos/sdk version in the binary)
  2. The equivalent Swift code:
    import CoreWLAN
    
    let client = CWWiFiClient.shared()
    let interface = client.interface()!
    let phy_mode = interface.activePHYMode()
    print(phy_mode.rawValue)

@madsmtm madsmtm added bug Something isn't working A-framework Affects the framework crates and the translator for them labels Oct 21, 2024
@keabarnes
Copy link
Author

keabarnes commented Jan 7, 2025

Sorry for the delay in my response, after running all the variants you asked for above, I only realized that the output had been fixed. I'm not sure if it was in this repo or the underlying framework, but it seems right now right?

I'd appreciate understanding if it was the underlying macOS version so I know to expect incorrect values from a specific version of the OS or of this crate, if you know? I'm now on macOS 15.1.1.

fn main() {
    use objc2_core_wlan::CWWiFiClient;

    unsafe {
        let client = CWWiFiClient::sharedWiFiClient();

        let interface = client.interface().unwrap();

        let phy_mode = interface.activePHYMode();

        println!("{:?}", phy_mode);
    }
}

Without flag:

❯ cargo run --example madsmtm_objc2_issues_662

Compiling ...
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 56s
Running `target/debug/examples/madsmtm_objc2_issues_662`

CWPHYMode(6)

With flag:

❯ RUSTFLAGS="-Clinker-flavor=ld" cargo run --example madsmtm_objc2_issues_662

Compiling ...    
Finished `dev` profile [unoptimized + debuginfo] target(s) in 3m 27s
Running `target/debug/examples/madsmtm_objc2_issues_662`

CWPHYMode(6)

Swift:

import CoreWLAN

let client = CWWiFiClient.shared()
let interface = client.interface()!
let phy_mode = interface.activePHYMode()
print(phy_mode.rawValue)
6
Program ended with exit code: 0

@keabarnes
Copy link
Author

keabarnes commented Jan 7, 2025

Running above Rust code snippet again on macOS 15.0.1 with the same version of objc2-* results in the original CWPHYMode(64) issue, regardless of wether the example was run with the RUSTFLAGS set or not. It seems like this is the an issue with the underlying OS framework, do you have precedent in the codebase to handle things in a specific way given a specific version of the OS?

@madsmtm
Copy link
Owner

madsmtm commented Jan 7, 2025

Running above Rust code snippet again on macOS 15.0.1 with the same version of objc2-* results in the original CWPHYMode(64) issue, regardless of wether the example was run with the RUSTFLAGS set or not.

Damn! Could you check macOS 15.0 and macOS 15.1 too, just to be sure of the full range of (non-beta) versions that this happens on?

It seems like this is the an issue with the underlying OS framework, do you have precedent in the codebase to handle things in a specific way given a specific version of the OS?

Hmm, not really, especially not something like this. But I think you'd be able to handle it with something like:

  1. Modify objc2-core-wlan/translation-config.toml to contain class.CWInterface.methods.activePHYMode.skipped = true, and re-run the header translator (if it's difficult for you to set up, then I can do that part myself).
  2. Add a file that contains something like:
    impl CWInterface {
        #[cfg(feature = "CoreWLANTypes")]
        fn activePHYMode(&self) -> CWPHYMode {
            let inner: CWPHYMode = unsafe { msg_send![self, activePHYMode] };
            // These versions had a bug [explanation]
            if available!(macos = 15.0) && !available!(macos = 15.1) {
                CWPHYMode(inner.0 >> 2)
            } else {
                inner
            }
        }
    }

If it affects CWNetwork::supportsPHYMode too, then something similar should be done there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Affects the framework crates and the translator for them bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants