start: initial minimal implementation

3 tabs: bitcoin, lightning and settings.
only settings is populated, with wifi info and shutdown.

see build.zig for how everything ties up together.
add-custom-font
alex 2 years ago
parent 68dd23525e
commit bfc71fec92

@ -0,0 +1,5 @@
build for rpi:
zig build -Dtarget=aarch64-linux-musl -Ddriver=fbev -Drelease-safe -Dstrip
otherwise just `zig build` on dev host

@ -1,34 +1,283 @@
const std = @import("std");
const nifbuild = @import("lib/nif/build.zig");
pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
b.use_stage1 = true;
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const strip = b.option(bool, "strip", "strip output binary; default: false") orelse false;
const drv = b.option(DriverTarget, "driver", "display and input drivers combo; default: sdl2") orelse .sdl2;
const disp_horiz = b.option(u32, "horiz", "display horizontal pixels count; default: 800") orelse 800;
const disp_vert = b.option(u32, "vert", "display vertical pixels count; default: 480") orelse 480;
// gui build
const ngui = b.addExecutable("ngui", "src/ngui.zig");
ngui.setTarget(target);
ngui.setBuildMode(mode);
ngui.pie = true;
ngui.strip = strip;
ngui.addIncludePath("lib");
ngui.addIncludePath("src/ui/c");
ngui.linkLibC();
const exe = b.addExecutable("ngui", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
const lvgl_flags = &.{
"-std=c11",
"-fstack-protector",
"-Wall",
"-Wextra",
"-Wformat",
"-Wformat-security",
"-Wundef",
};
ngui.addCSourceFiles(lvgl_generic_src, lvgl_flags);
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
const ngui_cflags: []const []const u8 = &.{
"-std=c11",
"-Wall",
"-Wextra",
"-Wshadow",
"-Wundef",
"-Wunused-parameter",
"-Werror",
};
ngui.addCSourceFiles(&.{
"src/ui/c/ui.c",
"src/ui/c/lv_font_courierprimecode_14.c",
//"src/ui/c/lv_font_courierprimecode_16.c",
"src/ui/c/lv_font_courierprimecode_24.c",
}, ngui_cflags);
ngui.defineCMacroRaw(b.fmt("NM_DISP_HOR={}", .{disp_horiz}));
ngui.defineCMacroRaw(b.fmt("NM_DISP_VER={}", .{disp_vert}));
ngui.defineCMacro("LV_CONF_INCLUDE_SIMPLE", null);
ngui.defineCMacro("LV_TICK_CUSTOM", "1");
ngui.defineCMacro("LV_TICK_CUSTOM_INCLUDE", "\"ui.h\"");
ngui.defineCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())");
switch (drv) {
.sdl2 => {
ngui.addCSourceFiles(lvgl_sdl2_src, lvgl_flags);
ngui.addCSourceFile("src/ui/c/drv_sdl2.c", ngui_cflags);
ngui.defineCMacro("NM_DRV_SDL2", null);
ngui.defineCMacro("USE_SDL", null);
ngui.linkSystemLibrary("SDL2");
},
.fbev => {
ngui.addCSourceFiles(lvgl_fbev_src, lvgl_flags);
ngui.addCSourceFile("src/ui/c/drv_fbev.c", ngui_cflags);
ngui.defineCMacro("NM_DRV_FBEV", null);
ngui.defineCMacro("USE_FBDEV", null);
ngui.defineCMacro("USE_EVDEV", null);
},
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const ngui_build_step = b.step("ngui", "build ngui (nakamochi gui)");
ngui_build_step.dependOn(&b.addInstallArtifact(ngui).step);
// daemon build
const nd = b.addExecutable("nd", "src/nd.zig");
nd.setTarget(target);
nd.setBuildMode(mode);
nd.pie = true;
nd.strip = strip;
nifbuild.addPkg(b, nd, "lib/nif");
const niflib = nifbuild.library(b, "lib/nif");
niflib.setTarget(target);
niflib.setBuildMode(mode);
nd.linkLibrary(niflib);
const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const nd_build_step = b.step("nd", "build nd (nakamochi daemon)");
nd_build_step.dependOn(&b.addInstallArtifact(nd).step);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
// default build
const build_all_step = b.step("all", "build everything");
build_all_step.dependOn(ngui_build_step);
build_all_step.dependOn(nd_build_step);
b.default_step.dependOn(build_all_step);
{
const tests = b.addTest("src/test.zig");
tests.setTarget(target);
tests.setBuildMode(mode);
tests.linkLibC();
if (b.args) |args| {
for (args) |a, i| {
if (std.mem.eql(u8, a, "--test-filter")) {
tests.setFilter(args[i + 1]); // don't care about OOB
break;
}
}
}
const test_step = b.step("test", "run tests");
test_step.dependOn(&tests.step);
}
}
const DriverTarget = enum {
sdl2,
fbev, // framebuffer + evdev
};
const lvgl_sdl2_src: []const []const u8 = &.{
"lib/lv_drivers/sdl/sdl.c",
"lib/lv_drivers/sdl/sdl_common.c",
};
const lvgl_fbev_src: []const []const u8 = &.{
"lib/lv_drivers/display/fbdev.c",
"lib/lv_drivers/indev/evdev.c",
};
const lvgl_generic_src: []const []const u8 = &.{
"lib/lvgl/src/core/lv_disp.c",
"lib/lvgl/src/core/lv_event.c",
"lib/lvgl/src/core/lv_group.c",
"lib/lvgl/src/core/lv_indev.c",
"lib/lvgl/src/core/lv_indev_scroll.c",
"lib/lvgl/src/core/lv_obj.c",
"lib/lvgl/src/core/lv_obj_class.c",
"lib/lvgl/src/core/lv_obj_draw.c",
"lib/lvgl/src/core/lv_obj_pos.c",
"lib/lvgl/src/core/lv_obj_scroll.c",
"lib/lvgl/src/core/lv_obj_style.c",
"lib/lvgl/src/core/lv_obj_style_gen.c",
"lib/lvgl/src/core/lv_obj_tree.c",
"lib/lvgl/src/core/lv_refr.c",
"lib/lvgl/src/core/lv_theme.c",
"lib/lvgl/src/draw/arm2d/lv_gpu_arm2d.c",
"lib/lvgl/src/draw/lv_draw.c",
"lib/lvgl/src/draw/lv_draw_arc.c",
"lib/lvgl/src/draw/lv_draw_img.c",
"lib/lvgl/src/draw/lv_draw_label.c",
"lib/lvgl/src/draw/lv_draw_layer.c",
"lib/lvgl/src/draw/lv_draw_line.c",
"lib/lvgl/src/draw/lv_draw_mask.c",
"lib/lvgl/src/draw/lv_draw_rect.c",
"lib/lvgl/src/draw/lv_draw_transform.c",
"lib/lvgl/src/draw/lv_draw_triangle.c",
"lib/lvgl/src/draw/lv_img_buf.c",
"lib/lvgl/src/draw/lv_img_cache.c",
"lib/lvgl/src/draw/lv_img_decoder.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_arc.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_bg.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_composite.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_img.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_label.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_layer.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_line.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_mask.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_polygon.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_rect.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_stack_blur.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_texture_cache.c",
"lib/lvgl/src/draw/sdl/lv_draw_sdl_utils.c",
"lib/lvgl/src/draw/sw/lv_draw_sw.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_arc.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_blend.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_dither.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_gradient.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_img.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_layer.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_letter.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_line.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_polygon.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_rect.c",
"lib/lvgl/src/draw/sw/lv_draw_sw_transform.c",
"lib/lvgl/src/extra/layouts/flex/lv_flex.c",
"lib/lvgl/src/extra/layouts/grid/lv_grid.c",
"lib/lvgl/src/extra/libs/bmp/lv_bmp.c",
"lib/lvgl/src/extra/libs/ffmpeg/lv_ffmpeg.c",
"lib/lvgl/src/extra/libs/freetype/lv_freetype.c",
"lib/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c",
"lib/lvgl/src/extra/libs/fsdrv/lv_fs_posix.c",
"lib/lvgl/src/extra/libs/fsdrv/lv_fs_stdio.c",
"lib/lvgl/src/extra/libs/fsdrv/lv_fs_win32.c",
"lib/lvgl/src/extra/libs/gif/gifdec.c",
"lib/lvgl/src/extra/libs/gif/lv_gif.c",
"lib/lvgl/src/extra/libs/png/lodepng.c",
"lib/lvgl/src/extra/libs/png/lv_png.c",
"lib/lvgl/src/extra/libs/qrcode/lv_qrcode.c",
"lib/lvgl/src/extra/libs/qrcode/qrcodegen.c",
"lib/lvgl/src/extra/libs/rlottie/lv_rlottie.c",
"lib/lvgl/src/extra/libs/sjpg/lv_sjpg.c",
"lib/lvgl/src/extra/libs/sjpg/tjpgd.c",
"lib/lvgl/src/extra/lv_extra.c",
"lib/lvgl/src/extra/others/fragment/lv_fragment.c",
"lib/lvgl/src/extra/others/fragment/lv_fragment_manager.c",
"lib/lvgl/src/extra/others/gridnav/lv_gridnav.c",
"lib/lvgl/src/extra/others/ime/lv_ime_pinyin.c",
"lib/lvgl/src/extra/others/imgfont/lv_imgfont.c",
"lib/lvgl/src/extra/others/monkey/lv_monkey.c",
"lib/lvgl/src/extra/others/msg/lv_msg.c",
"lib/lvgl/src/extra/others/snapshot/lv_snapshot.c",
"lib/lvgl/src/extra/themes/basic/lv_theme_basic.c",
"lib/lvgl/src/extra/themes/default/lv_theme_default.c",
"lib/lvgl/src/extra/themes/mono/lv_theme_mono.c",
"lib/lvgl/src/extra/widgets/animimg/lv_animimg.c",
"lib/lvgl/src/extra/widgets/calendar/lv_calendar.c",
"lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_arrow.c",
"lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_dropdown.c",
"lib/lvgl/src/extra/widgets/chart/lv_chart.c",
"lib/lvgl/src/extra/widgets/colorwheel/lv_colorwheel.c",
"lib/lvgl/src/extra/widgets/imgbtn/lv_imgbtn.c",
"lib/lvgl/src/extra/widgets/keyboard/lv_keyboard.c",
"lib/lvgl/src/extra/widgets/led/lv_led.c",
"lib/lvgl/src/extra/widgets/list/lv_list.c",
"lib/lvgl/src/extra/widgets/menu/lv_menu.c",
"lib/lvgl/src/extra/widgets/meter/lv_meter.c",
"lib/lvgl/src/extra/widgets/msgbox/lv_msgbox.c",
"lib/lvgl/src/extra/widgets/span/lv_span.c",
"lib/lvgl/src/extra/widgets/spinbox/lv_spinbox.c",
"lib/lvgl/src/extra/widgets/spinner/lv_spinner.c",
"lib/lvgl/src/extra/widgets/tabview/lv_tabview.c",
"lib/lvgl/src/extra/widgets/tileview/lv_tileview.c",
"lib/lvgl/src/extra/widgets/win/lv_win.c",
"lib/lvgl/src/font/lv_font.c",
"lib/lvgl/src/font/lv_font_fmt_txt.c",
"lib/lvgl/src/font/lv_font_loader.c",
"lib/lvgl/src/hal/lv_hal_disp.c",
"lib/lvgl/src/hal/lv_hal_indev.c",
"lib/lvgl/src/hal/lv_hal_tick.c",
"lib/lvgl/src/misc/lv_anim.c",
"lib/lvgl/src/misc/lv_anim_timeline.c",
"lib/lvgl/src/misc/lv_area.c",
"lib/lvgl/src/misc/lv_async.c",
"lib/lvgl/src/misc/lv_bidi.c",
"lib/lvgl/src/misc/lv_color.c",
"lib/lvgl/src/misc/lv_fs.c",
"lib/lvgl/src/misc/lv_gc.c",
"lib/lvgl/src/misc/lv_ll.c",
"lib/lvgl/src/misc/lv_log.c",
"lib/lvgl/src/misc/lv_lru.c",
"lib/lvgl/src/misc/lv_math.c",
"lib/lvgl/src/misc/lv_mem.c",
"lib/lvgl/src/misc/lv_printf.c",
"lib/lvgl/src/misc/lv_style.c",
"lib/lvgl/src/misc/lv_style_gen.c",
"lib/lvgl/src/misc/lv_templ.c",
"lib/lvgl/src/misc/lv_timer.c",
"lib/lvgl/src/misc/lv_tlsf.c",
"lib/lvgl/src/misc/lv_txt.c",
"lib/lvgl/src/misc/lv_txt_ap.c",
"lib/lvgl/src/misc/lv_utils.c",
"lib/lvgl/src/widgets/lv_arc.c",
"lib/lvgl/src/widgets/lv_bar.c",
"lib/lvgl/src/widgets/lv_btn.c",
"lib/lvgl/src/widgets/lv_btnmatrix.c",
"lib/lvgl/src/widgets/lv_canvas.c",
"lib/lvgl/src/widgets/lv_checkbox.c",
"lib/lvgl/src/widgets/lv_dropdown.c",
"lib/lvgl/src/widgets/lv_img.c",
"lib/lvgl/src/widgets/lv_label.c",
"lib/lvgl/src/widgets/lv_line.c",
"lib/lvgl/src/widgets/lv_objx_templ.c",
"lib/lvgl/src/widgets/lv_roller.c",
"lib/lvgl/src/widgets/lv_slider.c",
"lib/lvgl/src/widgets/lv_switch.c",
"lib/lvgl/src/widgets/lv_table.c",
"lib/lvgl/src/widgets/lv_textarea.c",
};

