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

nixos/mbim-network: init #91372

Closed
wants to merge 1 commit into from
Closed

nixos/mbim-network: init #91372

wants to merge 1 commit into from

Conversation

@mdlayher
Copy link
Member

mdlayher commented Jun 23, 2020

Motivation for this change

I'd like to control my Sierra Wireless MC7455 LTE modem in MBIM mode using mbim-network in a native, NixOS-configured way. This PR is loosely based on the configuration of the OpenVPN module which allows for multiple instances to be running.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Here's a dmesg snippet showing the kernel initializing the device:

[matt@routnerr-2:~]$ dmesg | grep cdc
[   10.425295] usbcore: registered new interface driver cdc_ncm
[   10.467144] usbcore: registered new interface driver cdc_wdm
[   10.525180] cdc_mbim 1-1.3:1.12: cdc-wdm0: USB WDM device
[   10.526210] cdc_mbim 1-1.3:1.12 wwan0: register 'cdc_mbim' at usb-0000:00:13.0-1.3, CDC MBIM, 46:56:cd:f5:dc:d6
[   10.526450] usbcore: registered new interface driver cdc_mbim
[   11.315462] cdc_mbim 1-1.3:1.12 wwp0s19u1u3i12: renamed from wwan0

My relevant Nix config for using this device with Project Fi (no authentication, using mbim-proxy by default):

services.mbim-network.devices."/dev/cdc-wdm0".apn = "h2g2";

Starting the systemd unit brings the device up and shows that an IP configuration can be fetched successfully, with a few anonymizations:

Jun 23 14:49:24 routnerr-2 systemd[1]: Starting mbim-network for '/dev/cdc-wdm0'...
Jun 23 14:49:24 routnerr-2 mbim-network[22404]: Loading profile at /nix/store/8352hirv32jh9miadvynq0vm3bkal1vn-mbim-network-dev-cdc-wdm0.conf...
Jun 23 14:49:24 routnerr-2 mbim-network[22404]:     APN: h2g2
Jun 23 14:49:24 routnerr-2 mbim-network[22404]:     APN auth protocol: unset
Jun 23 14:49:24 routnerr-2 mbim-network[22404]:     APN user: unset
Jun 23 14:49:24 routnerr-2 mbim-network[22404]:     APN password: unset
Jun 23 14:49:24 routnerr-2 mbim-network[22404]:     mbim-proxy: yes
Jun 23 14:49:24 routnerr-2 mbim-network[22404]: Querying subscriber ready status 'mbimcli -d /dev/cdc-wdm0 --query-subscriber-ready-status --no-close --device-open-proxy'...
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: [/dev/cdc-wdm0] Subscriber ready status retrieved: Ready state: 'initialized' Subscriber ID: 'xxx' SIM ICCID: 'xxx' Ready info: 'none' Telephone numbers: (1) 'xxx' [/dev/cdc-wdm0] Session not closed: TRID: '4'
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Saving state at /tmp/mbim-network-state-cdc-wdm0... (TRID: 4)
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Querying registration state 'mbimcli -d /dev/cdc-wdm0 --query-registration-state --no-open=4 --no-close --device-open-proxy'...
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: [/dev/cdc-wdm0] Registration status: Network error: 'unknown' Register state: 'home' Register mode: 'automatic' Available data classes: 'lte' Current cellular class: 'gsm' Provider ID: '310260' Provider name: 'Project Fi' Roaming text: 'unknown' Registration flags: 'packet-service-automatic-attach' [/dev/cdc-wdm0] Session not closed: TRID: '6'
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Saving state at /tmp/mbim-network-state-cdc-wdm0... (TRID: 6)
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Attaching to packet service with 'mbimcli -d /dev/cdc-wdm0 --attach-packet-service --no-open=6 --no-close --device-open-proxy'...
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Saving state at /tmp/mbim-network-state-cdc-wdm0... (TRID: 8)
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Starting network with 'mbimcli -d /dev/cdc-wdm0 --connect=apn='h2g2' --no-open=8 --no-close --device-open-proxy'...
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Network started successfully
Jun 23 14:49:28 routnerr-2 mbim-network[22404]: Saving state at /tmp/mbim-network-state-cdc-wdm0... (TRID: 11)
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]: [/dev/cdc-wdm0] IPv4 configuration available: 'address, gateway, dns, mtu'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:      IP [0]: '192.0.2.10/28'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     Gateway: '192.0.2.1'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     DNS [0]: '10.177.0.34'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     DNS [1]: '10.177.0.210'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:         MTU: '1500'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]: [/dev/cdc-wdm0] IPv6 configuration available: 'address, gateway, dns, mtu'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:      IP [0]: '2001:db8::10/64'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     Gateway: '2001:db8::1'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     DNS [0]: 'fd00:976a::9'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:     DNS [1]: 'fd00:976a::10'
Jun 23 14:49:29 routnerr-2 j84f9wl2m4knm6m2psny4jnvm6jqarrw-unit-script-mbim-network-dev-cdc-wdm0-post-start[22491]:         MTU: '1500'
Jun 23 14:49:29 routnerr-2 systemd[1]: Started mbim-network for '/dev/cdc-wdm0'.

And stopping the systemd unit brings the device down and clears the transaction ID state:

