Add wwan networking

This commit is contained in:
Fabian Hauser 2019-12-23 21:29:42 +00:00
parent a9e5fa79a5
commit bf015614b6
4 changed files with 88 additions and 111 deletions

View file

@ -7,92 +7,65 @@ with lib;
let
cfg = config.services.wwan;
mbim-ip = pkgs.writeScriptBin "mbim-ip" readFile ./wwan/mbim-ip.bash;
mbim-ip-configured = pkgs.writeScriptBin "mbim-ip-configured" ''
mbim-ip-configured = pkgs.writeScriptBin "mbim-ip-configured" (''
#!${pkgs.stdenv.shell}
MBIM_BINARY=${pkgs.libmbim}/bin/mbimcli
MBIM_INTERFACE=${cfg.mbimInterface}
exec ${mbim-ip} $@
'';
'' + (readFile ./wwan/mbim-ip.bash));
in
{
options = {
services.wwan = {
enable = mkEnableOption "wwan client service";
options.services.wwan = {
enable = mkEnableOption "wwan client service";
config = mkOption {
type = types.attrsOf (types.submodule (
{
options = {
apn = mkOption {
type = types.str;
description = ''
APN domain of provider.
'';
};
apn = mkOption {
type = types.str;
description = ''
APN domain of provider.
'';
};
apnUser = mkOption {
type = types.str;
default = "";
description = ''
APN username (optional).
'';
};
apnUser = mkOption {
type = types.str;
default = "";
description = ''
APN username (optional).
'';
};
apnPass = mkOption {
type = types.str;
default = "";
description = ''
APN password (optional).
'';
};
apnPass = mkOption {
type = types.str;
default = "";
description = ''
APN password (optional).
'';
};
apnAuth = mkOption {
type = types.enum;
values = [ "PAP" "CHAP" "MSCHAPV2" "" ];
default = "";
description = ''
APN authentication type, one of ${concatMapStringsSep ", " show values} (optional).
'';
};
apnAuth = mkOption {
type = types.enum [ "PAP" "CHAP" "MSCHAPV2" "" ];
default = "";
description = ''
APN authentication type, one of ${concatMapStringsSep ", " show values} (optional).
'';
};
mbimProxy = mkOption {
type = types.bool;
default = true;
description = ''
Whether to use the mbim proxy or not.
'';
};
mbimProxy = mkOption {
type = types.bool;
default = true;
description = ''
Whether to use the mbim proxy or not.
'';
};
mbimInterface = mkOption {
type = types.path;
default = /dev/cdc-wdm0
description = "MBIM Interface which the connection will use.";
};
mbimInterface = mkOption {
type = types.str;
default = "/dev/cdc-wdm0";
description = ''
MBIM Interface which the connection will use.
'';
};
networkInterface = mkOption {
type = types.str;
description = "Name of the WWAN network interface";
};
};
}
));
default = {};
example = literalExample ''
{
wwan = {
apn = "gprs.swisscom.ch";
networkInterface = "wwp0s19u1u3i12";
};
}
'';
description = ''
Configuration for WWAN connectivity using a MBIM capable card.
'';
};
networkInterface = mkOption {
type = types.str;
description = "Name of the WWAN network interface";
};
};
@ -100,27 +73,25 @@ in
systemd.services."wwan" = {
description = "WWAN connectivity";
wantedBy = [ "network.target" ];
wants = [ "sys-subsystem-net-devices-${cfg.networkInterface}.device"];
bindsTo = [ "network-addresses-${cfg.networkInterface}.service" ];
path = [ pkgs.libmbim pkgs.iproute ];
serviceConfig = {
ExecStart = "@${pkgs.libmbim}/bin/mbim-network ${toString cfg.mbimInterface} start";
ExecStop = "@${pkgs.libmbim}/bin/mbim-network ${toString cfg.mbimInterface} stop";
# MBIM networking is a special fellow - it gets the IP address for us,
# but we need to manually set it to the interface
ExecStartPost = "@${mbim-ip-configured} start ${cfg.networkInterface}";
ExecStopPre = "@${mbim-ip-configured} stop ${cfg.networkInterface}";
ExecStart = "${mbim-ip-configured}/bin/mbim-ip-configured start ${cfg.networkInterface}";
ExecStop = "${mbim-ip-configured}/bin/mbim-ip-configured stop ${cfg.networkInterface}";
RemainAfterExit = true;
};
};
environment.etc."/etc/mbim-network.conf".text = ''
APN=${cfg.apnUser}
environment.etc."mbim-network.conf".text = ''
APN=${cfg.apn}
APN_USER=${cfg.apnUser}
APN_PASS=${cfg.apnPass}
APN_AUTH=${cfg.apnAuth}
PROXY=${optionalString cfg.proxy "yes"}
PROXY=${optionalString cfg.mbimProxy "yes"}
'';
networking.interfaces.${cfg.networkInterface}.useDHCP = false;
};
}