@ -0,0 +1,73 @@
the trouble is fontawesome now supplies multiple files,
fa-brands-400.woff2, fa-regular-400.woff2 and fa-solid-900.woff2.
don't know which symbol is in which file.
list all defined symbols into a file:
grep 0x ../ngui/lib/lvgl/src/font/lv_symbol_def.h | grep -v 0x2022 | \
cut -d, -f2 | cut -c4-7 | tr 'A-F' 'a-f' \
> /tmp/sym.txt
download and unzip fontawesome. expect to find metadata/icons.yml file.
grep metadata to find out which set each icon is in:
for c in $(cat /tmp/sym.txt); do
t=$(grep -B3 "unicode: $c" metadata/icons.yml | grep -- '- ' | head -n1 | tr -d ' -')
echo "$c\t$t"
done
some icons are in multiple styles. search for the code on https://fontawesome.com/icons/
and compare to the image on https://docs.lvgl.io/8.3/overview/font.html.
the command above takes the first one listed in icons.yml, which is usually "solid".
when searching on fontawesome, make sure it's a free icon, as opposed to their pro version.
not all icons might be present. at the time of writing, the following codes are amiss:
- 0xf067 `LV_SYMBOL_PLUS`; actually exists but listed as unicode:2b in icons.yml
- 0xf8a2 `LV_SYMBOL_NEW_LINE`; looks like fontawesome removed `level-down-alt` from v6
so i picked an alternative 0xf177 `arrow-left-long`
dump previous command output into an fa-icon-style.txt file. add missing "solid" style
in the second column and replace f8a2 with `f177=>0xf8a2` mapping. the latter is
the syntax for when running [lvgl font convertion tool](https://github.com/lvgl/lv_font_conv).
while there, add more codes to the file, separating columns with a single tab:
- 0xf379 brands (bitcoin)
- 0xe0b4 solid (bitcoin-sign)
- 0xf0e7 solid (lightning bolt)
split the previously generated fa-icon-style.txt file into chunks suitable for
constructing lvgl's font converter arguments.
first, check which styles are present. at the moment, only "brands" and "solid"
are used:
$ cut -f2 fa-icon-style.txt | sort | uniq -c
3 brands
61 solid
then split the file, for each style from the previous command. example for "solid":
grep solid fa-icon-style.txt | cut -f1 | tr 'a-f' 'A-F' | \
while IFS= read -r line; do printf "0x$line\n"; done | \
paste -s -d, | tr -d '\n' > fa-solid.txt
typically, you'll want to bundle the symbols from fontawesome with a regular font.
i'll use [courier prime code](https://github.com/quoteunquoteapps/courierprimecode)
as an example.
install the font converter tool; requires nodejs:
npm i lvgl/lv_font_conv
finally, convert and bundle all fonts, for 14px size as an example:
./node_modules/.bin/lv_font_conv --no-compress --no-prefilter --bpp 4 --size 14 \
--font courier-prime-code.ttf -r 0x20-0x7F,0xB0,0x2022 \
--font fa-brands-400.ttf -r $(cat fa-brands.txt) \
--font fa-solid-900.ttf -r $(cat fa-solid.txt) \
--format lvgl --force-fast-kern-format \
-o lv_font_courierprimecode_14.c
the arguments are similar to those in the header of any LVGL font in `lib/lvgl/src/font/lv_font/xxx.c`.

@ -0,0 +1,29 @@
const build = @import("std").build;
pub fn addPkg(b: *build.Builder, obj: *build.LibExeObjStep, prefix: []const u8) void {
obj.addPackagePath("nif", pkgPath(b, prefix));
}
pub fn pkgPath(b: *build.Builder, prefix: []const u8) []const u8 {
return b.pathJoin(&.{prefix, "nif.zig"});
}
pub fn library(b: *build.Builder, prefix: []const u8) *build.LibExeObjStep {
const lib = b.addStaticLibrary("nif", b.pathJoin(&.{prefix, "nif.zig"}));
lib.addIncludePath(b.pathJoin(&.{prefix, "wpa_supplicant"}));
lib.defineCMacro("CONFIG_CTRL_IFACE", null);
lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null);
lib.addCSourceFiles(&.{
b.pathJoin(&.{prefix, "wpa_supplicant/wpa_ctrl.c"}),
b.pathJoin(&.{prefix, "wpa_supplicant/os_unix.c"}),
}, &.{
"-Wall",
"-Wextra",
"-Wshadow",
"-Wundef",
"-Wunused-parameter",
"-Werror",
});
lib.linkLibC();
return lib;
}