Jun 23 14:56:31 routnerr-2 systemd[1]: Stopping mbim-network for '/dev/cdc-wdm0'...
Jun 23 14:56:32 routnerr-2 mbim-network[25473]: Loading profile at /nix/store/8352hirv32jh9miadvynq0vm3bkal1vn-mbim-network-dev-cdc-wdm0.conf...
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     APN: h2g2
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     APN auth protocol: unset
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     APN user: unset
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     APN password: unset
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     mbim-proxy: yes
Jun 23 14:56:32 routnerr-2 mbim-network[25473]: Loading previous state from /tmp/mbim-network-state-cdc-wdm0...
Jun 23 14:56:32 routnerr-2 mbim-network[25473]:     Previous Transaction ID: 13
Jun 23 14:56:32 routnerr-2 mbim-network[25473]: Stopping network with 'mbimcli -d /dev/cdc-wdm0 --disconnect --no-open=13 --device-open-proxy'...
Jun 23 14:56:32 routnerr-2 mbim-network[25473]: Network stopped successfully
Jun 23 14:56:32 routnerr-2 mbim-network[25473]: Clearing state at /tmp/mbim-network-state-cdc-wdm0...
Jun 23 14:56:35 routnerr-2 systemd[1]: mbim-network-dev-cdc-wdm0.service: Succeeded.
Jun 23 14:56:35 routnerr-2 systemd[1]: Stopped mbim-network for '/dev/cdc-wdm0'.

I have a few open questions:

  1. Unfortunately, I have absolutely no idea how to test this change with a NixOS test as it relies on the physical modem device attached to my router. Any suggestions?

  2. Does this belong under services.mbim-network or maybe something like networking.mbim?

  3. I don't intend to implement it in this initial PR, but how should I deal with IP address configuration via the MBIM out-of-band signaling (note the post-start systemd unit output above)? My particular modem only supports raw-ip mode rather than 802-3, so I can't use DHCP.

I'm considering parsing the output of the IP query command and plumbing that into the NixOS networking config in some way but have no idea how that should work. Suggestions appreciated! A hand-wavey hypothetical config:

services.mbim-network.devices."/dev/cdc-wdm0" = {
  apn = "h2g2";
  netdev = {
    # Specifies which device which will have the configuration applied, and which parts of the configuration.
    name = "wwp0s19u1u3i12";
    configure = [ "address" "gateway" "dns" "mtu" ];
  };
};

/cc @flokli per our conversation in #nixos-on-your-router.

@mdlayher
Copy link
Member Author

mdlayher commented Jun 23, 2020

/marvin opt-in

@marvin-mk2 marvin-mk2 bot added the marvin label Jun 23, 2020
@marvin-mk2
Copy link

marvin-mk2 bot commented Jun 23, 2020

Hi! I'm an experimental bot. My goal is to guide this PR through its stages, hopefully ending with a merge. You can read up on the usage here.

@mdlayher
Copy link
Member Author

mdlayher commented Jun 23, 2020

/status needs_review

@mdlayher mdlayher force-pushed the mdlayher:mdl-mbim-network branch from df69eba to 74959f0 Jun 23, 2020
@mdlayher
Copy link
Member Author

mdlayher commented Jun 23, 2020

@flokli updated, thanks.

Copy link
Contributor

flokli left a comment

I won't get a chance to test this on real hardware before the weekend, are you fine with keeping it open until then, or can someone else test this?

nixos/modules/services/networking/mbim-network.nix Outdated Show resolved Hide resolved
Signed-off-by: Matt Layher <mdlayher@gmail.com>
@mdlayher mdlayher force-pushed the mdlayher:mdl-mbim-network branch from 74959f0 to e39e790 Jun 24, 2020
@mdlayher
Copy link
Member Author

mdlayher commented Jun 24, 2020

@flokli @symphorien thank you both for the reviews, updated.

@flokli, no rush at all. I have a copy of this module in my own configs and am able to import and use it there already. Thank you for your help.

@mdlayher
Copy link
Member Author

mdlayher commented Jun 25, 2020

After a couple of conversations on IRC, I suspect I am going to take the NetworkManager/ModemManager approach for my modem rather than using this module.

Should I close this PR or should I leave it open for review/merge in case it's useful for others?

@timokau
Copy link
Member

timokau commented Jul 1, 2020

This is outside of my area of expertise, but the diff looks good enough to me and it looks like @flokli and @symphorien already gave more knowledgeable reviews. I'd be fine with getting this finished up & merged if you're using it, but if you don't plan to use (and therefore maintain) it yourself I think its better to close it. If you want to help out others, maybe add documentation on the approach you opted for instead.

/status needs_work

@marvin-mk2 marvin-mk2 bot added awaiting_changes and removed needs_reviewer labels Jul 1, 2020
@timokau
Copy link
Member

timokau commented Jul 1, 2020

If you do decide to pursue this further, I'd like to pick up the "secrets in store" discussion one more time. Is it really true that the relevant username/password is generally public knowledge?

@mdlayher
Copy link
Member Author

mdlayher commented Jul 1, 2020

I'd be fine with getting this finished up & merged if you're using it, but if you don't plan to use (and therefore maintain) it yourself I think its better to close it.

Will do, thanks!

If you want to help out others, maybe add documentation on the approach you opted for instead.

Unfortunately I don't have it quite worked out yet, but it seems like something along the lines of this will make it so NM/MM only manage GSM interfaces:

    networking.networkmanager = {
      enable = false;
      dns = "none";
      unmanaged = ["*,except:type:gsm"];
    };

From there, I have to do some more tinkering with the CLIs. If there's a way to Nixify all of that, I'll be sure to write up a guide.

@mdlayher mdlayher closed this Jul 1, 2020
@mdlayher mdlayher deleted the mdlayher:mdl-mbim-network branch Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.