Jump to content

Setup BCM43225 and customise WiFi key switch via DSDT


corsaro
 Share

13 posts in this topic

Recommended Posts

Hi,

I'm trying to customise the WiFi toggle touch key that my HP Pavilion dv6-2193el (BCM43225 wifi controller with RehabMan's FakePCIID_Broadcom_WiFi kext) uses to enable/disable WiFi on OS X 10.11.5.

 

The problem is that the default behaviour of the switch is to disconnect from my current ssid and never reconnect to it. So I proceeded on patching my DSDT.

 

By using RehabMan's ACPIDebug, I found that this button triggers EC Query _Q15 event, so I proceeded to edit that Method.

 

Here is the original code extracted by Clover:

Method (_Q15, 0, NotSerialized)  // _Qxx: EC Query
{
    Store (0x15, P80H)
    Store (CMSR (0x49), WAB1)
    If (And (WAB1, 0x08))
    {
        And (WAB1, 0xF7, WAB1)
        Store (Zero, RFLE)
    }
    Else
    {
        Or (WAB1, 0x08, WAB1)
        If (LEqual (WAOK, Zero))
        {
            If (And (WBLC, One))
            {
                Store (One, RFLE)
            }
        }
    }

    If (LEqual (WAOK, Zero))
    {
        If (And (WAB1, 0x0A))
        {
            Or (WAB1, 0x02, WAB1)
            Or (WAB2, 0x02, WAB2)
            Or (WAB3, 0x02, WAB3)
        }
        Else
        {
            Or (WAB1, 0x0A, WAB1)
            Or (WAB2, 0x0A, WAB2)
            Or (WAB3, 0x0A, WAB3)
        }

        Or (WAB5, 0x08, WAB5)
        Or (WAB4, 0x08, WAB4)
    }
    Else
    {
        Store (0x07, WAB5)
        Store (Zero, WAB4)
        If (And (WAB1, 0x02))
        {
            Or (WAB4, One, WAB4)
        }

        If (And (WAB2, 0x02))
        {
            Or (WAB4, 0x02, WAB4)
        }

        If (And (WAB3, 0x02))
        {
            Or (WAB4, 0x04, WAB4)
        }
    }

    TRAP (TRTI, 0x20)
    If (LEqual (WAOK, One))
    {
        If (WA40)
        {
            Store (0x1B, ^^^^WMID.WEID)
        }
        Else
        {
            Store (0x05, ^^^^WMID.WEID)
        }

        Store (Zero, ^^^^WMID.WMED)
        Notify (WMID, 0x80)
    }
} 

I'm a newbie on DSDTs so what I thought was to provide a nice way to trigger a custom global service on OS X that could enable/disable wifi via networksetup. So I looked inside RehabMan's VoodooPS2Keyboard kext (I use it to enable and customise my keyboard) source code and I found a way to trigger the F13 button, in order to provide to Settings a button to bind my service.

 

First of all I replaced the Method with this code, just to try:

Method (_Q15, 0, NotSerialized) // WiFi Toggle
{
    Notify (PS2M, 0x0478) // Note: I have either PS2M and PS2K, but with PS2M brightness keys work
}