@ -0,0 +1,63 @@
const std = @import("std");
const mem = std.mem;
const net = std.net;
const os = std.os;
pub const wpa = @import("wpa.zig");
const IFF_UP = 1 << 0; //0b1;
const IFF_LOOPBACK = 1 << 3; //0b1000;
const ifaddrs = extern struct {
next: ?*ifaddrs,
name: [*:0]const u8,
flags: c_uint, // see IFF_xxx SIOCGIFFLAGS in netdevice(7)
addr: ?*std.os.sockaddr,
netmask: ?*std.os.sockaddr,
ifu: extern union {
broad: *os.sockaddr, // flags & IFF_BROADCAST
dst: *os.sockaddr, // flags & IFF_POINTOPOINT
},
data: ?*anyopaque,
};
extern "c" fn getifaddrs(ptrp: **ifaddrs) c_int;
extern "c" fn freeifaddrs(ptr: *ifaddrs) void;
/// retrieves a list of all public IP addresses assigned to the network interfaces,
/// optionally filtering by the interface name.
/// caller owns the returned value.
pub fn pubAddresses(allocator: mem.Allocator, ifname: ?[]const u8) ![]net.Address {
var res: *ifaddrs = undefined;
if (getifaddrs(&res) != 0) {
return error.Getifaddrs;
}
defer freeifaddrs(res);
var list = std.ArrayList(net.Address).init(allocator);
var it: ?*ifaddrs = res;
while (it) |ifa| : (it = ifa.next) {
const sa: *os.sockaddr = ifa.addr orelse continue;
if (sa.family != os.AF.INET and sa.family != os.AF.INET6) {
// not an IP address
continue;
}
if (ifa.flags & IFF_UP == 0 or ifa.flags & IFF_LOOPBACK != 0) {
// skip loopbacks and those which are not "up"
continue;
}
const ipaddr = net.Address.initPosix(@alignCast(4, sa)); // initPosix makes a copy
if (ipaddr.any.family == os.AF.INET6 and ipaddr.in6.sa.scope_id > 0) {
// want only global, with 0 scope
// non-zero scopes make sense for link-local addr only.
continue;
}
if (ifname) |name| {
if (!mem.eql(u8, name, mem.sliceTo(ifa.name, 0))) {
continue;
}
}
try list.append(ipaddr);
}
return list.toOwnedSlice();
}

