aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/wifi-adm.nix
blob: e69afd1c827fb52e1b08d822f841d367376c48f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
  config,
  lib,
  ...
}: let
  inherit (lib) mkOption mkEnableOption types mkIf mkMerge hostapd elemAt;
  cnf = config.cynerd.wifiAP.adm;

  wifi-networks = name: {
    "${cnf."${name}".interface}" = {
      bssid = elemAt cnf."${name}".bssids 0;
      ssid = "TurrisAdamkovi";
      authentication = {
        mode = "wpa3-sae-transition";
        wpaPasswordFile = "/run/secrets/hostapd-TurrisAdamkovi.pass";
        saePasswordsFile = "/run/secrets/hostapd-TurrisAdamkovi.pass";
      };
    };
    "${cnf."${name}".interface}.milan" = {
      bssid = elemAt cnf."${name}".bssids 1;
      ssid = "MILAN-AC";
      authentication = {
        mode = "wpa2-sha1";
        wpaPasswordFile = "/run/secrets/hostapd-MILAN-AC.pass";
      };
    };
  };

  net-networks = name: {
    "lan-${cnf."${name}".interface}" = {
      matchConfig = {
        Name = cnf."${name}".interface;
        WLANInterfaceType = "ap";
      };
      networkConfig.Bridge = "brlan";
      bridgeVLANs = [
        {
          EgressUntagged = 1;
          PVID = 1;
        }
      ];
    };
    "lan-${cnf."${name}".interface}.milan" = {
      matchConfig.Name = "${cnf."${name}".interface}.milan";
      networkConfig.Bridge = "brlan";
      bridgeVLANs = [
        {
          EgressUntagged = 1;
          PVID = 1;
        }
      ];
    };
  };

  wOptions = card: channelDefault: {
    interface = mkOption {
      type = with types; nullOr str;
      default = null;
      description = "Specify interface for ${card}";
    };
    bssids = mkOption {
      type = with types; listOf str;
      default = [];
      description = "BSSIDs for networks.";
    };
    channel = mkOption {
      type = types.ints.positive;
      default = channelDefault;
      description = "Channel to be used for ${card}";
    };
  };
in {
  options = {
    cynerd.wifiAP.adm = {
      enable = mkEnableOption "Enable Wi-Fi Access Point support";
      ar9287 = wOptions "Qualcom Atheros AR9287" 7;
      qca988x = wOptions "Qualcom Atheros QCA988x" 36;
    };
  };

  config = mkIf cnf.enable {
    services.hostapd = {
      enable = true;
      radios = {
        "${cnf.ar9287.interface}" = mkIf (cnf.ar9287.interface != null) {
          countryCode = "CZ";
          inherit (cnf.ar9287) channel;
          wifi4 = {
            enable = true;
            inherit (hostapd.qualcomAtherosAR9287.wifi4) capabilities;
          };
          networks = wifi-networks "ar9287";
        };
        "${cnf.qca988x.interface}" = mkIf (cnf.qca988x.interface != null) {
          countryCode = "CZ";
          inherit (cnf.qca988x) channel;
          band = "5g";
          wifi4 = {
            enable = true;
            inherit (hostapd.qualcomAtherosQCA988x.wifi4) capabilities;
          };
          wifi5 = {
            enable = true;
            inherit (hostapd.qualcomAtherosQCA988x.wifi5) capabilities;
          };
          networks = wifi-networks "qca988x";
        };
      };
    };
    systemd.network.networks = mkMerge [
      (mkIf (cnf.ar9287.interface != null) (net-networks "ar9287"))
      (mkIf (cnf.qca988x.interface != null) (net-networks "qca988x"))
    ];
  };
}