├── img └── setup.jpg ├── .gitignore ├── include ├── version.hpp ├── wifi.hpp └── i2c_nfc_device.hpp ├── DOCKER_HOWTO.md ├── README.md ├── LICENSE └── src └── xinfc-wsc.cpp /img/setup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caian/xinfc/HEAD/img/setup.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /include/version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Caian Benedicto 3 | * 4 | * This file is part of xinfc. 5 | * 6 | * xinfc is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * xinfc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with xinfc. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #if !defined(XINFC_VERSION) 23 | #define XINFC_VERSION "(unversioned)" 24 | #endif 25 | -------------------------------------------------------------------------------- /DOCKER_HOWTO.md: -------------------------------------------------------------------------------- 1 | # Building for OpenWRT using docker 2 | 3 | Start a new docker instance: 4 | 5 | ``` 6 | sudo docker run --rm -ti --volume "$PWD:/xinfc" ubuntu:20.04 /bin/bash 7 | ``` 8 | 9 | Install requirements and add the build user: 10 | 11 | ``` 12 | cd / 13 | 14 | apt update 15 | apt -y install perl build-essential libncurses5-dev libmpfr-dev \ 16 | libgmp-dev libpam-dev liblzma-dev file git rsync gawk wget \ 17 | python3 python3-distutils python3-setuptools unzip swig 18 | 19 | useradd openwrt 20 | mkdir openwrt 21 | chmod 777 openwrt 22 | cd openwrt 23 | ``` 24 | 25 | Do the build process as a regular user: 26 | 27 | ``` 28 | su openwrt 29 | ``` 30 | 31 | Grab the OpenWRT source and build it ([dimfishr's build](https://github.com/dimfishr/openwrt)): 32 | 33 | ``` 34 | wget https://github.com/dimfishr/openwrt/archive/refs/tags/filogic-2023-12-27.zip 35 | 36 | unzip filogic-2023-12-27.zip 37 | 38 | cd openwrt-filogic-2023-12-27 39 | 40 | ./scripts/feeds update -a 41 | ./scripts/feeds install -a 42 | 43 | echo "CONFIG_TARGET_mediatek=y\n" > .config 44 | echo "CONFIG_TARGET_mediatek_filogic=y\n" >> .config 45 | echo "CONFIG_TARGET_MULTI_PROFILE=y\n" >> .config 46 | echo "CONFIG_TARGET_PER_DEVICE_ROOTFS=y\n" >> .config 47 | echo "CONFIG_TARGET_DEVICE_mediatek_filogic_DEVICE_xiaomi_mi-router-ax3000t=y\n" >> .config 48 | echo "CONFIG_TARGET_DEVICE_mediatek_filogic_DEVICE_xiaomi_mi-router-ax3000t-ubootmod=y\n" >> .config 49 | echo "CONFIG_PACKAGE_wpad-basic-mbedtls=m\n" >> .config 50 | echo "CONFIG_PACKAGE_libwolfsslcpu-crypto=y\n" >> .config 51 | echo "CONFIG_PACKAGE_wpad-wolfssl=y\n" >> .config 52 | echo "CONFIG_PACKAGE_dnsmasq=m\n" >> .config 53 | echo "CONFIG_PACKAGE_dnsmasq-full=y\n" >> .config 54 | echo "CONFIG_PACKAGE_kmod-nf-nathelper=y\n" >> .config 55 | echo "CONFIG_PACKAGE_kmod-nf-nathelper-extra=y\n" >> .config 56 | echo "CONFIG_PACKAGE_luci=y\n" >> .config 57 | echo "CONFIG_PACKAGE_luci-proto-wireguard=y\n" >> .config 58 | echo "CONFIG_PACKAGE_xl2tpd=y\n" >> .config 59 | 60 | make defconfig 61 | make download V=s 62 | make tools/install -j$(nproc) V=s || \ 63 | make tools/install V=s 64 | make toolchain/install -j$(nproc) V=s || \ 65 | make toolchain/install V=s 66 | make -j$(nproc) V=s || \ 67 | make V=s 68 | ``` 69 | 70 | Set the compiler: 71 | 72 | ``` 73 | export PATH="/openwrt/openwrt-filogic-2023-12-27/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-5.15.145/scripts/dtc:/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/host/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/host/bin:/openwrt/openwrt-filogic-2023-12-27/staging_dir/host/bin:$PATH" 74 | export CXX=/openwrt/openwrt-filogic-2023-12-27/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-g++ 75 | ``` 76 | 77 | **If you plan to rebuild the code, then this is a good time to `docker commit` the container into an image so you don't have to do this all over again.** 78 | 79 | Build xinfc: 80 | 81 | ``` 82 | cd /xinfc 83 | bash build.sh 84 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xinfc 2 | 3 | This repository contains tools for interfacing with the NFC chip on 4 | Xiaomi routers. 5 | 6 | ## About 7 | 8 | Some Xiaomi routers are NFC capable. This a convenient way to share network information, requiring only proximity to the router. While practical, the stock router firmware is not flexible, so, for instance, you can't tell it to share the guest network credentials instead of the main one. 9 | 10 | Open source firmwares like OpenWRT are much more flexible, but some components are missing support, the NFC chips used by Xiaomi being some of them. 11 | 12 | This repository aims to add some more functionality to these firmwares and make it practical to program Wi-Fi credentials to NFC chips. 13 | 14 | ## Disclaimer 15 | 16 | The tools in this repository may break the NFC chip and/or the router if used incorrectly and may pose a security risk if exploited. None of the tools provided check the ID of the NFC chip before writing to it. Make sure the Router and NFC chip match the tested hardware. Use at your own risk. 17 | 18 | ## Tested hardware 19 | 20 | | Router | NFC Chip | Firmware 21 | |--------|----------|---------| 22 | | Xiaomi AX3000T (RD03) | NT082C NTC1 320N0G (Fudan Microelectronics) | OpenWrt 23.05.2 23 | 24 | ## Required packages 25 | 26 | - i2c-tools 27 | 28 | ## Finding I2C bus and I2C address 29 | 30 | A router may have multiple I2C busses with many devices attached to it **even memory chips, that's why it is important to know what you are doing!** Luckily your router will have only one bus and a single device (the NFC chip). You can use `i2cdetect` to find devices on a bus. For instance, my AX3000T has only bus `0` and the NFC chip with address `0x57`: 31 | 32 | ``` 33 | root@OpenWrt:~# i2cdetect -y 0 34 | 0 1 2 3 4 5 6 7 8 9 a b c d e f 35 | 00: -- -- -- -- -- -- -- -- 36 | 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 37 | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 38 | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 39 | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40 | 50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- -- 41 | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 42 | 70: -- -- -- -- -- -- -- -- 43 | ``` 44 | 45 | The bus and address will be required by the tools to access the NFC chip. 46 | 47 | ## Tools 48 | 49 | ### xinfc-wsc 50 | 51 | Programs a Wi-Fi Simple Configuration (WSC) NDEF on the NFC chip that can be scanned by Android devices to auto-connect to the network. Notice: The tool lacks WPA3 support. Mixed WPA3/WPA2 networks will be announced as WPA2. 52 | 53 | `xinfc-wsc ` 54 | 55 | The network encryption is the same used by OpenWRT's `/etc/config/wireless`. Run `xinfc-wsc` without any arguments to see the full list of available encryption methods (some are not supported): 56 | 57 | ``` 58 | ./xinfc-wsc 0 0x57 TestTests test1234 sae-mixed 59 | ``` 60 | 61 | `xinfc-wsc` will back up the current chip data to a file every time it runs. **Keep the first backup safe because it contains the original data programmed by the stock firmware**. 62 | 63 | **Warning: The backup data may prove insufficient to restore the chip if something goes wrong!** 64 | 65 | ## Building xinfc 66 | 67 | I've provided some scripts to build xinfc on Linux and OpenWRT 23. The OpenWRT cross-compiling is based on docker and uses [dimfishr's build](https://github.com/dimfishr/openwrt) as build root. The build instructions are also based on dimfishr's scripts. The dummy build is intended for testing and replaces all I2C calls with a proxy. 68 | 69 | ## Daemonizing the tools 70 | 71 | The NFC chip does not require a daemon or service to work. Data is programmed once and that's it, it survives reboots **and the chip can even broadcast when the router is powered off!**. An automation should, ideally, program the chip on boot and every time the desired network changes. 72 | 73 | ## Known issues 74 | 75 | I've noticed that the chip stops responding a lot. I've added retries to overcome this situation and I also noticed that the stock router firmware does this. Maybe it's a matter of tuning some I2C parameters, but I don't know. 76 | 77 | ## Adding more hardware 78 | 79 | So far I tested this on my AX3000T: 80 | 81 | ![AX3000T setup](img/setup.jpg) 82 | 83 | I used two needles commonly used to clean 3D printer nozzles and probed the SCL/SDA pins directly. Then I connected a cheap logic analyzer to them. This shows how the router talks to the chip. 84 | 85 | Contributions are welcome :) -------------------------------------------------------------------------------- /include/wifi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Caian Benedicto 3 | * 4 | * This file is part of xinfc. 5 | * 6 | * xinfc is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * xinfc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with xinfc. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace xinfc { 23 | 24 | struct wifi_lenghts 25 | { 26 | static const unsigned int ssid_min = 2; 27 | static const unsigned int ssid_max = 28; 28 | static const unsigned int pass_min = 8; 29 | static const unsigned int pass_max = 63; 30 | }; 31 | 32 | enum wifi_crypt 33 | { 34 | wifi_crypt_none = 0x01, 35 | wifi_crypt_wep = 0x02, 36 | wifi_crypt_tkip = 0x04, 37 | wifi_crypt_aes = 0x08, 38 | wifi_crypt_tkip_aes = wifi_crypt_tkip | wifi_crypt_aes, 39 | }; 40 | 41 | enum wifi_auth 42 | { 43 | wifi_auth_open = 0x01, 44 | wifi_auth_wpa_personal = 0x02, 45 | wifi_auth_shared = 0x04, 46 | wifi_auth_wpa_enterprise = 0x08, 47 | wifi_auth_wpa2_enterprise = 0x10, 48 | wifi_auth_wpa2_personal = 0x20, 49 | wifi_auth_wpa_wpa2_personal = wifi_auth_wpa_personal | wifi_auth_wpa2_personal, 50 | }; 51 | 52 | struct wifi_str 53 | { 54 | // From https://openwrt.org/docs/guide-user/network/wifi/basic#encryption_modes 55 | static const char* none() // no authentication none 56 | { 57 | return "none"; 58 | } 59 | 60 | static const char* sae() // WPA3 Personal (SAE) CCMP 61 | { 62 | return "sae"; 63 | } 64 | 65 | static const char* sae_mixed() // WPA2/WPA3 Personal (PSK/SAE) mixed mode CCMP 66 | { 67 | return "sae-mixed"; 68 | } 69 | 70 | static const char* psk2_tkip_ccmp() // WPA2 Personal (PSK) TKIP, CCMP 71 | { 72 | return "psk2+tkip+ccmp"; 73 | } 74 | 75 | static const char* psk2_tkip_aes() // WPA2 Personal (PSK) TKIP, CCMP 76 | { 77 | return "psk2+tkip+aes"; 78 | } 79 | 80 | static const char* psk2_tkip() // WPA2 Personal (PSK) TKIP 81 | { 82 | return "psk2+tkip"; 83 | } 84 | 85 | static const char* psk2_ccmp() // WPA2 Personal (PSK) CCMP 86 | { 87 | return "psk2+ccmp"; 88 | } 89 | 90 | static const char* psk2_aes() // WPA2 Personal (PSK) CCMP 91 | { 92 | return "psk2+aes"; 93 | } 94 | 95 | static const char* psk2() // WPA2 Personal (PSK) CCMP 96 | { 97 | return "psk2"; 98 | } 99 | 100 | static const char* psk_tkip_ccmp() // WPA Personal (PSK) TKIP, CCMP 101 | { 102 | return "psk+tkip+ccmp"; 103 | } 104 | 105 | static const char* psk_tkip_aes() // WPA Personal (PSK) TKIP, CCMP 106 | { 107 | return "psk+tkip+aes"; 108 | } 109 | 110 | static const char* psk_tkip() // WPA Personal (PSK) TKIP 111 | { 112 | return "psk+tkip"; 113 | } 114 | 115 | static const char* psk_ccmp() // WPA Personal (PSK) CCMP 116 | { 117 | return "psk+ccmp"; 118 | } 119 | 120 | static const char* psk_aes() // WPA Personal (PSK) CCMP 121 | { 122 | return "psk+aes"; 123 | } 124 | 125 | static const char* psk() // WPA Personal (PSK) CCMP 126 | { 127 | return "psk"; 128 | } 129 | 130 | static const char* psk_mixed_tkip_ccmp() // WPA/WPA2 Personal (PSK) mixed mode TKIP, CCMP 131 | { 132 | return "psk-mixed+tkip+ccmp"; 133 | } 134 | 135 | static const char* psk_mixed_tkip_aes() // WPA/WPA2 Personal (PSK) mixed mode TKIP, CCMP 136 | { 137 | return "psk-mixed+tkip+aes"; 138 | } 139 | 140 | static const char* psk_mixed_tkip() // WPA/WPA2 Personal (PSK) mixed mode TKIP 141 | { 142 | return "psk-mixed+tkip"; 143 | } 144 | 145 | static const char* psk_mixed_ccmp() // WPA/WPA2 Personal (PSK) mixed mode CCMP 146 | { 147 | return "psk-mixed+ccmp"; 148 | } 149 | 150 | static const char* psk_mixed_aes() // WPA/WPA2 Personal (PSK) mixed mode CCMP 151 | { 152 | return "psk-mixed+aes"; 153 | } 154 | 155 | static const char* psk_mixed() // WPA/WPA2 Personal (PSK) mixed mode CCMP 156 | { 157 | return "psk-mixed"; 158 | } 159 | 160 | static const char* wep() // defaults to "open system" authentication aka wep+open 161 | { 162 | return "wep"; 163 | } 164 | 165 | static const char* wep_open() // "open system" authentication 166 | { 167 | return "wep+open"; 168 | } 169 | 170 | static const char* wep_shared() // "shared key" authentication 171 | { 172 | return "wep+shared"; 173 | } 174 | 175 | static const char* wpa3() // WPA3 Enterprise CCMP 176 | { 177 | return "wpa3"; 178 | } 179 | 180 | static const char* wpa3_mixed() // WPA3/WPA2 Enterprise CCMP 181 | { 182 | return "wpa3-mixed"; 183 | } 184 | 185 | static const char* wpa2_tkip_ccmp() // WPA2 Enterprise TKIP, CCMP 186 | { 187 | return "wpa2+tkip+ccmp"; 188 | } 189 | 190 | static const char* wpa2_tkip_aes() // WPA2 Enterprise TKIP, CCMP 191 | { 192 | return "wpa2+tkip+aes"; 193 | } 194 | 195 | static const char* wpa2_ccmp() // WPA2 Enterprise CCMP 196 | { 197 | return "wpa2+ccmp"; 198 | } 199 | 200 | static const char* wpa2_aes() // WPA2 Enterprise CCMP 201 | { 202 | return "wpa2+aes"; 203 | } 204 | 205 | static const char* wpa2() // WPA2 Enterprise CCMP 206 | { 207 | return "wpa2"; 208 | } 209 | 210 | static const char* wpa2_tkip() // WPA2 Enterprise TKIP 211 | { 212 | return "wpa2+tkip"; 213 | } 214 | 215 | static const char* wpa_tkip_ccmp() // WPA Enterprise TKIP, CCMP 216 | { 217 | return "wpa+tkip+ccmp"; 218 | } 219 | 220 | static const char* wpa_tkip_aes() // WPA Enterprise TKIP, AES 221 | { 222 | return "wpa+tkip+aes"; 223 | } 224 | 225 | static const char* wpa_ccmp() // WPA Enterprise CCMP 226 | { 227 | return "wpa+ccmp"; 228 | } 229 | 230 | static const char* wpa_aes() // WPA Enterprise CCMP 231 | { 232 | return "wpa+aes"; 233 | } 234 | 235 | static const char* wpa_tkip() // WPA Enterprise TKIP 236 | { 237 | return "wpa+tkip"; 238 | } 239 | 240 | static const char* wpa() // WPA Enterprise CCMP 241 | { 242 | return "wpa"; 243 | } 244 | 245 | static const char* wpa_mixed_tkip_ccmp() // WPA/WPA2 Enterprise mixed mode TKIP, CCMP 246 | { 247 | return "wpa-mixed+tkip+ccmp"; 248 | } 249 | 250 | static const char* wpa_mixed_tkip_aes() // WPA/WPA2 Enterprise mixed mode TKIP, CCMP 251 | { 252 | return "wpa-mixed+tkip+aes"; 253 | } 254 | 255 | static const char* wpa_mixed_tkip() // WPA/WPA2 Enterprise mixed mode TKIP 256 | { 257 | return "wpa-mixed+tkip"; 258 | } 259 | 260 | static const char* wpa_mixed_ccmp() // WPA/WPA2 Enterprise mixed mode CCMP 261 | { 262 | return "wpa-mixed+ccmp"; 263 | } 264 | 265 | static const char* wpa_mixed_aes() // WPA/WPA2 Enterprise mixed mode CCMP 266 | { 267 | return "wpa-mixed+aes"; 268 | } 269 | 270 | static const char* wpa_mixed() // WPA/WPA2 Enterprise mixed mode CCMP 271 | { 272 | return "wpa-mixed"; 273 | } 274 | 275 | static const char* owe() // Opportunistic Wireless Encryption (OWE) CCMP 276 | { 277 | return "owe"; 278 | } 279 | }; 280 | 281 | } 282 | -------------------------------------------------------------------------------- /include/i2c_nfc_device.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Caian Benedicto 3 | * 4 | * This file is part of xinfc. 5 | * 6 | * xinfc is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * xinfc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with xinfc. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #if defined(XINFC_DUMMY_OUT) 34 | #include 35 | #include 36 | #include 37 | #endif 38 | 39 | namespace xinfc { 40 | 41 | struct i2c_error 42 | { 43 | const char* msg; 44 | int eno; 45 | int ret; 46 | }; 47 | 48 | class i2c_nfc_device 49 | { 50 | public: 51 | 52 | static const unsigned int max_ndef_buf_size = 160; 53 | static const unsigned short base_ndef_addr = 0x10; 54 | 55 | static_assert(max_ndef_buf_size / 4 <= I2C_RDRW_IOCTL_MAX_MSGS); 56 | 57 | private: 58 | 59 | std::string _bus_path; 60 | unsigned short _address; 61 | int _fd; 62 | 63 | public: 64 | 65 | i2c_nfc_device(const std::string& bus, unsigned short address) : 66 | _bus_path("/dev/i2c-" + bus), 67 | _address(address), 68 | _fd( 69 | #if !defined(XINFC_DUMMY_OUT) 70 | open(_bus_path.c_str(), O_RDWR, 0) 71 | #else 72 | -1 73 | #endif 74 | ) 75 | { 76 | #if !defined(XINFC_DUMMY_OUT) 77 | if (_fd < 0) 78 | { 79 | throw i2c_error { "failed to open i2c bus", errno, _fd }; 80 | } 81 | #endif 82 | } 83 | 84 | void set_timeout(unsigned long timeout) const 85 | { 86 | #if !defined(XINFC_DUMMY_OUT) 87 | if (ioctl(_fd, I2C_TIMEOUT, timeout) < 0) 88 | { 89 | throw i2c_error { "failed to set i2c timeout", errno, _fd }; 90 | } 91 | #endif 92 | } 93 | 94 | void set_retries(unsigned long retries) const 95 | { 96 | #if !defined(XINFC_DUMMY_OUT) 97 | const int r = ioctl(_fd, I2C_RETRIES, retries); 98 | 99 | if (r < 0) 100 | { 101 | throw i2c_error { "failed to set i2c retries", errno, r }; 102 | } 103 | #endif 104 | } 105 | 106 | void set_device_address(unsigned char address) 107 | { 108 | #if !defined(XINFC_DUMMY_OUT) 109 | long laddress = address; 110 | const int r = ioctl(_fd, I2C_SLAVE, laddress); 111 | 112 | if (r < 0) 113 | { 114 | throw i2c_error { "failed to set i2c device address", errno, r }; 115 | } 116 | #endif 117 | } 118 | 119 | void close() 120 | { 121 | #if !defined(XINFC_DUMMY_OUT) 122 | const int r = ::close(_fd); 123 | 124 | if (r) 125 | { 126 | throw i2c_error { "failed to close device", errno, r}; 127 | } 128 | #endif 129 | 130 | _fd = -1; 131 | } 132 | 133 | void read_ndef(unsigned char* out_buf, unsigned int size_4B_aligned) 134 | { 135 | if (size_4B_aligned == 0) 136 | return; 137 | 138 | if (out_buf == nullptr) 139 | { 140 | throw i2c_error { "invalid ndef buffer", 0 }; 141 | } 142 | 143 | if ((size_4B_aligned % 4) != 0) 144 | { 145 | throw i2c_error { "invalid read alignment", 0 }; 146 | } 147 | 148 | if (size_4B_aligned > max_ndef_buf_size) 149 | size_4B_aligned = max_ndef_buf_size; 150 | 151 | const unsigned int read_nmsgs = 2; 152 | 153 | struct i2c_msg msgs[2]; 154 | struct i2c_rdwr_ioctl_data rdwr; 155 | 156 | // The read operation is done by writing 157 | // the u16 address and then reading 158 | 159 | unsigned char ndef_addr_buf[2] = { 160 | (base_ndef_addr >> 8) & 0xFF, 161 | base_ndef_addr & 0xFF 162 | }; 163 | 164 | memset(out_buf, 0, size_4B_aligned); 165 | 166 | msgs[0].addr = _address; 167 | msgs[0].flags = 0; 168 | msgs[0].len = sizeof(ndef_addr_buf); 169 | msgs[0].buf = ndef_addr_buf; 170 | 171 | msgs[1].addr = _address; 172 | msgs[1].flags = I2C_M_RD; 173 | msgs[1].len = size_4B_aligned; 174 | msgs[1].buf = out_buf; 175 | 176 | rdwr.msgs = msgs; 177 | rdwr.nmsgs = read_nmsgs; 178 | 179 | #if !defined(XINFC_DUMMY_OUT) 180 | const int r = ioctl(_fd, I2C_RDWR, &rdwr); 181 | 182 | if (r != read_nmsgs) 183 | { 184 | throw i2c_error { "failed to read from i2c device", errno, r }; 185 | } 186 | #else 187 | print_rdwr(rdwr); 188 | #endif 189 | } 190 | 191 | void write_ndef_at( 192 | const unsigned char* buf, 193 | unsigned int size, 194 | unsigned short ndef_off 195 | ) 196 | { 197 | if (size == 0) 198 | return; 199 | 200 | if (buf == nullptr) 201 | { 202 | throw i2c_error { "invalid ndef buffer", 0, 0 }; 203 | } 204 | 205 | if (size > max_ndef_buf_size) 206 | { 207 | throw i2c_error { "invalid ndef buffer size", 0, 0 }; 208 | } 209 | 210 | // Each write operation will only write 4 bytes of data 211 | const unsigned int write_nmsgs = ((size - 1) / 4) + 1; 212 | 213 | struct i2c_msg msgs[write_nmsgs]; 214 | struct i2c_rdwr_ioctl_data rdwr; 215 | 216 | // Each write operation also needs 2 extra bytes of addressing 217 | unsigned char ndef_wbuf[write_nmsgs * 6]; 218 | 219 | for (unsigned int i = 0; i < write_nmsgs; i++) 220 | { 221 | auto curr_buf_off = 4*i; 222 | auto curr_p_buf = buf + curr_buf_off; 223 | auto curr_p_wbuf = ndef_wbuf + 6*i; 224 | auto ndef_addr = base_ndef_addr + ndef_off + curr_buf_off; 225 | 226 | auto len = std::min(size - curr_buf_off, 4U); 227 | 228 | curr_p_wbuf[0] = (ndef_addr >> 8) & 0xFF; 229 | curr_p_wbuf[1] = ndef_addr & 0xFF; 230 | 231 | for (unsigned int j = 0; j < len; j++) 232 | curr_p_wbuf[2 + j] = curr_p_buf[j]; 233 | 234 | for (unsigned int j = len; j < 4; j++) 235 | curr_p_wbuf[2 + j] = 0; 236 | 237 | auto& msg = msgs[i]; 238 | 239 | msg.addr = _address; 240 | msg.flags = 0; 241 | msg.len = 6; 242 | msg.buf = curr_p_wbuf; 243 | } 244 | 245 | rdwr.msgs = msgs; 246 | rdwr.nmsgs = write_nmsgs; 247 | 248 | #if !defined(XINFC_DUMMY_OUT) 249 | const int r = ioctl(_fd, I2C_RDWR, &rdwr); 250 | 251 | if (r != (int)write_nmsgs) 252 | { 253 | throw i2c_error { "failed to write to i2c device", errno, r }; 254 | } 255 | #else 256 | print_rdwr(rdwr); 257 | #endif 258 | } 259 | 260 | ~i2c_nfc_device() 261 | { 262 | if (_fd >= 0) 263 | ::close(_fd); 264 | } 265 | 266 | #if defined(XINFC_DUMMY_OUT) 267 | void print_rdwr(const i2c_rdwr_ioctl_data& rdwr) 268 | { 269 | for (unsigned int i = 0; i < rdwr.nmsgs; i++) 270 | { 271 | const auto& msg = rdwr.msgs[i]; 272 | const auto rd = (msg.flags & I2C_M_RD) != 0; 273 | 274 | std::stringstream ss; 275 | 276 | ss << (rd ? "read " : "write ") << msg.len 277 | << (rd ? " from " : " to ") << "0x" << std::hex 278 | << std::setfill('0') << std::setw(2) << msg.addr 279 | << (rd ? " to " : " from ") << std::setw(8) << (void*)msg.buf; 280 | 281 | if (!rd) 282 | { 283 | for (int i = 0; i < msg.len; i++) 284 | ss << " 0x" << std::setw(2) << (int)msg.buf[i]; 285 | } 286 | 287 | std::cerr << ss.str() << std::endl; 288 | } 289 | } 290 | #endif 291 | }; 292 | 293 | } 294 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /src/xinfc-wsc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Caian Benedicto 3 | * 4 | * This file is part of xinfc. 5 | * 6 | * xinfc is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2, or (at your option) 9 | * any later version. 10 | * 11 | * xinfc is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with xinfc. If not, see . 18 | */ 19 | 20 | #include "i2c_nfc_device.hpp" 21 | #include "version.hpp" 22 | #include "wifi.hpp" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | int parse_i2c_address(const std::string&); 31 | bool select_encryption_mode(const std::string&, xinfc::wifi_crypt&, 32 | xinfc::wifi_auth&); 33 | int apply_config(const std::string&, int, const std::string&, 34 | const std::string&, const xinfc::wifi_crypt&, const xinfc::wifi_auth&); 35 | size_t make_wsc_ndef(const std::string&, const std::string&, 36 | const xinfc::wifi_crypt&, const xinfc::wifi_auth&, unsigned char*, size_t); 37 | void print_usage(); 38 | 39 | int main(int argc, const char* argv[]) 40 | { 41 | using namespace xinfc; 42 | 43 | std::cerr << "xinfc version " << XINFC_VERSION << std::endl; 44 | 45 | if (argc != 6) 46 | { 47 | print_usage(); 48 | exit(1); 49 | } 50 | 51 | const std::string i2cbus = argv[1]; 52 | const std::string i2caddr_s = argv[2]; 53 | const std::string ssid = argv[3]; 54 | const std::string pass = argv[4]; 55 | const std::string mode = argv[5]; 56 | 57 | if (i2cbus.size() != 1) 58 | { 59 | std::cerr 60 | << "Error: Invalid i2c bus parameter!" 61 | << std::endl; 62 | 63 | exit(1); 64 | } 65 | 66 | const int i2caddr = parse_i2c_address(i2caddr_s); 67 | 68 | std::cerr << "I2c device address is " << i2caddr << "." << std::endl; 69 | 70 | if (i2caddr <= 0) 71 | { 72 | exit(2); 73 | } 74 | 75 | if (ssid.size() < wifi_lenghts::ssid_min || ssid.size() > wifi_lenghts::ssid_max) 76 | { 77 | std::cerr 78 | << "Error: ssid must have between " << wifi_lenghts::ssid_min 79 | << " and " << wifi_lenghts::ssid_max << " characters!" 80 | << std::endl; 81 | 82 | exit(3); 83 | } 84 | 85 | if (pass.size() < wifi_lenghts::pass_min || pass.size() > wifi_lenghts::pass_max) 86 | { 87 | std::cerr 88 | << "Error: password must have between " << wifi_lenghts::pass_min 89 | << " and " << wifi_lenghts::pass_max << " characters!" 90 | << std::endl; 91 | 92 | exit(4); 93 | } 94 | 95 | wifi_crypt crypt; 96 | wifi_auth auth; 97 | 98 | if (!select_encryption_mode(mode, crypt, auth)) 99 | { 100 | exit(5); 101 | } 102 | 103 | try 104 | { 105 | int r = apply_config(i2cbus, i2caddr, ssid, pass, crypt, auth); 106 | 107 | return r; 108 | } 109 | catch(const char* msg) 110 | { 111 | std::cerr 112 | << "Error: " << msg << "!" 113 | << std::endl; 114 | } 115 | catch(const xinfc::i2c_error& error) 116 | { 117 | std::cerr 118 | << "Error: " << error.msg << "! ret=" << error.ret 119 | << " errno=" << error.eno 120 | << std::endl; 121 | } 122 | 123 | return 20; 124 | } 125 | 126 | int apply_config( 127 | const std::string& i2cbus, 128 | int i2caddr, 129 | const std::string& ssid, 130 | const std::string& pass, 131 | const xinfc::wifi_crypt& crypt, 132 | const xinfc::wifi_auth& auth 133 | ) 134 | { 135 | std::cerr << "Opening i2c bus " << i2cbus << "..." << std::endl; 136 | 137 | xinfc::i2c_nfc_device device(i2cbus, i2caddr); 138 | 139 | std::cerr << "Setting i2c timeout..." << std::endl; 140 | 141 | device.set_timeout(3); 142 | 143 | std::cerr << "Setting i2c retries..." << std::endl; 144 | 145 | device.set_retries(2); 146 | 147 | std::cerr << "Setting i2c device address " << i2caddr << "..." << std::endl; 148 | 149 | device.set_device_address((unsigned char)i2caddr); 150 | 151 | std::cerr << "I2c device address set." << std::endl; 152 | 153 | /////////////////////////////////////////////////////// 154 | 155 | const std::string backup_filename = "nfc_ndef_backup.bin"; 156 | 157 | unsigned char ndef_rbuf[xinfc::i2c_nfc_device::max_ndef_buf_size]; 158 | unsigned char ndef_wbuf[xinfc::i2c_nfc_device::max_ndef_buf_size]; 159 | 160 | std::cerr << "Reading existing NDEF data..." << std::endl; 161 | 162 | device.read_ndef(ndef_rbuf, sizeof(ndef_rbuf)); 163 | 164 | std::cerr << "Read " << sizeof(ndef_rbuf) << " bytes." << std::endl; 165 | 166 | const auto backup_fd = open(backup_filename.c_str(), 167 | O_EXCL | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 168 | 169 | if (backup_fd < 0) 170 | { 171 | if (errno != EEXIST) 172 | { 173 | std::cerr 174 | << "Cannot open " << backup_filename 175 | << "! errno=" << errno 176 | << std::endl; 177 | 178 | return 11; 179 | } 180 | 181 | std::cerr << "Backup file found. Skipping backup..." << std::endl; 182 | } 183 | else 184 | { 185 | std::cerr 186 | << "Stock chip data backup not found. Backing up..." 187 | << std::endl; 188 | 189 | const auto to_write = sizeof(ndef_rbuf); 190 | const auto written = write(backup_fd, ndef_rbuf, sizeof(ndef_rbuf)); 191 | const auto eno = errno; 192 | 193 | close(backup_fd); 194 | 195 | if (written != (ssize_t)to_write) 196 | { 197 | std::cerr 198 | << "Cannot write to " << backup_filename 199 | << "! errno=" << eno 200 | << std::endl; 201 | 202 | return 12; 203 | } 204 | 205 | std::cerr << "Backup complete." << std::endl; 206 | } 207 | 208 | //////////////////////////////////////////////////////////////// 209 | 210 | std::cerr << "Building new NDEF data..." << std::endl; 211 | 212 | const size_t size = make_wsc_ndef(ssid, pass, crypt, 213 | auth, ndef_wbuf, sizeof(ndef_wbuf)); 214 | 215 | std::cerr << "New NDEF is " << size << " bytes." << std::endl; 216 | 217 | //////////////////////////////////////////////////////////////// 218 | 219 | const int max_retries = 5; 220 | int retries = 0; 221 | 222 | for (retries = 0; retries < max_retries; retries++) 223 | { 224 | std::cerr << "Writing new NDEF data..." << std::endl; 225 | 226 | const unsigned int max_bytes = 4; 227 | 228 | for (unsigned int i = 0; i < size; i += max_bytes) 229 | { 230 | const unsigned int s = std::min(max_bytes, 231 | (unsigned int)size - i); 232 | 233 | const int max_w_retries = 5; 234 | unsigned int w_retries = 0; 235 | 236 | for (w_retries = 0; w_retries <= max_w_retries; w_retries++) 237 | { 238 | try 239 | { 240 | device.write_ndef_at(ndef_wbuf + i, s, i); 241 | 242 | break; 243 | } 244 | catch(const xinfc::i2c_error& error) 245 | { 246 | if (w_retries == max_w_retries) 247 | { 248 | std::cerr << std::endl; 249 | 250 | throw; 251 | } 252 | 253 | std::cerr << "x"; 254 | 255 | // The i2c line / device sometimes hang 256 | // TODO tune timeout/retries ioctl? 257 | usleep(20000); 258 | } 259 | } 260 | 261 | std::cerr << "."; 262 | } 263 | 264 | std::cerr << std::endl; 265 | 266 | usleep(1000000); 267 | 268 | std::cerr << "Verifying written NDEF data..." << std::endl; 269 | 270 | { 271 | memset(ndef_rbuf, 0, size); 272 | 273 | const unsigned int aligned_size = (((size - 1) / 4) + 1) * 4; 274 | 275 | const int max_w_retries = 20; 276 | unsigned int w_retries = 0; 277 | 278 | for (w_retries = 0; w_retries <= max_w_retries; w_retries++) 279 | { 280 | try 281 | { 282 | device.read_ndef(ndef_rbuf, aligned_size); 283 | 284 | break; 285 | } 286 | catch(const xinfc::i2c_error& error) 287 | { 288 | if (w_retries == max_w_retries) 289 | { 290 | std::cerr << std::endl; 291 | 292 | throw; 293 | } 294 | 295 | // The i2c line / device sometimes hang 296 | // TODO tune timeout/retries ioctl? 297 | usleep(40000); 298 | } 299 | } 300 | 301 | if (std::equal(ndef_wbuf, ndef_wbuf + size, ndef_rbuf)) 302 | { 303 | std::cerr << "Success." << std::endl; 304 | 305 | break; 306 | } 307 | } 308 | 309 | std::cerr << "Data does not match! Retrying..." << std::endl; 310 | } 311 | 312 | if (retries == max_retries) 313 | { 314 | throw "failed to write new NDEF data"; 315 | } 316 | 317 | return 0; 318 | } 319 | 320 | size_t make_wsc_ndef( 321 | const std::string& ssid, 322 | const std::string& pass, 323 | const xinfc::wifi_crypt& crypt, 324 | const xinfc::wifi_auth& auth, 325 | unsigned char* buf, 326 | size_t max_size 327 | ) 328 | { 329 | const char ndef_app[] = "application/vnd.wfa.wsc"; 330 | 331 | if (69 + ssid.size() + pass.size() > max_size) 332 | return 0; 333 | 334 | const auto payload_len = 35 + ssid.size() + pass.size(); 335 | 336 | size_t i = 0; 337 | 338 | buf[i++] = 0x03; 339 | buf[i++] = 30 + payload_len; 340 | buf[i++] = 0xd2; buf[i++] = 0x17; 341 | buf[i++] = 4 + payload_len; 342 | 343 | for (unsigned int j = 0; j < sizeof(ndef_app) - 1; j++) 344 | buf[i++] = ndef_app[j]; 345 | 346 | buf[i++] = 0x10; buf[i++] = 0x0e; // NDEF credential tag 347 | buf[i++] = (payload_len >> 8) & 0xFF; // payload length 348 | buf[i++] = payload_len & 0xFF; // payload length 349 | buf[i++] = 0x10; buf[i++] = 0x26; // NDEF network idx tag 350 | buf[i++] = 0x00; buf[i++] = 0x01; // network idx length 351 | buf[i++] = 0x01; // network idx (always 1) 352 | buf[i++] = 0x10; buf[i++] = 0x45; // NDEF network name tag 353 | buf[i++] = (ssid.size() >> 8) & 0xFF; // ssid length 354 | buf[i++] = ssid.size() & 0xFF; // ssid length 355 | 356 | for (unsigned int j = 0; j < ssid.size(); j++) 357 | buf[i++] = ssid[j]; 358 | 359 | buf[i++] = 0x10; buf[i++] = 0x03; // NDEF auth type tag 360 | buf[i++] = 0x00; buf[i++] = 0x02; // auth type length 361 | buf[i++] = (auth >> 8) & 0xFF; // auth 362 | buf[i++] = auth & 0xFF; // auth 363 | buf[i++] = 0x10; buf[i++] = 0x0f; // NDEF crypt type tag 364 | buf[i++] = 0x00; buf[i++] = 0x02; // crypt type length 365 | buf[i++] = (crypt >> 8) & 0xFF; // crypt 366 | buf[i++] = crypt & 0xFF; // crypt 367 | buf[i++] = 0x10; buf[i++] = 0x27; // NDEF network key tag 368 | buf[i++] = (pass.size() >> 8) & 0xFF; // pass length 369 | buf[i++] = pass.size() & 0xFF; // pass length 370 | 371 | for (unsigned int j = 0; j < pass.size(); j++) 372 | buf[i++] = pass[j]; 373 | 374 | buf[i++] = 0x10; buf[i++] = 0x20; // NDEF mac address tag 375 | buf[i++] = 0x00; buf[i++] = 0x06; // mac address length 376 | buf[i++] = 0xFF; buf[i++] = 0xFF; // mac address 377 | buf[i++] = 0xFF; buf[i++] = 0xFF; // mac address 378 | buf[i++] = 0xFF; buf[i++] = 0xFF; // mac address 379 | buf[i++] = 0xFE; 380 | 381 | return i; 382 | } 383 | 384 | int parse_i2c_address( 385 | const std::string& saddr 386 | ) 387 | { 388 | if (saddr.size() != 4 || saddr[0] != '0' || 389 | (saddr[1] != 'x' && saddr[1] != 'X')) 390 | { 391 | std::cerr 392 | << "Error: Invalid i2c device!" 393 | << std::endl; 394 | 395 | return -1; 396 | } 397 | 398 | int addr = 0; 399 | 400 | for (int i = 0; i < 2; i++) 401 | { 402 | int c = (int)saddr[2 + i]; 403 | 404 | if (c >= '0' && c <= '9') c = c - (int)'0'; 405 | else if (c >= 'a' && c <= 'f') c = c - (int)'a' + 10; 406 | else if (c >= 'A' && c <= 'F') c = c - (int)'A' + 10; 407 | else 408 | { 409 | std::cerr 410 | << "Error: Invalid i2c device!" 411 | << std::endl; 412 | 413 | return -2; 414 | } 415 | 416 | addr = (addr << 4) + c; 417 | } 418 | 419 | return addr; 420 | } 421 | 422 | bool select_encryption_mode( 423 | const std::string& mode, 424 | xinfc::wifi_crypt& out_crypt, 425 | xinfc::wifi_auth& out_auth 426 | ) 427 | { 428 | using namespace xinfc; 429 | 430 | if (mode == wifi_str::none()) 431 | { 432 | out_crypt = wifi_crypt_none; 433 | out_auth = wifi_auth_open; 434 | return true; 435 | } 436 | 437 | if (mode == wifi_str::sae()) 438 | { 439 | std::cerr 440 | << "Error: WPA3 encryption modes not supported!" 441 | << std::endl; 442 | 443 | return false; 444 | } 445 | 446 | if (mode == wifi_str::sae_mixed()) 447 | { 448 | std::cerr 449 | << "Warning: Mixed WPA2/WPA3 will be announced as WPA2!" 450 | << std::endl; 451 | 452 | out_crypt = wifi_crypt_aes; 453 | out_auth = wifi_auth_wpa2_personal; 454 | return true; 455 | } 456 | 457 | if (mode == wifi_str::psk2_tkip_ccmp()) 458 | { 459 | out_crypt = wifi_crypt_tkip_aes; 460 | out_auth = wifi_auth_wpa2_personal; 461 | return true; 462 | } 463 | 464 | if (mode == wifi_str::psk2_tkip_aes()) 465 | { 466 | out_crypt = wifi_crypt_tkip_aes; 467 | out_auth = wifi_auth_wpa2_personal; 468 | return true; 469 | } 470 | 471 | if (mode == wifi_str::psk2_tkip()) 472 | { 473 | out_crypt = wifi_crypt_tkip; 474 | out_auth = wifi_auth_wpa2_personal; 475 | return true; 476 | } 477 | 478 | if (mode == wifi_str::psk2_ccmp()) 479 | { 480 | out_crypt = wifi_crypt_aes; 481 | out_auth = wifi_auth_wpa2_personal; 482 | return true; 483 | } 484 | 485 | if (mode == wifi_str::psk2_aes()) 486 | { 487 | out_crypt = wifi_crypt_aes; 488 | out_auth = wifi_auth_wpa2_personal; 489 | return true; 490 | } 491 | 492 | if (mode == wifi_str::psk2()) 493 | { 494 | out_crypt = wifi_crypt_aes; 495 | out_auth = wifi_auth_wpa2_personal; 496 | return true; 497 | } 498 | 499 | if (mode == wifi_str::psk_tkip_ccmp()) 500 | { 501 | out_crypt = wifi_crypt_tkip_aes; 502 | out_auth = wifi_auth_wpa_personal; 503 | return true; 504 | } 505 | 506 | if (mode == wifi_str::psk_tkip_aes()) 507 | { 508 | out_crypt = wifi_crypt_tkip_aes; 509 | out_auth = wifi_auth_wpa_personal; 510 | return true; 511 | } 512 | 513 | if (mode == wifi_str::psk_tkip()) 514 | { 515 | out_crypt = wifi_crypt_tkip; 516 | out_auth = wifi_auth_wpa_personal; 517 | return true; 518 | } 519 | 520 | if (mode == wifi_str::psk_ccmp()) 521 | { 522 | out_crypt = wifi_crypt_aes; 523 | out_auth = wifi_auth_wpa_personal; 524 | return true; 525 | } 526 | 527 | if (mode == wifi_str::psk_aes()) 528 | { 529 | out_crypt = wifi_crypt_aes; 530 | out_auth = wifi_auth_wpa_personal; 531 | return true; 532 | } 533 | 534 | if (mode == wifi_str::psk()) 535 | { 536 | out_crypt = wifi_crypt_aes; 537 | out_auth = wifi_auth_wpa_personal; 538 | return true; 539 | } 540 | 541 | if (mode == wifi_str::psk_mixed_tkip_ccmp()) 542 | { 543 | out_crypt = wifi_crypt_tkip_aes; 544 | out_auth = wifi_auth_wpa_wpa2_personal; 545 | return true; 546 | } 547 | 548 | if (mode == wifi_str::psk_mixed_tkip_aes()) 549 | { 550 | out_crypt = wifi_crypt_tkip_aes; 551 | out_auth = wifi_auth_wpa_wpa2_personal; 552 | return true; 553 | } 554 | 555 | if (mode == wifi_str::psk_mixed_tkip()) 556 | { 557 | out_crypt = wifi_crypt_tkip; 558 | out_auth = wifi_auth_wpa_wpa2_personal; 559 | return true; 560 | } 561 | 562 | if (mode == wifi_str::psk_mixed_ccmp()) 563 | { 564 | out_crypt = wifi_crypt_aes; 565 | out_auth = wifi_auth_wpa_wpa2_personal; 566 | return true; 567 | } 568 | 569 | if (mode == wifi_str::psk_mixed_aes()) 570 | { 571 | out_crypt = wifi_crypt_aes; 572 | out_auth = wifi_auth_wpa_wpa2_personal; 573 | return true; 574 | } 575 | 576 | if (mode == wifi_str::psk_mixed()) 577 | { 578 | out_crypt = wifi_crypt_aes; 579 | out_auth = wifi_auth_wpa_wpa2_personal; 580 | return true; 581 | } 582 | 583 | if (mode == wifi_str::wep()) 584 | { 585 | out_crypt = wifi_crypt_wep; 586 | out_auth = wifi_auth_open; 587 | return true; 588 | } 589 | 590 | if (mode == wifi_str::wep_open()) 591 | { 592 | out_crypt = wifi_crypt_wep; 593 | out_auth = wifi_auth_open; 594 | return true; 595 | } 596 | 597 | if (mode == wifi_str::wep_shared()) 598 | { 599 | out_crypt = wifi_crypt_wep; 600 | out_auth = wifi_auth_shared; 601 | return true; 602 | } 603 | 604 | if (mode == wifi_str::wpa3()) 605 | { 606 | std::cerr 607 | << "Error: WPA3 encryption modes not supported!" 608 | << std::endl; 609 | 610 | return false; 611 | } 612 | 613 | if (mode == wifi_str::wpa3_mixed()) 614 | { 615 | std::cerr 616 | << "Warning: Mixed WPA2/WPA3 will be announced as WPA2!" 617 | << std::endl; 618 | 619 | out_crypt = wifi_crypt_aes; 620 | out_auth = wifi_auth_wpa2_enterprise; 621 | return true; 622 | } 623 | 624 | if (mode == wifi_str::wpa2_tkip_ccmp()) 625 | { 626 | out_crypt = wifi_crypt_tkip_aes; 627 | out_auth = wifi_auth_wpa2_enterprise; 628 | return true; 629 | } 630 | 631 | if (mode == wifi_str::wpa2_tkip_aes()) 632 | { 633 | out_crypt = wifi_crypt_tkip_aes; 634 | out_auth = wifi_auth_wpa2_enterprise; 635 | return true; 636 | } 637 | 638 | if (mode == wifi_str::wpa2_ccmp()) 639 | { 640 | out_crypt = wifi_crypt_aes; 641 | out_auth = wifi_auth_wpa2_enterprise; 642 | return true; 643 | } 644 | 645 | if (mode == wifi_str::wpa2_aes()) 646 | { 647 | out_crypt = wifi_crypt_aes; 648 | out_auth = wifi_auth_wpa2_enterprise; 649 | return true; 650 | } 651 | 652 | if (mode == wifi_str::wpa2()) 653 | { 654 | out_crypt = wifi_crypt_aes; 655 | out_auth = wifi_auth_wpa2_enterprise; 656 | return true; 657 | } 658 | 659 | if (mode == wifi_str::wpa2_tkip()) 660 | { 661 | out_crypt = wifi_crypt_tkip; 662 | out_auth = wifi_auth_wpa2_enterprise; 663 | return true; 664 | } 665 | 666 | if (mode == wifi_str::wpa_tkip_ccmp()) 667 | { 668 | out_crypt = wifi_crypt_tkip_aes; 669 | out_auth = wifi_auth_wpa_enterprise; 670 | return true; 671 | } 672 | 673 | if (mode == wifi_str::wpa_tkip_aes()) 674 | { 675 | out_crypt = wifi_crypt_tkip_aes; 676 | out_auth = wifi_auth_wpa_enterprise; 677 | return true; 678 | } 679 | 680 | if (mode == wifi_str::wpa_ccmp()) 681 | { 682 | out_crypt = wifi_crypt_aes; 683 | out_auth = wifi_auth_wpa_enterprise; 684 | return true; 685 | } 686 | 687 | if (mode == wifi_str::wpa_aes()) 688 | { 689 | out_crypt = wifi_crypt_aes; 690 | out_auth = wifi_auth_wpa_enterprise; 691 | return true; 692 | } 693 | 694 | if (mode == wifi_str::wpa_tkip()) 695 | { 696 | out_crypt = wifi_crypt_tkip; 697 | out_auth = wifi_auth_wpa_enterprise; 698 | return true; 699 | } 700 | 701 | if (mode == wifi_str::wpa()) 702 | { 703 | out_crypt = wifi_crypt_aes; 704 | out_auth = wifi_auth_wpa_enterprise; 705 | return true; 706 | } 707 | 708 | if (mode == wifi_str::wpa_mixed_tkip_ccmp()) 709 | { 710 | std::cerr 711 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 712 | << std::endl; 713 | 714 | out_crypt = wifi_crypt_tkip_aes; 715 | out_auth = wifi_auth_wpa2_enterprise; 716 | return true; 717 | } 718 | 719 | if (mode == wifi_str::wpa_mixed_tkip_aes()) 720 | { 721 | std::cerr 722 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 723 | << std::endl; 724 | 725 | out_crypt = wifi_crypt_tkip_aes; 726 | out_auth = wifi_auth_wpa2_enterprise; 727 | return true; 728 | } 729 | 730 | if (mode == wifi_str::wpa_mixed_tkip()) 731 | { 732 | std::cerr 733 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 734 | << std::endl; 735 | 736 | out_crypt = wifi_crypt_tkip; 737 | out_auth = wifi_auth_wpa2_enterprise; 738 | return true; 739 | } 740 | 741 | if (mode == wifi_str::wpa_mixed_ccmp()) 742 | { 743 | std::cerr 744 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 745 | << std::endl; 746 | 747 | out_crypt = wifi_crypt_aes; 748 | out_auth = wifi_auth_wpa2_enterprise; 749 | return true; 750 | } 751 | 752 | if (mode == wifi_str::wpa_mixed_aes()) 753 | { 754 | std::cerr 755 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 756 | << std::endl; 757 | 758 | out_crypt = wifi_crypt_aes; 759 | out_auth = wifi_auth_wpa2_enterprise; 760 | return true; 761 | } 762 | 763 | if (mode == wifi_str::wpa_mixed()) 764 | { 765 | std::cerr 766 | << "Warning: Mixed WPA/WPA2 will be announced as WPA2!" 767 | << std::endl; 768 | 769 | out_crypt = wifi_crypt_aes; 770 | out_auth = wifi_auth_wpa2_enterprise; 771 | return true; 772 | } 773 | 774 | if (mode == wifi_str::owe()) 775 | { 776 | std::cerr 777 | << "Error: OWE mode not supported!" 778 | << std::endl; 779 | 780 | return false; 781 | } 782 | 783 | std::cerr 784 | << "Error: unknown encryption mode!" 785 | << std::endl; 786 | 787 | return false; 788 | } 789 | 790 | void print_usage() 791 | { 792 | using namespace xinfc; 793 | 794 | std::cerr 795 | << "USAGE: xinfcw i2c-bus i2c-device ssid password mode" << std::endl 796 | << " i2c-device must be a hex byte in the format 0xMN" << std::endl 797 | << " ssid must have between " << wifi_lenghts::ssid_min 798 | << " and " << wifi_lenghts::ssid_max << " characters." << std::endl 799 | << " password must have between " << wifi_lenghts::pass_min 800 | << " and " << wifi_lenghts::pass_max << " characters." << std::endl 801 | << " mode must be one of the following:" << std::endl 802 | << " " << wifi_str::none() << std::endl 803 | << " " << wifi_str::sae_mixed() << std::endl 804 | << " " << wifi_str::psk2_tkip_ccmp() << std::endl 805 | << " " << wifi_str::psk2_tkip_aes() << std::endl 806 | << " " << wifi_str::psk2_tkip() << std::endl 807 | << " " << wifi_str::psk2_ccmp() << std::endl 808 | << " " << wifi_str::psk2_aes() << std::endl 809 | << " " << wifi_str::psk2() << std::endl 810 | << " " << wifi_str::psk_tkip_ccmp() << std::endl 811 | << " " << wifi_str::psk_tkip_aes() << std::endl 812 | << " " << wifi_str::psk_tkip() << std::endl 813 | << " " << wifi_str::psk_ccmp() << std::endl 814 | << " " << wifi_str::psk_aes() << std::endl 815 | << " " << wifi_str::psk() << std::endl 816 | << " " << wifi_str::psk_mixed_tkip_ccmp() << std::endl 817 | << " " << wifi_str::psk_mixed_tkip_aes() << std::endl 818 | << " " << wifi_str::psk_mixed_tkip() << std::endl 819 | << " " << wifi_str::psk_mixed_ccmp() << std::endl 820 | << " " << wifi_str::psk_mixed_aes() << std::endl 821 | << " " << wifi_str::psk_mixed() << std::endl 822 | << " " << wifi_str::wep() << std::endl 823 | << " " << wifi_str::wep_open() << std::endl 824 | << " " << wifi_str::wep_shared() << std::endl 825 | << " " << wifi_str::wpa3_mixed() << std::endl 826 | << " " << wifi_str::wpa2_tkip_ccmp() << std::endl 827 | << " " << wifi_str::wpa2_tkip_aes() << std::endl 828 | << " " << wifi_str::wpa2_ccmp() << std::endl 829 | << " " << wifi_str::wpa2_aes() << std::endl 830 | << " " << wifi_str::wpa2() << std::endl 831 | << " " << wifi_str::wpa2_tkip() << std::endl 832 | << " " << wifi_str::wpa_tkip_ccmp() << std::endl 833 | << " " << wifi_str::wpa_tkip_aes() << std::endl 834 | << " " << wifi_str::wpa_ccmp() << std::endl 835 | << " " << wifi_str::wpa_aes() << std::endl 836 | << " " << wifi_str::wpa_tkip() << std::endl 837 | << " " << wifi_str::wpa() << std::endl 838 | << " " << wifi_str::wpa_mixed_tkip_ccmp() << std::endl 839 | << " " << wifi_str::wpa_mixed_tkip_aes() << std::endl 840 | << " " << wifi_str::wpa_mixed_tkip() << std::endl 841 | << " " << wifi_str::wpa_mixed_ccmp() << std::endl 842 | << " " << wifi_str::wpa_mixed_aes() << std::endl 843 | << " " << wifi_str::wpa_mixed() << std::endl; 844 | } 845 | --------------------------------------------------------------------------------