@ -0,0 +1,384 @@
const std = @import("std");
const mem = std.mem;
const Thread = std.Thread;
const WPACtrl = opaque {};
const WPAReqCallback = *const fn ([*:0]const u8, usize) callconv(.C) void;
extern fn wpa_ctrl_open(ctrl_path: [*:0]const u8) ?*WPACtrl;
extern fn wpa_ctrl_close(ctrl: *WPACtrl) void;
extern fn wpa_ctrl_request(ctrl: *WPACtrl, cmd: [*:0]const u8, clen: usize, reply: [*:0]u8, rlen: *usize, cb: ?WPAReqCallback) c_int;
extern fn wpa_ctrl_pending(ctrl: *WPACtrl) c_int;
extern fn wpa_ctrl_recv(ctrl: *WPACtrl, reply: [*:0]u8, reply_len: *usize) c_int;
pub const Control = struct {
//mu: Thread.Mutext = .{},
wpa_ctrl: *WPACtrl,
attached: bool = false,
const Self = @This();
pub const Error = error{
NameTooLong,
WpaCtrlFailure,
WpaCtrlTimeout,
WpaCtrlAttach,
WpaCtrlDetach,
WpaCtrlScanStart,
WpaCtrlSaveConfig,
WpaCtrlAddNetwork,
WpaCtrlRemoveNetwork,
WpaCtrlSelectNetwork,
WpaCtrlEnableNetwork,
WpaCtrlSetNetworkParam,
} || std.fmt.BufPrintError;
// TODO: using this in Self.request
pub const RequestCallback = *const fn (msg: [:0]const u8) void;
fn wpaErr(i: c_int) Error {
return switch (i) {
-2 => error.WpaCtrlTimeout,
else => error.WpaCtrlFailure,
};
}
/// open a WPA control interface identified by the path.
/// the returned instance must be close'd when done to free resources.
/// TODO: describe @android: and @abstract: prefixes
/// TODO: what about UDP, on windows?
pub fn open(path: [:0]const u8) Error!Self {
const ctrl = wpa_ctrl_open(path);
if (ctrl == null) {
return error.WpaCtrlFailure;
}
return Self{ .wpa_ctrl = ctrl.? };
}
/// release all associated resources, including detach'ing a monitor.
pub fn close(self: *Self) Error!void {
//self.mu.lock();
//defer self.mu.unlock();
if (self.attached) {
try self.detach();
}
wpa_ctrl_close(self.wpa_ctrl);
}
/// start control interface events monitoring.
/// presence of events is reported by self.pending; then can be read using self.receive.
pub fn attach(self: *Self) Error!void {
self.reqOK("ATTACH") catch return error.WpaCtrlAttach;
self.attached = true;
}
/// stop control interface events monitoring.
pub fn detach(self: *Self) Error!void {
self.reqOK("DETACH") catch return error.WpaCtrlDetach;
self.attached = false;
}
/// request wifi scan
pub fn scan(self: *Self) Error!void {
self.reqOK("SCAN") catch return error.WpaCtrlScanStart;
}
/// dump in-memory config to a file, typically /etc/wpa_supplicant/wpa_supplicant.conf.
/// fails if update_config set to 0.
pub fn saveConfig(self: *Self) Error!void {
self.reqOK("SAVE_CONFIG") catch return error.WpaCtrlSaveConfig;
}
/// add a new blank network, returning its ID.
/// the newly added network can be configured with self.setNetworkParam.
pub fn addNetwork(self: *Self) (Error||std.fmt.ParseIntError)!u32 {
var buf: [10:0]u8 = undefined;
const resp = self.request("ADD_NETWORK", &buf, null) catch return error.WpaCtrlAddNetwork;
return std.fmt.parseUnsigned(u32, mem.trim(u8, resp, "\n "), 10);
}
pub fn removeNetwork(self: *Self, id: u32) Error!void {
var buf: [48:0]u8 = undefined;
const cmd = try std.fmt.bufPrintZ(&buf, "REMOVE_NETWORK {d}", .{id});
return self.reqOK(cmd) catch return error.WpaCtrlRemoveNetwork;
}
pub fn selectNetwork(self: *Self, id: u32) Error!void {
var buf: [48:0]u8 = undefined;
const cmd = try std.fmt.bufPrintZ(&buf, "SELECT_NETWORK {d}", .{id});
return self.reqOK(cmd) catch return error.WpaCtrlSelectNetwork;
}
pub fn enableNetwork(self: *Self, id: u32) Error!void {
var buf: [48:0]u8 = undefined;
const cmd = try std.fmt.bufPrintZ(&buf, "ENABLE_NETWORK {d}", .{id});
return self.reqOK(cmd) catch return error.WpaCtrlEnableNetwork;
}
pub fn setNetworkParam(self: *Self, id: u32, name: []const u8, value: []const u8) Error!void {
var buf: [512:0]u8 = undefined;
const cmd = try std.fmt.bufPrintZ(&buf, "SET_NETWORK {d} {s} {s}", .{id, name, value});
return self.reqOK(cmd) catch return error.WpaCtrlSetNetworkParam;
}
fn reqOK(self: *Self, cmd: [:0]const u8) Error!void {
var buf: [10:0]u8 = undefined;
const resp = try self.request(cmd, &buf, null);
if (!mem.startsWith(u8, resp, "OK\n")) {
return error.WpaCtrlFailure;
}
}
/// send a command to the control interface, returning a response owned by buf.
/// callback receives a message from the same buf.
pub fn request(self: Self, cmd: [:0]const u8, buf: [:0]u8, callback: ?WPAReqCallback) Error![]const u8 {
//self.mu.lock();
//defer self.mu.unlock();
var n: usize = buf.len;
const e = wpa_ctrl_request(self.wpa_ctrl, cmd, cmd.len, buf, &n, callback);
if (e != 0) {
return wpaErr(e);
}
return buf[0..n];
}
/// reports whether pending messages are waiting to be read using self.receive.
/// requires self to be attach'ed.
pub fn pending(self: Self) Error!bool {
//self.mu.lock();
//defer self.mu.unlock();
const n = wpa_ctrl_pending(self.wpa_ctrl);
if (n < 0) {
return wpaErr(n);
}
return n > 0;
}
/// retrieve a pending message using the provided buf.
/// returned slice is owned by the buf.
/// requires self to be attach'ed.
pub fn receive(self: Self, buf: [:0]u8) Error![]const u8 {
//self.mu.lock();
//defer self.mu.unlock();
var n: usize = buf.len;
const e = wpa_ctrl_recv(self.wpa_ctrl, buf, &n);
if (e != 0) {
return wpaErr(e);
}
return buf[0..n];
}
};
//pub const WPA_CTRL_REQ = "CTRL-REQ-";
//pub const WPA_CTRL_RSP = "CTRL-RSP-";
//pub const WPA_EVENT_CONNECTED = "CTRL-EVENT-CONNECTED ";
//pub const WPA_EVENT_DISCONNECTED = "CTRL-EVENT-DISCONNECTED ";
//pub const WPA_EVENT_ASSOC_REJECT = "CTRL-EVENT-ASSOC-REJECT ";
//pub const WPA_EVENT_AUTH_REJECT = "CTRL-EVENT-AUTH-REJECT ";
//pub const WPA_EVENT_TERMINATING = "CTRL-EVENT-TERMINATING ";
//pub const WPA_EVENT_PASSWORD_CHANGED = "CTRL-EVENT-PASSWORD-CHANGED ";
//pub const WPA_EVENT_EAP_NOTIFICATION = "CTRL-EVENT-EAP-NOTIFICATION ";
//pub const WPA_EVENT_EAP_STARTED = "CTRL-EVENT-EAP-STARTED ";
//pub const WPA_EVENT_EAP_PROPOSED_METHOD = "CTRL-EVENT-EAP-PROPOSED-METHOD ";
//pub const WPA_EVENT_EAP_METHOD = "CTRL-EVENT-EAP-METHOD ";
//pub const WPA_EVENT_EAP_PEER_CERT = "CTRL-EVENT-EAP-PEER-CERT ";
//pub const WPA_EVENT_EAP_PEER_ALT = "CTRL-EVENT-EAP-PEER-ALT ";
//pub const WPA_EVENT_EAP_TLS_CERT_ERROR = "CTRL-EVENT-EAP-TLS-CERT-ERROR ";
//pub const WPA_EVENT_EAP_STATUS = "CTRL-EVENT-EAP-STATUS ";
//pub const WPA_EVENT_EAP_RETRANSMIT = "CTRL-EVENT-EAP-RETRANSMIT ";
//pub const WPA_EVENT_EAP_RETRANSMIT2 = "CTRL-EVENT-EAP-RETRANSMIT2 ";
//pub const WPA_EVENT_EAP_SUCCESS = "CTRL-EVENT-EAP-SUCCESS ";
//pub const WPA_EVENT_EAP_SUCCESS2 = "CTRL-EVENT-EAP-SUCCESS2 ";
//pub const WPA_EVENT_EAP_FAILURE = "CTRL-EVENT-EAP-FAILURE ";
//pub const WPA_EVENT_EAP_FAILURE2 = "CTRL-EVENT-EAP-FAILURE2 ";
//pub const WPA_EVENT_EAP_TIMEOUT_FAILURE = "CTRL-EVENT-EAP-TIMEOUT-FAILURE ";
//pub const WPA_EVENT_EAP_TIMEOUT_FAILURE2 = "CTRL-EVENT-EAP-TIMEOUT-FAILURE2 ";
//pub const WPA_EVENT_EAP_ERROR_CODE = "EAP-ERROR-CODE ";
//pub const WPA_EVENT_TEMP_DISABLED = "CTRL-EVENT-SSID-TEMP-DISABLED ";
//pub const WPA_EVENT_REENABLED = "CTRL-EVENT-SSID-REENABLED ";
//pub const WPA_EVENT_SCAN_STARTED = "CTRL-EVENT-SCAN-STARTED ";
//pub const WPA_EVENT_SCAN_RESULTS = "CTRL-EVENT-SCAN-RESULTS ";
//pub const WPA_EVENT_SCAN_FAILED = "CTRL-EVENT-SCAN-FAILED ";
//pub const WPA_EVENT_STATE_CHANGE = "CTRL-EVENT-STATE-CHANGE ";
//pub const WPA_EVENT_BSS_ADDED = "CTRL-EVENT-BSS-ADDED ";
//pub const WPA_EVENT_BSS_REMOVED = "CTRL-EVENT-BSS-REMOVED ";
//pub const WPA_EVENT_NETWORK_NOT_FOUND = "CTRL-EVENT-NETWORK-NOT-FOUND ";
//pub const WPA_EVENT_SIGNAL_CHANGE = "CTRL-EVENT-SIGNAL-CHANGE ";
//pub const WPA_EVENT_BEACON_LOSS = "CTRL-EVENT-BEACON-LOSS ";
//pub const WPA_EVENT_REGDOM_CHANGE = "CTRL-EVENT-REGDOM-CHANGE ";
//pub const WPA_EVENT_CHANNEL_SWITCH_STARTED = "CTRL-EVENT-STARTED-CHANNEL-SWITCH ";
//pub const WPA_EVENT_CHANNEL_SWITCH = "CTRL-EVENT-CHANNEL-SWITCH ";
//pub const WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER = "CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER ";
//pub const WPA_EVENT_UNPROT_BEACON = "CTRL-EVENT-UNPROT-BEACON ";
//pub const WPA_EVENT_DO_ROAM = "CTRL-EVENT-DO-ROAM ";
//pub const WPA_EVENT_SKIP_ROAM = "CTRL-EVENT-SKIP-ROAM ";
//pub const WPA_EVENT_SUBNET_STATUS_UPDATE = "CTRL-EVENT-SUBNET-STATUS-UPDATE ";
//pub const IBSS_RSN_COMPLETED = "IBSS-RSN-COMPLETED ";
//pub const WPA_EVENT_FREQ_CONFLICT = "CTRL-EVENT-FREQ-CONFLICT ";
//pub const WPA_EVENT_AVOID_FREQ = "CTRL-EVENT-AVOID-FREQ ";
//pub const WPA_EVENT_NETWORK_ADDED = "CTRL-EVENT-NETWORK-ADDED ";
//pub const WPA_EVENT_NETWORK_REMOVED = "CTRL-EVENT-NETWORK-REMOVED ";
//pub const WPA_EVENT_MSCS_RESULT = "CTRL-EVENT-MSCS-RESULT ";
//pub const WPS_EVENT_OVERLAP = "WPS-OVERLAP-DETECTED ";
//pub const WPS_EVENT_AP_AVAILABLE_PBC = "WPS-AP-AVAILABLE-PBC ";
//pub const WPS_EVENT_AP_AVAILABLE_AUTH = "WPS-AP-AVAILABLE-AUTH ";
//pub const WPS_EVENT_AP_AVAILABLE_PIN = "WPS-AP-AVAILABLE-PIN ";
//pub const WPS_EVENT_AP_AVAILABLE = "WPS-AP-AVAILABLE ";
//pub const WPS_EVENT_CRED_RECEIVED = "WPS-CRED-RECEIVED ";
//pub const WPS_EVENT_M2D = "WPS-M2D ";
//pub const WPS_EVENT_FAIL = "WPS-FAIL ";
//pub const WPS_EVENT_SUCCESS = "WPS-SUCCESS ";
//pub const WPS_EVENT_TIMEOUT = "WPS-TIMEOUT ";
//pub const WPS_EVENT_ACTIVE = "WPS-PBC-ACTIVE ";
//pub const WPS_EVENT_DISABLE = "WPS-PBC-DISABLE ";
//pub const WPS_EVENT_ENROLLEE_SEEN = "WPS-ENROLLEE-SEEN ";
//pub const WPS_EVENT_OPEN_NETWORK = "WPS-OPEN-NETWORK ";
//pub const WPA_EVENT_SCS_RESULT = "CTRL-EVENT-SCS-RESULT ";
//pub const WPA_EVENT_DSCP_POLICY = "CTRL-EVENT-DSCP-POLICY ";
//pub const WPS_EVENT_ER_AP_ADD = "WPS-ER-AP-ADD ";
//pub const WPS_EVENT_ER_AP_REMOVE = "WPS-ER-AP-REMOVE ";
//pub const WPS_EVENT_ER_ENROLLEE_ADD = "WPS-ER-ENROLLEE-ADD ";
//pub const WPS_EVENT_ER_ENROLLEE_REMOVE = "WPS-ER-ENROLLEE-REMOVE ";
//pub const WPS_EVENT_ER_AP_SETTINGS = "WPS-ER-AP-SETTINGS ";
//pub const WPS_EVENT_ER_SET_SEL_REG = "WPS-ER-AP-SET-SEL-REG ";
//pub const DPP_EVENT_AUTH_SUCCESS = "DPP-AUTH-SUCCESS ";
//pub const DPP_EVENT_AUTH_INIT_FAILED = "DPP-AUTH-INIT-FAILED ";
//pub const DPP_EVENT_NOT_COMPATIBLE = "DPP-NOT-COMPATIBLE ";
//pub const DPP_EVENT_RESPONSE_PENDING = "DPP-RESPONSE-PENDING ";
//pub const DPP_EVENT_SCAN_PEER_QR_CODE = "DPP-SCAN-PEER-QR-CODE ";
//pub const DPP_EVENT_AUTH_DIRECTION = "DPP-AUTH-DIRECTION ";
//pub const DPP_EVENT_CONF_RECEIVED = "DPP-CONF-RECEIVED ";
//pub const DPP_EVENT_CONF_SENT = "DPP-CONF-SENT ";
//pub const DPP_EVENT_CONF_FAILED = "DPP-CONF-FAILED ";
//pub const DPP_EVENT_CONN_STATUS_RESULT = "DPP-CONN-STATUS-RESULT ";
//pub const DPP_EVENT_CONFOBJ_AKM = "DPP-CONFOBJ-AKM ";
//pub const DPP_EVENT_CONFOBJ_SSID = "DPP-CONFOBJ-SSID ";
//pub const DPP_EVENT_CONFOBJ_SSID_CHARSET = "DPP-CONFOBJ-SSID-CHARSET ";
//pub const DPP_EVENT_CONFOBJ_PASS = "DPP-CONFOBJ-PASS ";
//pub const DPP_EVENT_CONFOBJ_PSK = "DPP-CONFOBJ-PSK ";
//pub const DPP_EVENT_CONNECTOR = "DPP-CONNECTOR ";
//pub const DPP_EVENT_C_SIGN_KEY = "DPP-C-SIGN-KEY ";
//pub const DPP_EVENT_PP_KEY = "DPP-PP-KEY ";
//pub const DPP_EVENT_NET_ACCESS_KEY = "DPP-NET-ACCESS-KEY ";
//pub const DPP_EVENT_SERVER_NAME = "DPP-SERVER-NAME ";
//pub const DPP_EVENT_CERTBAG = "DPP-CERTBAG ";
//pub const DPP_EVENT_CACERT = "DPP-CACERT ";
//pub const DPP_EVENT_MISSING_CONNECTOR = "DPP-MISSING-CONNECTOR ";
//pub const DPP_EVENT_NETWORK_ID = "DPP-NETWORK-ID ";
//pub const DPP_EVENT_CONFIGURATOR_ID = "DPP-CONFIGURATOR-ID ";
//pub const DPP_EVENT_RX = "DPP-RX ";
//pub const DPP_EVENT_TX = "DPP-TX ";
//pub const DPP_EVENT_TX_STATUS = "DPP-TX-STATUS ";
//pub const DPP_EVENT_FAIL = "DPP-FAIL ";
//pub const DPP_EVENT_PKEX_T_LIMIT = "DPP-PKEX-T-LIMIT ";
//pub const DPP_EVENT_INTRO = "DPP-INTRO ";
//pub const DPP_EVENT_CONF_REQ_RX = "DPP-CONF-REQ-RX ";
//pub const DPP_EVENT_CHIRP_STOPPED = "DPP-CHIRP-STOPPED ";
//pub const DPP_EVENT_MUD_URL = "DPP-MUD-URL ";
//pub const DPP_EVENT_BAND_SUPPORT = "DPP-BAND-SUPPORT ";
//pub const DPP_EVENT_CSR = "DPP-CSR ";
//pub const DPP_EVENT_CHIRP_RX = "DPP-CHIRP-RX ";
//pub const MESH_GROUP_STARTED = "MESH-GROUP-STARTED ";
//pub const MESH_GROUP_REMOVED = "MESH-GROUP-REMOVED ";
//pub const MESH_PEER_CONNECTED = "MESH-PEER-CONNECTED ";
//pub const MESH_PEER_DISCONNECTED = "MESH-PEER-DISCONNECTED ";
//pub const MESH_SAE_AUTH_FAILURE = "MESH-SAE-AUTH-FAILURE ";
//pub const MESH_SAE_AUTH_BLOCKED = "MESH-SAE-AUTH-BLOCKED ";
//pub const WMM_AC_EVENT_TSPEC_ADDED = "TSPEC-ADDED ";
//pub const WMM_AC_EVENT_TSPEC_REMOVED = "TSPEC-REMOVED ";
//pub const WMM_AC_EVENT_TSPEC_REQ_FAILED = "TSPEC-REQ-FAILED ";
//pub const P2P_EVENT_DEVICE_FOUND = "P2P-DEVICE-FOUND ";
//pub const P2P_EVENT_DEVICE_LOST = "P2P-DEVICE-LOST ";
//pub const P2P_EVENT_GO_NEG_REQUEST = "P2P-GO-NEG-REQUEST ";
//pub const P2P_EVENT_GO_NEG_SUCCESS = "P2P-GO-NEG-SUCCESS ";
//pub const P2P_EVENT_GO_NEG_FAILURE = "P2P-GO-NEG-FAILURE ";
//pub const P2P_EVENT_GROUP_FORMATION_SUCCESS = "P2P-GROUP-FORMATION-SUCCESS ";
//pub const P2P_EVENT_GROUP_FORMATION_FAILURE = "P2P-GROUP-FORMATION-FAILURE ";
//pub const P2P_EVENT_GROUP_STARTED = "P2P-GROUP-STARTED ";
//pub const P2P_EVENT_GROUP_REMOVED = "P2P-GROUP-REMOVED ";
//pub const P2P_EVENT_CROSS_CONNECT_ENABLE = "P2P-CROSS-CONNECT-ENABLE ";
//pub const P2P_EVENT_CROSS_CONNECT_DISABLE = "P2P-CROSS-CONNECT-DISABLE ";
//pub const P2P_EVENT_PROV_DISC_SHOW_PIN = "P2P-PROV-DISC-SHOW-PIN ";
//pub const P2P_EVENT_PROV_DISC_ENTER_PIN = "P2P-PROV-DISC-ENTER-PIN ";
//pub const P2P_EVENT_PROV_DISC_PBC_REQ = "P2P-PROV-DISC-PBC-REQ ";
//pub const P2P_EVENT_PROV_DISC_PBC_RESP = "P2P-PROV-DISC-PBC-RESP ";
//pub const P2P_EVENT_PROV_DISC_FAILURE = "P2P-PROV-DISC-FAILURE";
//pub const P2P_EVENT_SERV_DISC_REQ = "P2P-SERV-DISC-REQ ";
//pub const P2P_EVENT_SERV_DISC_RESP = "P2P-SERV-DISC-RESP ";
//pub const P2P_EVENT_SERV_ASP_RESP = "P2P-SERV-ASP-RESP ";
//pub const P2P_EVENT_INVITATION_RECEIVED = "P2P-INVITATION-RECEIVED ";
//pub const P2P_EVENT_INVITATION_RESULT = "P2P-INVITATION-RESULT ";
//pub const P2P_EVENT_INVITATION_ACCEPTED = "P2P-INVITATION-ACCEPTED ";
//pub const P2P_EVENT_FIND_STOPPED = "P2P-FIND-STOPPED ";
//pub const P2P_EVENT_PERSISTENT_PSK_FAIL = "P2P-PERSISTENT-PSK-FAIL id=";
//pub const P2P_EVENT_PRESENCE_RESPONSE = "P2P-PRESENCE-RESPONSE ";
//pub const P2P_EVENT_NFC_BOTH_GO = "P2P-NFC-BOTH-GO ";
//pub const P2P_EVENT_NFC_PEER_CLIENT = "P2P-NFC-PEER-CLIENT ";
//pub const P2P_EVENT_NFC_WHILE_CLIENT = "P2P-NFC-WHILE-CLIENT ";
//pub const P2P_EVENT_FALLBACK_TO_GO_NEG = "P2P-FALLBACK-TO-GO-NEG ";
//pub const P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED = "P2P-FALLBACK-TO-GO-NEG-ENABLED ";
//pub const ESS_DISASSOC_IMMINENT = "ESS-DISASSOC-IMMINENT ";
//pub const P2P_EVENT_REMOVE_AND_REFORM_GROUP = "P2P-REMOVE-AND-REFORM-GROUP ";
//pub const P2P_EVENT_P2PS_PROVISION_START = "P2PS-PROV-START ";
//pub const P2P_EVENT_P2PS_PROVISION_DONE = "P2PS-PROV-DONE ";
//pub const INTERWORKING_AP = "INTERWORKING-AP ";
//pub const INTERWORKING_EXCLUDED = "INTERWORKING-BLACKLISTED ";
//pub const INTERWORKING_NO_MATCH = "INTERWORKING-NO-MATCH ";
//pub const INTERWORKING_ALREADY_CONNECTED = "INTERWORKING-ALREADY-CONNECTED ";
//pub const INTERWORKING_SELECTED = "INTERWORKING-SELECTED ";
//pub const CRED_ADDED = "CRED-ADDED ";
//pub const CRED_MODIFIED = "CRED-MODIFIED ";
//pub const CRED_REMOVED = "CRED-REMOVED ";
//pub const GAS_RESPONSE_INFO = "GAS-RESPONSE-INFO ";
//pub const GAS_QUERY_START = "GAS-QUERY-START ";
//pub const GAS_QUERY_DONE = "GAS-QUERY-DONE ";
//pub const ANQP_QUERY_DONE = "ANQP-QUERY-DONE ";
//pub const RX_ANQP = "RX-ANQP ";
//pub const RX_HS20_ANQP = "RX-HS20-ANQP ";
//pub const RX_HS20_ANQP_ICON = "RX-HS20-ANQP-ICON ";
//pub const RX_HS20_ICON = "RX-HS20-ICON ";
//pub const RX_MBO_ANQP = "RX-MBO-ANQP ";
//pub const RX_VENUE_URL = "RX-VENUE-URL ";
//pub const HS20_SUBSCRIPTION_REMEDIATION = "HS20-SUBSCRIPTION-REMEDIATION ";
//pub const HS20_DEAUTH_IMMINENT_NOTICE = "HS20-DEAUTH-IMMINENT-NOTICE ";
//pub const HS20_T_C_ACCEPTANCE = "HS20-T-C-ACCEPTANCE ";
//pub const EXT_RADIO_WORK_START = "EXT-RADIO-WORK-START ";
//pub const EXT_RADIO_WORK_TIMEOUT = "EXT-RADIO-WORK-TIMEOUT ";
//pub const RRM_EVENT_NEIGHBOR_REP_RXED = "RRM-NEIGHBOR-REP-RECEIVED ";
//pub const RRM_EVENT_NEIGHBOR_REP_FAILED = "RRM-NEIGHBOR-REP-REQUEST-FAILED ";
//pub const WPS_EVENT_PIN_NEEDED = "WPS-PIN-NEEDED ";
//pub const WPS_EVENT_NEW_AP_SETTINGS = "WPS-NEW-AP-SETTINGS ";
//pub const WPS_EVENT_REG_SUCCESS = "WPS-REG-SUCCESS ";
//pub const WPS_EVENT_AP_SETUP_LOCKED = "WPS-AP-SETUP-LOCKED ";
//pub const WPS_EVENT_AP_SETUP_UNLOCKED = "WPS-AP-SETUP-UNLOCKED ";
//pub const WPS_EVENT_AP_PIN_ENABLED = "WPS-AP-PIN-ENABLED ";
//pub const WPS_EVENT_AP_PIN_DISABLED = "WPS-AP-PIN-DISABLED ";
//pub const WPS_EVENT_PIN_ACTIVE = "WPS-PIN-ACTIVE ";
//pub const WPS_EVENT_CANCEL = "WPS-CANCEL ";
//pub const AP_STA_CONNECTED = "AP-STA-CONNECTED ";
//pub const AP_STA_DISCONNECTED = "AP-STA-DISCONNECTED ";
//pub const AP_STA_POSSIBLE_PSK_MISMATCH = "AP-STA-POSSIBLE-PSK-MISMATCH ";
//pub const AP_STA_POLL_OK = "AP-STA-POLL-OK ";
//pub const AP_REJECTED_MAX_STA = "AP-REJECTED-MAX-STA ";
//pub const AP_REJECTED_BLOCKED_STA = "AP-REJECTED-BLOCKED-STA ";
//pub const HS20_T_C_FILTERING_ADD = "HS20-T-C-FILTERING-ADD ";
//pub const HS20_T_C_FILTERING_REMOVE = "HS20-T-C-FILTERING-REMOVE ";
//pub const AP_EVENT_ENABLED = "AP-ENABLED ";
//pub const AP_EVENT_DISABLED = "AP-DISABLED ";
//pub const INTERFACE_ENABLED = "INTERFACE-ENABLED ";
//pub const INTERFACE_DISABLED = "INTERFACE-DISABLED ";
//pub const ACS_EVENT_STARTED = "ACS-STARTED ";
//pub const ACS_EVENT_COMPLETED = "ACS-COMPLETED ";
//pub const ACS_EVENT_FAILED = "ACS-FAILED ";
//pub const DFS_EVENT_RADAR_DETECTED = "DFS-RADAR-DETECTED ";
//pub const DFS_EVENT_NEW_CHANNEL = "DFS-NEW-CHANNEL ";
//pub const DFS_EVENT_CAC_START = "DFS-CAC-START ";
//pub const DFS_EVENT_CAC_COMPLETED = "DFS-CAC-COMPLETED ";
//pub const DFS_EVENT_NOP_FINISHED = "DFS-NOP-FINISHED ";
//pub const DFS_EVENT_PRE_CAC_EXPIRED = "DFS-PRE-CAC-EXPIRED ";
//pub const AP_CSA_FINISHED = "AP-CSA-FINISHED ";
//pub const P2P_EVENT_LISTEN_OFFLOAD_STOP = "P2P-LISTEN-OFFLOAD-STOPPED ";
//pub const P2P_LISTEN_OFFLOAD_STOP_REASON = "P2P-LISTEN-OFFLOAD-STOP-REASON ";
//pub const BSS_TM_RESP = "BSS-TM-RESP ";
//pub const COLOC_INTF_REQ = "COLOC-INTF-REQ ";
//pub const COLOC_INTF_REPORT = "COLOC-INTF-REPORT ";
//pub const MBO_CELL_PREFERENCE = "MBO-CELL-PREFERENCE ";

