From f44b870df52407a2510090fa1392b9f7bbfe11d9 Mon Sep 17 00:00:00 2001 From: XorTroll Date: Mon, 27 Mar 2023 00:24:15 +0200 Subject: [PATCH] Update libs and minor fixes --- Atmosphere-libs | 2 +- Makefile | 6 +- Plutonium | 2 +- uLaunch/include/net/net_Service.hpp | 14 ++-- uLaunch/source/net/net_Service.cpp | 91 ++++++++++++++++++----- uMenu/source/ui/ui_SettingsMenuLayout.cpp | 14 ++-- 6 files changed, 93 insertions(+), 36 deletions(-) diff --git a/Atmosphere-libs b/Atmosphere-libs index 590cdaf..af0d008 160000 --- a/Atmosphere-libs +++ b/Atmosphere-libs @@ -1 +1 @@ -Subproject commit 590cdaf022a9c6a50b7bd712d35add3ddf81dc9c +Subproject commit af0d008900128d8679b80569f69fe562ed7d6681 diff --git a/Makefile b/Makefile index 2f977b1..3320570 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ export UL_MAJOR := 0 export UL_MINOR := 3 -export UL_MICRO := 4 +export UL_MICRO := 5 export UL_VERSION := $(UL_MAJOR).$(UL_MINOR).$(UL_MICRO) export UL_DEFS := -DUL_MAJOR=$(UL_MAJOR) -DUL_MINOR=$(UL_MINOR) -DUL_MICRO=$(UL_MICRO) -DUL_VERSION=\"$(UL_VERSION)\" @@ -51,7 +51,7 @@ make_menu: menu: base make_menu clean: - @rm -rf SdOut/ @$(MAKE) clean -C uDaemon/ @$(MAKE) clean -C uMenu/ - @$(MAKE) clean -C uHbTarget/ \ No newline at end of file + @$(MAKE) clean -C uHbTarget/ + @rm -rf SdOut/ \ No newline at end of file diff --git a/Plutonium b/Plutonium index 8891b6c..672dec9 160000 --- a/Plutonium +++ b/Plutonium @@ -1 +1 @@ -Subproject commit 8891b6c419139518f744f20c6ab618e4d38bf956 +Subproject commit 672dec9798f4bbceb808f4affb0e55419a8075ea diff --git a/uLaunch/include/net/net_Service.hpp b/uLaunch/include/net/net_Service.hpp index de79a17..a3c317c 100644 --- a/uLaunch/include/net/net_Service.hpp +++ b/uLaunch/include/net/net_Service.hpp @@ -4,14 +4,18 @@ namespace net { + struct __attribute__((aligned(1))) WlanMacAddress { + u8 mac[0x6]; + }; + Result Initialize(); void Finalize(); - Result GetInternetConnectionStatus(NifmInternetConnectionStatus* status); + Result GetInternetConnectionStatus(NifmInternetConnectionStatus &out_status); bool HasConnection(); - Result GetCurrentNetworkProfile(NetworkProfileData *data); - Result GetMACAddress(u64 *out); + Result GetCurrentNetworkProfile(NetworkProfileData &out_prof_data); + Result GetMacAddress(WlanMacAddress &out_addr); - std::string FormatMACAddress(u64 addr); - std::string GetConsoleIPAddress(); + std::string FormatMacAddress(const WlanMacAddress &addr); + std::string GetConsoleIpAddress(); } \ No newline at end of file diff --git a/uLaunch/source/net/net_Service.cpp b/uLaunch/source/net/net_Service.cpp index d955599..b5d874e 100644 --- a/uLaunch/source/net/net_Service.cpp +++ b/uLaunch/source/net/net_Service.cpp @@ -3,14 +3,63 @@ namespace net { + namespace { + + Service g_WlanService; + Service g_WlanWirelessCommunicationService; + + Result wlanInitialize() { + if(serviceIsActive(&g_WlanService)) { + return ResultSuccess; + } + + UL_RC_TRY(smGetService(&g_WlanService, "wlan")); + + // https://switchbrew.org/wiki/WLAN_services#CreateWirelessCommunicationService + UL_RC_TRY(serviceDispatch(&g_WlanService, 0, + .out_num_objects = 1, + .out_objects = &g_WlanWirelessCommunicationService + )); + + return ResultSuccess; + } + + void wlanExit() { + serviceClose(&g_WlanWirelessCommunicationService); + serviceClose(&g_WlanService); + } + + Result wlaninfGetMacAddress(WlanMacAddress *out_addr) { + return serviceDispatchOut(wlaninfGetServiceSession(), 2, *out_addr); + } + + Result wlanGetMacAddress(WlanMacAddress *out_addr) { + return serviceDispatchOut(&g_WlanWirelessCommunicationService, 33, *out_addr); + } + + } + Result Initialize() { UL_RC_TRY(nifmInitialize(NifmServiceType_System)); - UL_RC_TRY(wlaninfInitialize()); + + if(hosversionAtLeast(15,0,0)) { + UL_RC_TRY(wlanInitialize()); + } + else { + UL_RC_TRY(wlaninfInitialize()); + } + return ResultSuccess; } void Finalize() { - wlaninfExit(); + if(hosversionAtLeast(15,0,0)) { + wlanExit(); + } + else { + wlaninfExit(); + } + nifmExit(); } @@ -20,36 +69,40 @@ namespace net { return status == NifmInternetConnectionStatus_Connected; } - Result GetCurrentNetworkProfile(NetworkProfileData *data) { + Result GetCurrentNetworkProfile(NetworkProfileData &out_prof_data) { return serviceDispatch(nifmGetServiceSession_GeneralService(), 5, .buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_Out | SfBufferAttr_HipcPointer }, - .buffers = { { data, sizeof(NetworkProfileData) } } + .buffers = { { std::addressof(out_prof_data), sizeof(out_prof_data) } } ); } - Result GetMACAddress(u64 *out) { - return serviceDispatchOut(wlaninfGetServiceSession(), 2, *out); + Result GetMacAddress(WlanMacAddress &out_addr) { + if(hosversionAtLeast(15,0,0)) { + UL_RC_TRY(wlanGetMacAddress(std::addressof(out_addr))); + } + else { + UL_RC_TRY(wlaninfGetMacAddress(std::addressof(out_addr))); + } + return 0; } - std::string FormatMACAddress(u64 addr) { + std::string FormatMacAddress(const WlanMacAddress &addr) { std::stringstream strm; - strm << std::hex << std::uppercase << addr; - std::string str; - auto sstrm = strm.str(); - for(u32 i = 1; i < 7; i++) { - str += sstrm.substr((6 - i) * 2, 2); - if(i < 6) { - str += ":"; + strm << std::hex << std::uppercase; + for(u32 i = 0; i < sizeof(WlanMacAddress); i++) { + strm << static_cast(addr.mac[i]); + if((i + 1) < sizeof(WlanMacAddress)) { + strm << ':'; } } - return str; + return strm.str(); } - std::string GetConsoleIPAddress() { - char ipaddr[0x20] = {0}; + std::string GetConsoleIpAddress() { + char ip_addr[0x20] = {0}; auto ip = gethostid(); - sprintf(ipaddr, "%lu.%lu.%lu.%lu", (ip & 0x000000FF), (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000) >> 24); - return ipaddr; + sprintf(ip_addr, "%lu.%lu.%lu.%lu", ip & 0x000000FF, (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000) >> 24); + return ip_addr; } } \ No newline at end of file diff --git a/uMenu/source/ui/ui_SettingsMenuLayout.cpp b/uMenu/source/ui/ui_SettingsMenuLayout.cpp index d032f9f..21cd959 100644 --- a/uMenu/source/ui/ui_SettingsMenuLayout.cpp +++ b/uMenu/source/ui/ui_SettingsMenuLayout.cpp @@ -84,9 +84,9 @@ namespace ui { auto connected_wifi_name = GetLanguageString("set_wifi_none"); if(net::HasConnection()) { - net::NetworkProfileData data = {}; - net::GetCurrentNetworkProfile(&data); - connected_wifi_name = data.wifi_name; + net::NetworkProfileData prof_data = {}; + net::GetCurrentNetworkProfile(prof_data); + connected_wifi_name = prof_data.wifi_name; } this->PushSettingItem(GetLanguageString("set_wifi_name"), EncodeForSettings(connected_wifi_name), 2); @@ -129,12 +129,12 @@ namespace ui { setsysGetSerialNumber(&serial); this->PushSettingItem(GetLanguageString("set_serial_no"), EncodeForSettings(serial.number), -1); - u64 mac = 0; - net::GetMACAddress(&mac); - const auto mac_addr_str = net::FormatMACAddress(mac); + net::WlanMacAddress mac_addr = {}; + net::GetMacAddress(mac_addr); + const auto mac_addr_str = net::FormatMacAddress(mac_addr); this->PushSettingItem(GetLanguageString("set_mac_addr"), EncodeForSettings(mac_addr_str), -1); - const auto ip_str = net::GetConsoleIPAddress(); + const auto ip_str = net::GetConsoleIpAddress(); this->PushSettingItem("Console IP address", EncodeForSettings(ip_str), -1); if(reset_idx) {