Add wwan status check
This commit is contained in:
parent
4253b340ff
commit
aff3512244
2 changed files with 43 additions and 11 deletions
|
@ -48,7 +48,7 @@ in
|
||||||
services.wwan = {
|
services.wwan = {
|
||||||
enable = true;
|
enable = true;
|
||||||
apn = "gprs.swisscom.ch";
|
apn = "gprs.swisscom.ch";
|
||||||
networkInterface = "wwp0s19u1u3i12";
|
networkInterface = routerConfig.wanInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Use the GRUB 2 boot loader.
|
# Use the GRUB 2 boot loader.
|
||||||
|
|
|
@ -1,16 +1,29 @@
|
||||||
# Based on https://github.com/jgillich/nixos/blob/master/services/ppp.nix
|
# 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
|
# 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, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.wwan;
|
cfg = config.services.wwan;
|
||||||
|
|
||||||
mbim-ip-configured = pkgs.writeScriptBin "mbim-ip-configured" (''
|
mbim-ip-configured = pkgs.writeScriptBin "mbim-ip-configured" (''
|
||||||
#!${pkgs.stdenv.shell}
|
#!${pkgs.stdenv.shell}
|
||||||
MBIM_INTERFACE=${cfg.mbimInterface}
|
MBIM_INTERFACE=${cfg.mbimInterface}
|
||||||
'' + (readFile ./wwan/mbim-ip.bash));
|
'' + (readFile ./wwan/mbim-ip.bash));
|
||||||
|
|
||||||
|
mbim-check-status = pkgs.writeScriptBin "mbim-check-status" ''
|
||||||
|
#!${pkgs.stdenv.shell}
|
||||||
|
if ! systemctl is-active --quiet wwan.service; then
|
||||||
|
# Skip check if wwan is not running
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! mbim-network ${cfg.mbimInterface} status | grep -q "Status: activated"; then
|
||||||
|
echo "WWAN device is currently in disabled state, triggering restart."
|
||||||
|
systemctl restart wwan.service
|
||||||
|
fi
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.wwan = {
|
options.services.wwan = {
|
||||||
|
@ -70,11 +83,12 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
systemd.services."wwan" = {
|
systemd.services = {
|
||||||
|
"wwan" = {
|
||||||
description = "WWAN connectivity";
|
description = "WWAN connectivity";
|
||||||
wantedBy = [ "network.target" ];
|
wantedBy = [ "network.target" ];
|
||||||
bindsTo = [ "network-addresses-${cfg.networkInterface}.service" ];
|
bindsTo = [ "network-addresses-${cfg.networkInterface}.service" ];
|
||||||
path = [ pkgs.libmbim pkgs.iproute ];
|
path = with pkgs; [ libmbim iproute ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${mbim-ip-configured}/bin/mbim-ip-configured start ${cfg.networkInterface}";
|
ExecStart = "${mbim-ip-configured}/bin/mbim-ip-configured start ${cfg.networkInterface}";
|
||||||
|
@ -83,6 +97,24 @@ in
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
"wwan-check" = {
|
||||||
|
description = "Check WWAN connectivity and restart if disabled";
|
||||||
|
path = with pkgs; [ libmbim ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
ExecStart = "${mbim-check-status}/bin/mbim-check-status";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systemd.timers."wwan-check" = {
|
||||||
|
description = "WWAN connectivity check";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
Unit = "wwan-check";
|
||||||
|
OnBootSec="2m";
|
||||||
|
OnUnitActiveSec="1m";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
environment.etc."mbim-network.conf".text = ''
|
environment.etc."mbim-network.conf".text = ''
|
||||||
APN=${cfg.apn}
|
APN=${cfg.apn}
|
||||||
|
|
Loading…
Add table
Reference in a new issue