@ -0,0 +1,22 @@
wpa_supplicant and hostapd
--------------------------
Copyright (c) 2002-2022, Jouni Malinen <j@w1.fi> and contributors
All Rights Reserved.
See the README file for the current license terms.
This software was previously distributed under BSD/GPL v2 dual license
terms that allowed either of those license alternatives to be
selected. As of February 11, 2012, the project has chosen to use only
the BSD license option for future distribution. As such, the GPL v2
license option is no longer used. It should be noted that the BSD
license option (the one with advertisement clause removed) is compatible
with GPL and as such, does not prevent use of this software in projects
that use GPL.
Some of the files may still include pointers to GPL version 2 license
terms. However, such copyright and license notifications are maintained
only for attribution purposes and any distribution of this software
after February 11, 2012 is no longer under the GPL v2 option.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,56 @@
wpa_supplicant and hostapd
--------------------------
Copyright (c) 2002-2022, Jouni Malinen <j@w1.fi> and contributors
All Rights Reserved.
These programs are licensed under the BSD license (the one with
advertisement clause removed).
If you are submitting changes to the project, please see CONTRIBUTIONS
file for more instructions.
This package may include either wpa_supplicant, hostapd, or both. See
README file respective subdirectories (wpa_supplicant/README or
hostapd/README) for more details.
Source code files were moved around in v0.6.x releases and compared to
earlier releases, the programs are now built by first going to a
subdirectory (wpa_supplicant or hostapd) and creating build
configuration (.config) and running 'make' there (for Linux/BSD/cygwin
builds).
License
-------
This software may be distributed, used, and modified under the terms of
BSD license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name(s) of the above-listed copyright holder(s) nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@ -0,0 +1,50 @@
/*
* wpa_supplicant/hostapd - Build time configuration defines
* Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*
* This header file can be used to define configuration defines that were
* originally defined in Makefile. This is mainly meant for IDE use or for
* systems that do not have suitable 'make' tool. In these cases, it may be
* easier to have a single place for defining all the needed C pre-processor
* defines.
*/
#ifndef BUILD_CONFIG_H
#define BUILD_CONFIG_H
/* Insert configuration defines, e.g., #define EAP_MD5, here, if needed. */
#ifdef CONFIG_WIN32_DEFAULTS
#define CONFIG_NATIVE_WINDOWS
#define CONFIG_ANSI_C_EXTRA
#define CONFIG_WINPCAP
#define IEEE8021X_EAPOL
#define PKCS12_FUNCS
#define PCSC_FUNCS
#define CONFIG_CTRL_IFACE
#define CONFIG_CTRL_IFACE_NAMED_PIPE
#define CONFIG_DRIVER_NDIS
#define CONFIG_NDIS_EVENTS_INTEGRATED
#define CONFIG_DEBUG_FILE
#define EAP_MD5
#define EAP_TLS
#define EAP_MSCHAPv2
#define EAP_PEAP
#define EAP_TTLS
#define EAP_GTC
#define EAP_OTP
#define EAP_LEAP
#define EAP_TNC
#define _CRT_SECURE_NO_DEPRECATE
#ifdef USE_INTERNAL_CRYPTO
#define CONFIG_TLS_INTERNAL_CLIENT
#define CONFIG_INTERNAL_LIBTOMMATH
#define CONFIG_CRYPTO_INTERNAL
#endif /* USE_INTERNAL_CRYPTO */
#endif /* CONFIG_WIN32_DEFAULTS */
#endif /* BUILD_CONFIG_H */

