aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/wifi-zd.nix
blob: c275fc3d5d5b1826f9e4272ce370b9f66142de3f (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
{
  config,
  lib,
  ...
}: let
  inherit (lib) mkOption mkEnableOption types mkIf mkForce elemAt;
  cnf = config.cynerd.wifiAP.zd;

  wOptions = {
    bssids = mkOption {
      type = with types; listOf str;
      default = [];
      description = "BSSIDs for networks.";
    };
    channel = mkOption {
      type = types.ints.positive;
      description = "Channel to be used";
    };
  };
in {
  options = {
    cynerd.wifiAP.zd = {
      enable = mkEnableOption "Enable Wi-Fi Access Point support (OpenWrt One)";
      wlan0 = wOptions;
      wlan1 = wOptions;
    };
  };

  config = mkIf cnf.enable {
    # TODO regdom doesn't work for some reason
    boot.extraModprobeConfig = ''
      options cfg80211 ieee80211_regdom="CZ"
    '';
    services.hostapd = {
      enable = true;
      radios = {
        "wlan0" = {
          inherit (cnf.wlan0) channel;
          countryCode = "CZ";
          wifi4 = {
            enable = true;
            capabilities = [
              "HT40"
              "SHORT-GI-20"
              "SHORT-GI-40"
              "TX-STBC"
              "RX-STBC1"
              "MAX-AMSDU-7935"
            ];
          };
          networks = {
            "wlan0" = {
              bssid = elemAt cnf.wlan0.bssids 0;
              ssid = "UNas";
              authentication = {
                mode = "wpa2-sha256";
                wpaPasswordFile = "/run/secrets/hostapd-UNas.pass";
              };
            };
            "wlan0.guest" = {
              bssid = elemAt cnf.wlan0.bssids 1;
              ssid = "Koci";
              authentication = {
                mode = "wpa2-sha256";
                wpaPasswordFile = "/run/secrets/hostapd-Koci.pass";
              };
            };
            "wlan0.iotd" = {
              bssid = elemAt cnf.wlan0.bssids 2;
              ssid = "IOTD";
              authentication = {
                mode = "wpa2-sha256";
                wpaPasswordFile = "/run/secrets/hostapd-IOTD.pass";
              };
              settings = {
                ieee80211w = mkForce 0;
                wpa_key_mgmt = mkForce "WPA-PSK"; # force use without sha256
              };
            };
          };
        };
        #"wlan1" = {
        #};
      };
    };
    systemd.network.networks = {
      "lan-wlan0" = {
        matchConfig = {
          Name = "wlan0 wlan0.iotd";
          WLANInterfaceType = "ap";
        };
        networkConfig.Bridge = "brlan";
        bridgeVLANs = [
          {
            EgressUntagged = 1;
            PVID = 1;
          }
        ];
      };
      "lan-wlan0-guest" = {
        matchConfig.Name = "wlan0.guest";
        networkConfig.Bridge = "brlan";
        bridgeVLANs = [
          {
            EgressUntagged = 2;
            PVID = 2;
          }
        ];
      };
    };
  };
}