and I made a service (shell script) via Automator that could switch wifi, binding the F13 key (I think OS X doesn't use it(?)) to it through Settings app

if [ "$(networksetup -getairportpower en1 | grep -o 'On\|Off')" == "On"]; then
    networksetup -setairportpower en1 Off
else
    networksetup -setairportpower en1 On
fi

pretty self-explanatory.

Note: I use en1 because en0 is my ethernet card

 

That worked!... almost.

 

I lost the feature that the button's LED turns Blue when the connection is active or Red when it is inactive.

I tried to make numerous edits on the Method naïvely and tried to disable the default behaviour of disconnecting from the network. I didn't get the correct solution. I noticed that the code has three IF statements, so one of that controls the LED state, but I can't find the right statement neither I find the correct solution of throwing the PS2M event when there is other code (OS X throws me an error sound and I cannot understand why, neither system.log is reporting anything - when there is only the Notify call, the F13 key event and service are nominal)

 

My question: one of you experts could gently help me on understanding this code and make a functional and (possibly) optimised way of doing this? I'm sure that my method of calling a service via PS2 key event is not really the best one.

 

###

 

Another problem: during these numerous tests and reboots my WiFi controller stopped working. On OS X it says that it is Off and I can't turn it on. I tried to reinstall the kext, use the original DSDT, reinstall OS X... but nothing happened.

 

System.log reports this messages at every system startup:

kernel: AirPort: Link Down on en1. Reason 8 (Disassociated because station leaving).
kernel: en1::IO80211Interface::postMessage bssid changed
UserEventAgent: Captive: CNPluginHandler en1: Inactive
airportd: airportdProcessDLILEvent: en1 attached (down)

I tried to boot with Fedora (Linux) and WiFi doesn't work, same thing: it says that it's off and I can't turn it on.

 

My question: Did I "fried" my WiFi?

 

Solution: EC reset

 

###

Footnotes:

As always, English is not my madre lingua. Hope to be clear.

 

Thanks for your patience.

Edited by corsaro
Link to comment
Share on other sites

Dear RehabMan,

thanks for your quick response.

 

WiFi now works (I found a new "EFI" menu on HP and selected "Reset System" - the "classic" EC Reset method didn't work).

 

For the DSDT you are right, RFLE controls the state of the LED. Now the LED works.

But as I said before, when I touch the button, OS X throws me an error sound and the service is not triggered. System.log reports nothing about it.

 

This is the updated code:

Method (_Q15, 0, NotSerialized)  // WiFi Toggle
{
    Notify (PS2M, 0x0478)
    //Store (0x15, P80H)
    //Store (CMSR (0x49), WAB1)
    If (And (WAB1, 0x08))
    {
        And (WAB1, 0xF7, WAB1) // is this useful ?
        Store (Zero, RFLE)
    }
    Else
    {
        Or (WAB1, 0x08, WAB1) // is this useful ?
        If (LEqual (WAOK, Zero))
        {
            If (And (WBLC, One))
            {
                Store (One, RFLE)
            }
        }
    }
}
Link to comment
Share on other sites

 

Dear RehabMan,

thanks for your quick response.

 

WiFi now works (I found a new "EFI" menu on HP and selected "Reset System" - the "classic" EC Reset method didn't work).

 

For the DSDT you are right, RFLE controls the state of the LED. Now the LED works.

But as I said before, when I touch the button, OS X throws me an error sound and the service is not triggered. System.log reports nothing about it.

 

This is the updated code:

Method (_Q15, 0, NotSerialized)  // WiFi Toggle
{
    Notify (PS2M, 0x0478)
    //Store (0x15, P80H)
    //Store (CMSR (0x49), WAB1)
    If (And (WAB1, 0x08))
    {
        And (WAB1, 0xF7, WAB1) // is this useful ?
        Store (Zero, RFLE)
    }
    Else
    {
        Or (WAB1, 0x08, WAB1) // is this useful ?
        If (LEqual (WAOK, Zero))
        {
            If (And (WBLC, One))
            {
                Store (One, RFLE)
            }
        }
    }
}

 

I don't think 0x0478 makes any sense...

 

From ApplePS2ToADBMap.h:

 

0x68,   // 78  Keyboard Lang 3 (Japanese Katakana)

 

You were trying to send F13, right?....

 

 

0x69,   // 64  F13
Link to comment
Share on other sites

 

I don't think 0x0478 makes any sense...

 

From ApplePS2ToADBMap.h:

0x68,   // 78  Keyboard Lang 3 (Japanese Katakana)

You were trying to send F13, right?....

0x69,   // 64  F13

 

 

Oops, I forgot to say that I don't directly use ADB 0x69 but instead I'm calling e078 and then rebind it to 69 via VoodooPS2Keyboard kext.

 

This is because I don't know how to call from DSDT ADB 0x69 / how to calculate the hex to insert to the DSDT.

 

I tried 0x0464, 0x0064, 0x64, 0x0464 (via P2K, just because I don't know what's the difference between PS2K and PS2M) but nothing, I learned that '04' is related to '0e'.

Lastly I tried 0x0164 and that threw 64=69 (yay!), but OS X threw me error sound in repetition. Tried 0x0364 and OS X still threw me the error sound once.

 

Can you confirm that OS X doesn't use F13 key in some way? Maybe it triggers some function that is unavailable to me (although OS X should start the binded service)? Is there a known way to calculate the first 2 figures of the hex code? It's kinda weird to just edit here and there and reboot the system without knowing how to manage "the matter". Maybe I'm too lazy to continue googling in search for a documentation (I found useful only your posts and blog articles)

Link to comment
Share on other sites

Oops, I forgot to say that I don't directly use ADB 0x69 but instead I'm calling e078 and then rebind it to 69 via VoodooPS2Keyboard kext.

 

This is because I don't know how to call from DSDT ADB 0x69 / how to calculate the hex to insert to the DSDT.

 

I tried 0x0464, 0x0064, 0x64, 0x0464 (via P2K, just because I don't know what's the difference between PS2K and PS2M) but nothing, I learned that '04' is related to '0e'.

Lastly I tried 0x0164 and that threw 64=69 (yay!), but OS X threw me error sound in repetition. Tried 0x0364 and OS X still threw me the error sound once.

 

Can you confirm that OS X doesn't use F13 key in some way? Maybe it triggers some function that is unavailable to me (although OS X should start the binded service)? Is there a known way to calculate the first 2 figures of the hex code? It's kinda weird to just edit here and there and reboot the system without knowing how to manage "the matter". Maybe I'm too lazy to continue googling in search for a documentation (I found useful only your posts and blog articles)

 

You should use the debug VoodooPS2Controller.kext (or 'ioio -s ApplePS2Keyboard LogScanCodes 1') to verify your translations are happening as you expect.

Link to comment
Share on other sites

You should use the debug VoodooPS2Controller.kext (or 'ioio -s ApplePS2Keyboard LogScanCodes 1') to verify your translations are happening as you expect.

 That's what I did. Without it I couldn't verify keycodes and so describe this situation to you :-)

 

So I understand that this "brute forcing" is the only way. I can confirm that with 0x0164 and 0x0364 OS X throws me respectively error sound in repetition and error sound once and VoodooPS2Keyboard says respectively 64=69 and 64=69. That's F13 as I'm expecting.

 

UPDATE:

Tried with 0x036b (F20) and same thing, error sound but VoodooPS2Keyboard logs the key event.

Link to comment
Share on other sites

 That's what I did. Without it I couldn't verify keycodes and so describe this situation to you :-)

 

So I understand that this "brute forcing" is the only way. I can confirm that with 0x0164 and 0x0364 OS X throws me respectively error sound in repetition and error sound once and VoodooPS2Keyboard says respectively 64=69 and 64=69. That's F13 as I'm expecting.

 

UPDATE:

Tried with 0x036b (F20) and same thing, error sound but VoodooPS2Keyboard logs the key event.

 

Something must be wrong with the software at the other end (eg. not grabbing the keystroke).

Link to comment
Share on other sites

Something must be wrong with the software at the other end (eg. not grabbing the keystroke).

 

So what could be the solution? I can't think about another approach that involves no key events, or I'm too naive to think with a low-level mind. Maybe I have to study and make an ad-hoc kext?

Link to comment
Share on other sites

So what could be the solution? I can't think about another approach that involves no key events, or I'm too naive to think with a low-level mind. Maybe I have to study and make an ad-hoc kext?

 

Verify your key capture/binding method works with an actual key you can press.

Link to comment
Share on other sites

Verify your key capture/binding method works with an actual key you can press.

 

 

I tried to bind the service via CMD+F13 and it worked, although the LED and the key are not properly synchronised. (LED tends to ignore the first tap when the system loads up)

 

UPDATE:

I solved the sync (or I hope so) by placing the Notify call into the IF statement

Method (_Q15, 0, NotSerialized)  // WiFi Toggle
{
    //Store (0x15, P80H)
    //Store (CMSR (0x49), WAB1)
    If (And (WAB1, 0x08))
    {
        And (WAB1, 0xF7, WAB1)
        Store (Zero, RFLE)
        Notify (PS2M, 0x0364)
    }
    Else
    {
        Or (WAB1, 0x08, WAB1)
        If (LEqual (WAOK, Zero))
        {
            If (And (WBLC, One))
            {
                Store (One, RFLE)
                Notify (PS2M, 0x0364)
            }
        }
    }
} 

So now it's almost complete. I noticed that if I use e.g. CTRL+[WiFi Key] the LED doesn't change, but if I use CMD+[WiFi Key] or [WiFi Key] the LED changes. Maybe I can control this input via DSDT?

Edited by corsaro
Link to comment
Share on other sites

Back again.

 

I thought about another way of doing this thing, without PS2 key, and I finished on modifying ACPIDebug.kext to get notification from _Q15 with the new LED state attached, in order to synchronise it with the WiFi card state. The notification is OK and the report of the new state works nominally on system.log.

 

But I'm a newbie and I have one giant problem: how can I control the state of my WiFi card from the kext?

I tried to search around IO80211Family kext and I saw that it's closed source. So bad!

 

Is there a possible solution that I can implement?

 

Greetings.

Link to comment
Share on other sites

Regarding "frying" your Wi-Fi, this happened to me before I knocked off the Wi-Fi toggle in DSDT.

Just switch it on from Windows and reboot.

You might want to have a Windows To Go install on a USB hard drive or something for the purpose, or even an install on a 10 GB partition ...

 

I was thinking ...

Why do you use FakePCIID for injecting your Wi-Fi?

Mine (BCM43324 though) is injected via DSDT in a ARPT device.

A DSDT injection tends to be cleaner than a multitude of kexts ...

Regarding "frying" your Wi-Fi, this happened to me before I knocked off the Wi-Fi toggle in DSDT.

Just switch it on from Windows and reboot.

You might want to have a Windows To Go install on a USB hard drive or something for the purpose, or even an install on a 10 GB partition ...

 

I was thinking ...

Why do you use FakePCIID for injecting your Wi-Fi?

Mine (BCM43324 though) is injected via DSDT in a ARPT device.

A DSDT injection tends to be cleaner than a multitude of kexts ...

 

Did you have any stroke of luck with your red/white Mute button?

Link to comment
Share on other sites

 Share

×
×
  • Create New...