Skip to content

Instantly share code, notes, and snippets.

@Kansattica
Last active March 14, 2025 08:54
Show Gist options
  • Save Kansattica/c886b0f21f90a0bdc7ace439d256f225 to your computer and use it in GitHub Desktop.
Save Kansattica/c886b0f21f90a0bdc7ace439d256f225 to your computer and use it in GitHub Desktop.
more working nixpackage for unlocking cellular modem on nixos
networking.networkmanager.fccUnlockScripts = [
{id = "8086:7560"; path = "${pkgs.lenovo-wwan-unlock}/bin/fcc_unlock.sh";}
];
Sometimes modemmanager times out while running the unlock script and I have to run it manually with:
sudo /etc/ModemManager/fcc-unlock.d/8086\:7560 whatever wwan0 wwan0at0 wwan0at1 wwam0mbim0
which seems to work
{ stdenvNoCC, fetchurl, lib }:
stdenvNoCC.mkDerivation rec {
#name = "lenovo-wwan-unlock-${version}";
pname = "lenovo-wwan-unlock-easy";
version = "2.0.0";
src = ./wwan-unlock.sh;
# I like to keep the file locally in my repo, but you can also download it from here
# this PR, specifically: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/1141/diffs?commit_id=2734ac25191264e6d786af8a9577fb51519cb846
/*src = fetchurl {
url = "https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/raw/2734ac25191264e6d786af8a9577fb51519cb846/data/dispatcher-fcc-unlock/8086";
hash = "sha256-QuAC2a0renRZQsZvWfTEE9a/Pj6G+ZhGEmYtVagaurE=";
};*/
dontUnpack = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin/
cp -v $src $out/bin/fcc_unlock.sh
chmod +x $out/bin/fcc_unlock.sh
patchShebangs $out/bin/fcc_unlock.sh
runHook postInstall
'';
meta = with lib; {
homepage = "https://gist.github.com/BohdanTkachenko/3f852c352cb2e02cdcbb47419e2fcc74";
description = "Easy unlock for Lenovo PC wwan.";
license = licenses.cc0;
platforms = platforms.linux;
maintainers = [ "The Internet's Beloved Princess Grace" ];
};
}
# add the package to nixpkgs in an overlay
modules = [
({ config, pkgs, ... }: { nixpkgs.overlays =
[
(self: super: {
lenovo-wwan-unlock = super.callPackage ./easy-lenovo-wwan-unlock.nix { };
}
)
]
@ndom91
Copy link

ndom91 commented Jul 5, 2024

Hey what do you mean by "not quite working.." exactly?

@Kansattica
Copy link
Author

So, the Lenovo binaries... run, but they refuse to work if you're in the United States or something, but the modemmanager folks have a shell script that does work (and is a lot easier to get going). I've updated this gist with my current setup. Hope it helps!

@ndom91
Copy link

ndom91 commented Jul 6, 2024

Hmm okay, stupid question, but do you need to do this FCC unlock AT command dance for SKU's / modems bought outside the US? I have a 12thgen X1 Carbon with a Quectel RM520N-GL that I bought in Germany 🤔

@Kansattica
Copy link
Author

I couldn't tell you- I'm using a US computer in the US. You can try connecting with modemmanager/modem-manager-gui (possibly after running sudo mmcli --set-logging=debug) and watch journalctl to see what it says. Worst case scenario, the modem gets in a weird state until you reboot.

@ndom91
Copy link

ndom91 commented Jul 6, 2024

Okay thanks for the quick response. Unfortunately I'm still having issues getting the device to be detected at all under kernel 6.9.7. I've enabled a few kernel modules by hand (wwan, mhi, mhi_pci_generic, usbserial, etc. etc.) and at first nothing at all related to this device was appearing in lspci or lsusb. However, after enabling the wwan_hwsim kernel module, I did get /dev/wwan0at0 and /dev/wwan0at1 devices to show up under /dev/*. Unfortunatley there's no other ttyUSB* or qmi or cdc device available, and as such modem manager (neither gui nor the cli (mmcli)) detect anything :(. There are no related messages under dmesg during boot either. I'm slowly getting to the point where I don't think this is gonna work haha. Although I did find messages on the kernel mailinglist that this device should be supported as of 6.6. They even mentioned device Id's for a "lenovo variant" 🤷

I tried passing these devices to the fcc_unlock.sh script so that it sends those AT commands there, but it always responds with "Failed to get challenge..", i.e. the initial command doesn't return any response whatsoever

@Kansattica
Copy link
Author

Annoying. Mine looks like it's using the iosm kernel module if that helps.

My relevant devices are (according to mmcli): wwan0 (net), wwan0at0 (at), wwan0at1 (at), wwan0mbim0 (mbim), no qmi or cdc that I know of.

@ndom91
Copy link

ndom91 commented Jul 6, 2024

After messing with these kernel modules for days, I decided to open up the laptop and confirm which modem model # was even in here. You should have seen my face when I noticed the M.2 slot was empty 😂 🤦

Who sells a new laptop SKU with "... 5G" in the title, a nano SIM slot in the side of the chassis, but then doesn't include the modem?! Haha

Oh well, mystery solved for now at least. Thanks!

@Kansattica
Copy link
Author

Oh, yep, that'd do it. Best of luck!

@ViBE-HU
Copy link

ViBE-HU commented Feb 20, 2025

i have a T14s Gen 1 with an L860-GL (FRU 01AX796). is this a solution for that modem? if yes how can i use it? i'm using ubuntu 24.04.

@mguerrajordao
Copy link

Thank you for this.
Using it on Lenovo T14s Gen 4 with L860-GL (Intel XMM7560) in Hong Kong. Managed to get running under NixOS with the package overlay. I also download as suggested the unlock script from the gist https://gist.github.com/BohdanTkachenko/3f852c352cb2e02cdcbb47419e2fcc74 directly as suggested on the package derivation.
Still have issue with first boots the ModemManager systemd service is not auto-started and NetworkManager doesn't show the MobileBroadband, but i guess that is down to the other issue, as before the fcc-unlock apply script this was also happening.
Tested with 4G sim card and works fine. Didn't pursue very far with the other routes with using the Lenovo binary, after discovering this. Thank you for this.

@Kansattica
Copy link
Author

Thank you for this. Using it on Lenovo T14s Gen 4 with L860-GL (Intel XMM7560) in Hong Kong. Managed to get running under NixOS with the package overlay. I also download as suggested the unlock script from the gist https://gist.github.com/BohdanTkachenko/3f852c352cb2e02cdcbb47419e2fcc74 directly as suggested on the package derivation. Still have issue with first boots the ModemManager systemd service is not auto-started and NetworkManager doesn't show the MobileBroadband, but i guess that is down to the other issue, as before the fcc-unlock apply script this was also happening. Tested with 4G sim card and works fine. Didn't pursue very far with the other routes with using the Lenovo binary, after discovering this. Thank you for this.

Yeah, I find myself having to run mmcli -m any --simple-connect="apn=whatever,someothernonsense" to get networkmanager to get into gear, but it works fine after that. Happy to help!

@Kansattica
Copy link
Author

i have a T14s Gen 1 with an L860-GL (FRU 01AX796). is this a solution for that modem? if yes how can i use it? i'm using ubuntu 24.04.

I don't know, I don't have access to that modem. The instructions from https://gist.github.com/BohdanTkachenko/3f852c352cb2e02cdcbb47419e2fcc74 might help. You'll want to replace the PCI ID with the one for your modem- run lspci -nn and note the pair of numbers in square brackets after your modem. It's 8086:7560 for my modem, yours may vary. You'll want to make sure the file you put in /etc/ModemManager/fcc-unlock.d/ is named after your device's PCI ID. May or may not work, I'm just offering shots in the dark over the internet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment