Add wwan module
This commit is contained in:
parent
ef684576df
commit
a9e5fa79a5
3 changed files with 452 additions and 1 deletions
126
role/networking/wwan.nix
Normal file
126
role/networking/wwan.nix
Normal file
|
@ -0,0 +1,126 @@
|
|||
# Based on https://github.com/jgillich/nixos/blob/master/services/ppp.nix
|
||||
# Tipps and tricks under https://www.hackster.io/munoz0raul/how-to-use-gsm-3g-4g-in-embedded-linux-systems-9047cf#toc-configuring-the-ppp-files-5
|
||||
# TODO: http://www.embeddedpi.com/documentation/3g-4g-modems/raspberry-pi-sierra-wireless-mc7455-modem-raw-ip-qmi-interface-setup
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
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" ''
|
||||
#!${pkgs.stdenv.shell}
|
||||
MBIM_BINARY=${pkgs.libmbim}/bin/mbimcli
|
||||
MBIM_INTERFACE=${cfg.mbimInterface}
|
||||
exec ${mbim-ip} $@
|
||||
'';
|
||||
in
|
||||
{
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
apnUser = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
APN username (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).
|
||||
'';
|
||||
};
|
||||
|
||||
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.";
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."wwan" = {
|
||||
description = "WWAN connectivity";
|
||||
wantedBy = [ "network.target" ];
|
||||
wants = [ "sys-subsystem-net-devices-${cfg.networkInterface}.device"];
|
||||
|
||||
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}";
|
||||
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
|
||||
environment.etc."/etc/mbim-network.conf".text = ''
|
||||
APN=${cfg.apnUser}
|
||||
APN_USER=${cfg.apnUser}
|
||||
APN_PASS=${cfg.apnPass}
|
||||
APN_AUTH=${cfg.apnAuth}
|
||||
PROXY=${optionalString cfg.proxy "yes"}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue