WireGuard Implementation for ESP-IDF

Overview

esp_wireguard, WireGuard Implementation for ESP-IDF

This is an implementation of the WireGuard® for ESP-IDF, based on WireGuard Implementation for lwIP.

Build examples

Status

The code is alpha.

A single tunnel to a WireGuard peer has been working.

Supported ESP-IDF versions and targets

The following ESP-IDF versions are supported:

  • esp-idf master
  • esp-idf v4.2.x
  • esp-idf v4.3.x
  • ESP8266 RTOS SDK v3.4

The following targets are supported:

  • esp32
  • esp32s2
  • esp32c3
  • esp8266

Usage

In menuconfig under WireGuard, choose a TCP/IP adapter. The default is ESP-NETIF. SDKs older than esp-idf v4.1, including ESP8266 RTOS SDK v3.4 requires TCP/IP Adapter.

Both peers must have synced time. The library does not sync time.

A working network interface is required.

Create WireGuard configuration, wireguard_config_t. Use ESP_WIREGUARD_CONFIG_DEFAULT to initialize wireguard_config_t variable. Create wireguard_ctx_t. Pass the variables to esp_wireguard_init(). Then, call esp_wireguard_connect(). Call esp_wireguard_disconnect() to disconnect from the peer (and destroy the WireGuard interface).

#include <esp_wireguard.h>

esp_err_t err = ESP_FAIL;

wireguard_config_t wg_config = ESP_WIREGUARD_CONFIG_DEFAULT();

wg_config.private_key = CONFIG_WG_PRIVATE_KEY;
wg_config.listen_port = CONFIG_WG_LOCAL_PORT;
wg_config.public_key = CONFIG_WG_PEER_PUBLIC_KEY;
wg_config.allowed_ip = CONFIG_WG_LOCAL_IP_ADDRESS;
wg_config.allowed_ip_mask = CONFIG_WG_LOCAL_IP_NETMASK;
wg_config.endpoint = CONFIG_WG_PEER_ADDRESS;
wg_config.port = CONFIG_WG_PEER_PORT;

/* If the device is behind NAT or stateful firewall, set persistent_keepalive.
   persistent_keepalive is disabled by default */
// wg_config.persistent_keepalive = 10;

wireguard_ctx_t ctx = {0};
err = esp_wireguard_init(&wg_config, &ctx);
err = esp_wireguard_connect(ctx);

/* do something */

err = esp_wireguard_disconnect(&ctx);

See examples at examples.

IPv6 support

Enable CONFIG_LWIP_IPV6 under lwip component in menuconfig.

IPv6 support is alpha and probably broken. See also Known issues.

Known issues

The implementation uses LwIP as TCP/IP protocol stack.

