MSzturc / ThinkpadAssistant

An Assistant Application that allows you to use all your Function Keys on a T-Series Thinkpad Laptop
122 stars 13 forks source link

Ethernet switch #23

Closed EETagent closed 3 years ago

EETagent commented 4 years ago

Since many laptops do not have a Broadcom Wi-Fi card, Wi-Fi does not work. In such cases, it is then required to use Ethernet or the itlwm driver, which also acts as Ethernet. Would there be a possibility to add Ethernet switch to the Thinkpad Assistant? ThinkpadAssistant would then become a real Swiss knife of ThinkPad media keys.

https://github.com/zxystd/itlwm/blob/master/.github/README_en.md

Now, Intel Wi-Fi Cards are finally able to access the Internet!

Don't be misled by Ethernet shown in System Prefs. The reason is that I didn't use Apple's close source IO80211Family but rather spoofed it into Ethernet, just like USB Wi-Fi cards.

MSzturc commented 4 years ago

Have to do a bit research to find a way to disable a wired connection from Swift. If it's possible I will implement it.

MSzturc commented 4 years ago

Found a possible solution here: https://github.com/systemheld/WifiToggle/blob/7a0e60dc9a99204861a5d6d7a07297fffdf973b7/WifiToggle/main.swift

This code could get's the network interface in swift. The problem is that it used references that don't get released which will cause memory leaks.

MSzturc commented 4 years ago

I need a code snippet that is able to activate and deactive wired ethernet on mac properly. The snippet i found are able to deactivate ethernet but reactivating causes problems, like no internet connection or missing smb shares

igorkulman commented 4 years ago

What about shelling out to bash and enabling / disabling the adapter there? I am just not sure how it will handle the need for sudo.

MSzturc commented 4 years ago

That is pretty hard to do under macOS. Thinkpad Assistant runs in a sandbox (like every swift application by default). It's not possible to access resources outside of this sandbox.

EETagent commented 4 years ago

@MSzturc

What about using https://developer.apple.com/documentation/foundation/nsuserunixtask ?

HeliPort is able to switch off itlwm so maybe some symbiosis with it might be possible .

igorkulman commented 4 years ago

@MSzturc

What about using https://developer.apple.com/documentation/foundation/nsuserunixtask ?

HeliPort is able to switch off itlwm so maybe some symbiosis with it might be possible .

HeliPort communicates directly with the itlwm driver via ioctl. So it is not a universal solution.

EETagent commented 4 years ago

https://github.com/usr-sse2/Black80211-Catalina

There is new WIP kernel extension, it cooperate with itlwm and show itself as a Wi-Fi

obrazek

I am gonna test it with ThinkpadAssistant, this progress with Intel Wi-Fi drivers is unbelievable

MSzturc commented 4 years ago

Wow... there is an inner conflict inside me. I want to be part of this awesome change and im too lazy go back to intel since my dw1560 works perfectly.. I guess it's time to spend some money on the T490 ;-)

EETagent commented 4 years ago

Buying Intel is currently not a good idea. Those sweet new 8c ThinkPads with Ryzen 4750U ( Sadly Linux, Win only :( ) and ARM Apple machines behind the corner.

MSzturc commented 4 years ago

I know.. that's why i've still on skylake. Intel is not able to update their architecture and rereleasing the same Processor over and over. I would love to see an Ryzen based Laptop, but i guess this would be a dream that not come true. Do you expect that the first generation of Apple Silicon machines will be able to face current i7 lineup? I mean the IPad Pro is a beast but there is still a gap in benchmark that has to be filled ( esp. for video rendering and gpu intensive tasks )

EETagent commented 4 years ago

Current rumors say that first ARM macOS machine that Apple will release ( Except Mac Mini devkit ) will be 12" MacBook so Apple does not expect high performance too. I do not trust those high Geekbench scores as they represent only short perfomance burst ( Ice Lake MBA ( That one where fan is not connected to the CPU :D ) completely smashes my ThinkPad but long load perfomance is much much lower ) It is a fact though that Skylake is a 5 years old architecture so it would not be that hard for a brand new A14 beast to surpass it. Mobile Zen2 is completely different story though.

williambj1 commented 4 years ago

https://github.com/OpenIntelWireless/HeliPort/commit/fa800fe42b5b83c5e98b29f6fd15549a455c215c

EETagent commented 4 years ago

OpenIntelWireless/HeliPort@fa800fe

Thanks to HeliPort developers, problem with Wi-Fi switch is solved by giving HeliPort toggle service a shortcut in the keyboard settings. Only step missing is to get Ethernet 2 status to display right icon.

Also, Thinkpad Assistant must be disabled so macOS and HeliPort toggle service can intercept F17

MSzturc commented 4 years ago

So we need an toggle switch for wlan inside Thinkpad Assistent ?

EETagent commented 4 years ago

Yes, some menu item like for Caps Lock.

This would be hard to implement though? From what I tested only one from these two ( Thinkpad Assistant, HeliPort toggle service ) is able to intercept given shortcut. Ideally if Wi-Fi toggle would be managed by HeliPort service and Thinkpad Assistant would display right icon relatively to Ethernet 2 status. If using same shortcut for these two would not be possible, ThinkPad Assistant could monitor Ethernet 2 status and show icon on change?

MSzturc commented 4 years ago

Is there a command line command to toggle Heliport?

EETagent commented 4 years ago

Is there a command line command to toggle Heliport?

From what I have read so far, no

I just added a service in HeliPort to toggle WiFi.

After updating the app (remember to install it in Applications) and rebooting, you will find a service named HeliPort: Toggle WiFi in System Preferences > Keyboard > Shortcuts > Services > General, then you can assign a keyboard shortcut for it.

For Fn hotkeys based on EC queries, they are not able to be directly captured by the OS so it is out of the scope of itlwm and HeliPort. Luckily many laptop models send Fn hotkeys via WMI events. I have implemented a WMI driver months ago, with which you don't have to patch your DSDT to convert them to PS/2 key code. Check out the repo here.

MSzturc commented 4 years ago

We could try to call the HeliPort Service from Thinkpad Assistant

Please try following code:

ShortcutMonitor.shared.register(systemPrefsShortcut, withAction: { //startApp(withBundleIdentifier: "com.apple.systempreferences") NSPerformService("HeliPort: Toggle WiFi", nil) })

in ShortcutManager

Does it toggle Heliport when you press F9 ?

EETagent commented 4 years ago

@MSzturc Perfect solution, it works. Now only proper menu item and some way how to reliably track if Ethernet is connected

EETagent commented 4 years ago

@MSzturc

import Foundation
import Network

let heliportMonitor = NWPathMonitor(requiredInterfaceType: .other)

heliportMonitor.pathUpdateHandler = { path in
    if path.status == .satisfied {
        print("We're connected!")
    } else {
        print("No connection.")
    }
}

let queue = DispatchQueue(label: "Monitor")
heliportMonitor.start(queue: queue)

This code is able to successfully detect if Ethernet 2 ( Itlwm ) is connected. .wiredEthernet works too, but there could be collision with real Ethernet interface.

There is also much more complicated solution where en2 could be configured

MSzturc commented 4 years ago

Hey cool, I will have a look at it beginning next week. Thx for your effort

EETagent commented 4 years ago

As AirportItlwm now exists ( Similar to kext above ), I don't think there is need to implement this functionality now.