@ -0,0 +1,598 @@
/*
* wpa_supplicant/hostapd / common helper functions, etc.
* Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
#ifndef COMMON_H
#define COMMON_H
#include "os.h"
#if defined(__linux__) || defined(__GLIBC__)
#include <endian.h>
#include <byteswap.h>
#endif /* __linux__ */
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/endian.h>
#define __BYTE_ORDER _BYTE_ORDER
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
#define __BIG_ENDIAN _BIG_ENDIAN
#ifdef __OpenBSD__
#define bswap_16 swap16
#define bswap_32 swap32
#define bswap_64 swap64
#else /* __OpenBSD__ */
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#endif /* __OpenBSD__ */
#endif /* defined(__FreeBSD__) || defined(__NetBSD__) ||
* defined(__DragonFly__) || defined(__OpenBSD__) */
#ifdef __APPLE__
#include <sys/types.h>
#include <machine/endian.h>
#define __BYTE_ORDER _BYTE_ORDER
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
#define __BIG_ENDIAN _BIG_ENDIAN
static inline unsigned short bswap_16(unsigned short v)
{
return ((v & 0xff) << 8) | (v >> 8);
}
static inline unsigned int bswap_32(unsigned int v)
{
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
((v & 0xff0000) >> 8) | (v >> 24);
}
#endif /* __APPLE__ */
#ifdef __rtems__
#include <rtems/endian.h>
#define __BYTE_ORDER BYTE_ORDER
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __BIG_ENDIAN BIG_ENDIAN
#define bswap_16 CPU_swap_u16
#define bswap_32 CPU_swap_u32
#endif /* __rtems__ */
#ifdef CONFIG_NATIVE_WINDOWS
#include <winsock.h>
typedef int socklen_t;
#ifndef MSG_DONTWAIT
#define MSG_DONTWAIT 0 /* not supported */
#endif
#endif /* CONFIG_NATIVE_WINDOWS */
#ifdef _MSC_VER
#define inline __inline
#undef vsnprintf
#define vsnprintf _vsnprintf
#undef close
#define close closesocket
#endif /* _MSC_VER */
/* Define platform specific integer types */
#ifdef _MSC_VER
typedef UINT64 u64;
typedef UINT32 u32;
typedef UINT16 u16;
typedef UINT8 u8;
typedef INT64 s64;
typedef INT32 s32;
typedef INT16 s16;
typedef INT8 s8;
#define WPA_TYPES_DEFINED
#endif /* _MSC_VER */
#ifdef __vxworks
typedef unsigned long long u64;
typedef UINT32 u32;
typedef UINT16 u16;
typedef UINT8 u8;
typedef long long s64;
typedef INT32 s32;
typedef INT16 s16;
typedef INT8 s8;
#define WPA_TYPES_DEFINED
#endif /* __vxworks */
#ifndef WPA_TYPES_DEFINED
#ifdef CONFIG_USE_INTTYPES_H
#include <inttypes.h>
#else
#include <stdint.h>
#endif
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef int64_t s64;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
#define WPA_TYPES_DEFINED
#endif /* !WPA_TYPES_DEFINED */
/* Define platform specific byte swapping macros */
#if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
static inline unsigned short wpa_swap_16(unsigned short v)
{
return ((v & 0xff) << 8) | (v >> 8);
}
static inline unsigned int wpa_swap_32(unsigned int v)
{
return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
((v & 0xff0000) >> 8) | (v >> 24);
}
#define le_to_host16(n) (n)
#define host_to_le16(n) (n)
#define be_to_host16(n) wpa_swap_16(n)
#define host_to_be16(n) wpa_swap_16(n)
#define le_to_host32(n) (n)
#define host_to_le32(n) (n)
#define be_to_host32(n) wpa_swap_32(n)
#define host_to_be32(n) wpa_swap_32(n)
#define host_to_le64(n) (n)
#define WPA_BYTE_SWAP_DEFINED
#endif /* __CYGWIN__ || CONFIG_NATIVE_WINDOWS */
#ifndef WPA_BYTE_SWAP_DEFINED
#ifndef __BYTE_ORDER
#ifndef __LITTLE_ENDIAN
#ifndef __BIG_ENDIAN
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#if defined(sparc)
#define __BYTE_ORDER __BIG_ENDIAN
#endif
#endif /* __BIG_ENDIAN */
#endif /* __LITTLE_ENDIAN */
#endif /* __BYTE_ORDER */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define le_to_host16(n) ((__force u16) (le16) (n))
#define host_to_le16(n) ((__force le16) (u16) (n))
#define be_to_host16(n) bswap_16((__force u16) (be16) (n))
#define host_to_be16(n) ((__force be16) bswap_16((n)))
#define le_to_host32(n) ((__force u32) (le32) (n))
#define host_to_le32(n) ((__force le32) (u32) (n))
#define be_to_host32(n) bswap_32((__force u32) (be32) (n))
#define host_to_be32(n) ((__force be32) bswap_32((n)))
#define le_to_host64(n) ((__force u64) (le64) (n))
#define host_to_le64(n) ((__force le64) (u64) (n))
#define be_to_host64(n) bswap_64((__force u64) (be64) (n))
#define host_to_be64(n) ((__force be64) bswap_64((n)))
#elif __BYTE_ORDER == __BIG_ENDIAN
#define le_to_host16(n) bswap_16(n)
#define host_to_le16(n) bswap_16(n)
#define be_to_host16(n) (n)
#define host_to_be16(n) (n)
#define le_to_host32(n) bswap_32(n)
#define host_to_le32(n) bswap_32(n)
#define be_to_host32(n) (n)
#define host_to_be32(n) (n)
#define le_to_host64(n) bswap_64(n)
#define host_to_le64(n) bswap_64(n)
#define be_to_host64(n) (n)
#define host_to_be64(n) (n)
#ifndef WORDS_BIGENDIAN
#define WORDS_BIGENDIAN
#endif
#else
#error Could not determine CPU byte order
#endif
#define WPA_BYTE_SWAP_DEFINED
#endif /* !WPA_BYTE_SWAP_DEFINED */
/* Macros for handling unaligned memory accesses */
static inline u16 WPA_GET_BE16(const u8 *a)
{
return (a[0] << 8) | a[1];
}
static inline void WPA_PUT_BE16(u8 *a, u16 val)
{
a[0] = val >> 8;
a[1] = val & 0xff;
}
static inline u16 WPA_GET_LE16(const u8 *a)
{
return (a[1] << 8) | a[0];
}
static inline void WPA_PUT_LE16(u8 *a, u16 val)
{
a[1] = val >> 8;
a[0] = val & 0xff;
}
static inline u32 WPA_GET_BE24(const u8 *a)
{
return (a[0] << 16) | (a[1] << 8) | a[2];
}
static inline void WPA_PUT_BE24(u8 *a, u32 val)
{
a[0] = (val >> 16) & 0xff;
a[1] = (val >> 8) & 0xff;
a[2] = val & 0xff;
}
static inline u32 WPA_GET_BE32(const u8 *a)
{
return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
}
static inline void WPA_PUT_BE32(u8 *a, u32 val)
{
a[0] = (val >> 24) & 0xff;
a[1] = (val >> 16) & 0xff;
a[2] = (val >> 8) & 0xff;
a[3] = val & 0xff;
}
static inline u32 WPA_GET_LE32(const u8 *a)
{
return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0];
}
static inline void WPA_PUT_LE32(u8 *a, u32 val)
{
a[3] = (val >> 24) & 0xff;
a[2] = (val >> 16) & 0xff;
a[1] = (val >> 8) & 0xff;
a[0] = val & 0xff;
}
static inline u64 WPA_GET_BE64(const u8 *a)
{
return (((u64) a[0]) << 56) | (((u64) a[1]) << 48) |
(((u64) a[2]) << 40) | (((u64) a[3]) << 32) |
(((u64) a[4]) << 24) | (((u64) a[5]) << 16) |
(((u64) a[6]) << 8) | ((u64) a[7]);
}
static inline void WPA_PUT_BE64(u8 *a, u64 val)
{
a[0] = val >> 56;
a[1] = val >> 48;
a[2] = val >> 40;
a[3] = val >> 32;
a[4] = val >> 24;
a[5] = val >> 16;
a[6] = val >> 8;
a[7] = val & 0xff;
}
static inline u64 WPA_GET_LE64(const u8 *a)
{
return (((u64) a[7]) << 56) | (((u64) a[6]) << 48) |
(((u64) a[5]) << 40) | (((u64) a[4]) << 32) |
(((u64) a[3]) << 24) | (((u64) a[2]) << 16) |
(((u64) a[1]) << 8) | ((u64) a[0]);
}
static inline void WPA_PUT_LE64(u8 *a, u64 val)
{
a[7] = val >> 56;
a[6] = val >> 48;
a[5] = val >> 40;
a[4] = val >> 32;
a[3] = val >> 24;
a[2] = val >> 16;
a[1] = val >> 8;
a[0] = val & 0xff;
}
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
#ifndef ETH_HLEN
#define ETH_HLEN 14
#endif
#ifndef IFNAMSIZ
#define IFNAMSIZ 16
#endif
#ifndef ETH_P_ALL
#define ETH_P_ALL 0x0003
#endif
#ifndef ETH_P_IP
#define ETH_P_IP 0x0800
#endif
#ifndef ETH_P_80211_ENCAP
#define ETH_P_80211_ENCAP 0x890d /* TDLS comes under this category */
#endif
#ifndef ETH_P_PAE
#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
#endif /* ETH_P_PAE */
#ifndef ETH_P_EAPOL
#define ETH_P_EAPOL ETH_P_PAE
#endif /* ETH_P_EAPOL */
#ifndef ETH_P_RSN_PREAUTH
#define ETH_P_RSN_PREAUTH 0x88c7
#endif /* ETH_P_RSN_PREAUTH */
#ifndef ETH_P_RRB
#define ETH_P_RRB 0x890D
#endif /* ETH_P_RRB */
#ifndef ETH_P_OUI
#define ETH_P_OUI 0x88B7
#endif /* ETH_P_OUI */
#ifndef ETH_P_8021Q
#define ETH_P_8021Q 0x8100
#endif /* ETH_P_8021Q */
#ifdef __GNUC__
#define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
#define STRUCT_PACKED __attribute__ ((packed))
#else
#define PRINTF_FORMAT(a,b)
#define STRUCT_PACKED
#endif
#ifdef CONFIG_ANSI_C_EXTRA
#if !defined(_MSC_VER) || _MSC_VER < 1400
/* snprintf - used in number of places; sprintf() is _not_ a good replacement
* due to possible buffer overflow; see, e.g.,
* http://www.ijs.si/software/snprintf/ for portable implementation of
* snprintf. */
int snprintf(char *str, size_t size, const char *format, ...);
/* vsnprintf - only used for wpa_msg() in wpa_supplicant.c */
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
#endif /* !defined(_MSC_VER) || _MSC_VER < 1400 */
/* getopt - only used in main.c */
int getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg;
extern int optind;
#ifndef CONFIG_NO_SOCKLEN_T_TYPEDEF
#ifndef __socklen_t_defined
typedef int socklen_t;
#endif
#endif
/* inline - define as __inline or just define it to be empty, if needed */
#ifdef CONFIG_NO_INLINE