IPv6 support is not tested. Dual stack (IPv4 and IPv6) is not supported (see Issue #5). The first address of endpoint is used to choose IPv4 or IPv6 as a transport. The chosen transport must be available and usable.

The library assumes the interface is WiFi interface. Ethernet is not supported.

Older esp-idf versions with TCP/IP Adapter, such as v4.1.x, should work, but there are others issues, not directly related to the library.

License

BSD 3-Clause "New" or "Revised" License (SPDX ID: BSD-3-Clause). See LICENSE for details.

Authors

Issues
  • persistent keepalives should be off by default

    persistent keepalives should be off by default

    https://www.wireguard.com/quickstart/#nat-and-firewall-traversal-persistence

    This is called persistent keepalives. When this option is enabled, a keepalive packet is sent to the server endpoint once every interval seconds. A sensible interval that works with a wide variety of firewalls is 25 seconds. Setting it to 0 turns the feature off, which is the default, since most users will not need this, and it makes WireGuard slightly more chatty.

    opened by trombik 0
  • the driver does not support changes in DNS records

    the driver does not support changes in DNS records

    the original WireGuard implementation resolves DNS name of peer endpoint once at startup. it does not re-resolve the DNS name. the developer said "it's not a bug". a script, reresolve-dns, to "refresh" addresses is provided for Un*x machines. i believe this behavior is not part of the spec, but other implementations, including the upstream and OpenBSD's wg(4) for example, do the same. One implementation supports DNS resolution in its driver (DNS Updates to WireGuard Endpoints | Pro Custodibus).

    opened by trombik 0
Owner
Tomoyuki Sakurai
Founder of Makers Siem Reap. PGP finger print: 03EB 3D97 5E04 9B0C AB21 93A2 D693 42A9 EFBC 3577 https://github.com/trombik.gpg
Tomoyuki Sakurai
idf.py.exe, wrapper tool to invoke idf.py on Windows

IDF wrapper tool (idf.py.exe) This tools helps invoke idf.py in Windows CMD shell. In Windows CMD shell, python scripts can be executed directly (by t

Espressif Systems 3 Dec 13, 2021
An Arduino wrapper to @sdima1357's usb_soft_host esp-idf example

ESP32 USB Soft Host library for Arduino IDE This is mainly a wrapper around the excellent work of Dmitry Samsonov (@sdima1357) with esp32_usb_soft_hos

tobozo 102 Jun 19, 2022
GFX Demo for the ESP-IDF

Display Drivers and Demo for GFX This is a Demo of GFX With Several Display Drivers This is not GFX itself, but it includes it. GFX Documentation is b

honey the codewitch 61 May 17, 2022
ESP32 S2 C++ host library compatible with arduino, esp-idf.

Info I would like to announce USB host library for esp32 S2 compatible with arduino, esp-idf and PIO (when pio will be updated to most recent esp-idf)

null 15 Jun 2, 2022
To simplify the development of ESP32 in ESP-IDF, Easyio provides a complete driver library

Easyio 开源驱动库 Easyio 是一款适配于ESP-IDF框架的开源驱动库,以支持ESP32的简便开发。目的是简化乐鑫ESP-IDF开发框架的使用难度。(真要方便的话,有现成的Arduino和Platform可以用,不过实在迫于工作要求,有的开源东西不让用,同时便于对接FAE,于是就有了 E

null 161 Jun 21, 2022
使用ESP-IDF、ESP-ADF、LVGL等库,基于ESP32S2实现简单的网络收音机和FM收音机功能。

【电子森林项目】网络收音机/FM收音机 这个项目是报名《硬禾“暑期一起练”第3个平台 - 基于ESP32-S2模块的网络收音机和音频信号处理》所做的。 基本功能: 可以连接WiFi收听HLS协议的网络电台节目 收听空中的FM电台88MHz~108MHz OLED0.96寸显示 四个独立按键控制两种模

DaMi 12 Jun 3, 2022
LVGL8 for ESP-IDF

X-UI LVGL8 for ESP-IDF 移植自X-TRACK项目的页面栈框架,新增支持异步通信的订阅发布数据中心 特点 使用C语言重构,方便继承复用 核心文件 ui_page_manager.h、ui_page_manager.c 实现页面栈、订阅发布数据中心 完整页面生命周期 MVC架构 数

Zing 11 Apr 19, 2022
Additional components for ESP-IDF, maintained by Espressif

Espressif IDF Extra Components This repository aims to store ESP-IDF extra components which have been seperated and uploaded into IDF Component Manage

Espressif Systems 15 Jun 6, 2022
Add tensilica esp32 cpu and a board to qemu and dump the rom to learn more about esp-idf

qemu_esp32 Add tensilica esp32 cpu and a board to qemu and dump the rom to learn more about esp-idf ESP32 in QEMU. This documents how to add an esp32

null 333 Jun 22, 2022
This FreeRTOS example builds a simple Timer application for Linux using the ESP-IDF

Supported Targets Linux This FreeRTOS example builds a simple Timer application for Linux using the ESP-IDF. Build Source the IDF environment as usual

null 13 Apr 4, 2022
SX1276/77/78/79 Low Power Long Range Transceiver driver for esp-idf

esp-idf-sx127x SX1276/77/78/79 Low Power Long Range Transceiver driver for esp-idf. I based on this. Changes from the original Added support for ESP32

null 10 Jun 7, 2022
SX1262//68 Low Power Long Range Transceiver driver for esp-idf

esp-idf-sx126x SX1262//68 Low Power Long Range Transceiver driver for esp-idf. I ported from here. Ai-Thinker offers several LoRa modules. You can get

null 3 May 9, 2022
SI4432 ISM Transceiver driver for esp-idf

esp-idf-si4432 SI4432 ISM Transceiver driver for esp-idf. I refered this. Software requirements esp-idf v4.4 or later. This is because this version su

null 3 May 29, 2022
CC2500 Low-Cost Low-Power 2.4 GHz RF Transceiver driver for esp-idf

esp-idf-cc2500 CC2500 Low-Cost Low-Power 2.4 GHz RF Transceiver driver for esp-idf. I ported from this. 2.00mm pitch External Antena 1.27mm pitch PCB

null 3 May 29, 2022
Collection of additional Ethernet drivers for ESP-IDF

Collection of additional Ethernet drivers for ESP-IDF This repository aims to store additional Ethernet drivers which are not available directly in ES

Espressif Systems 3 May 9, 2022
ESP Insights is a remote diagnostics solution that allows users to remotely monitor the health of ESP devices in the field.

ESP Insights is a remote diagnostics solution that allows users to remotely monitor the health of ESP devices in the field.

Espressif Systems 27 Jun 9, 2022
ESP-32 CAM implementation of a Bird classifier using Arduino IDE

Bird-Classifier ESP-32 CAM implementation of a Bird classifier using Arduino IDE For the file server to run, you also need to have the ESP32 SD File M

null 3 Mar 28, 2022
bsdiff changed to remove bz2, the header and to allow streaming interfaces, to be used on the esp32 with idf as a component

bspatch for esp32 This project adds support for bspatch to the esp32 with some changes: no compression (bz2), no header and changed the interfaces to

Blockstream 8 Apr 26, 2022
A customized LGL Android mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android

PUBG Mobile ESP Mod Menu A customized LGL mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android. Everything are fixed so it works with both

null 42 Mar 19, 2022