Skip to content

Commit

Permalink
Update libs and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Mar 26, 2023
1 parent 00694c3 commit f44b870
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Atmosphere-libs
Submodule Atmosphere-libs updated 303 files
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)\"
Expand Down Expand Up @@ -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/
@$(MAKE) clean -C uHbTarget/
@rm -rf SdOut/
2 changes: 1 addition & 1 deletion Plutonium
14 changes: 9 additions & 5 deletions uLaunch/include/net/net_Service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
91 changes: 72 additions & 19 deletions uLaunch/source/net/net_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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<u32>(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;
}

}
14 changes: 7 additions & 7 deletions uMenu/source/ui/ui_SettingsMenuLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -129,12 +129,12 @@ namespace ui {
setsysGetSerialNumber(&serial);
this->PushSettingItem(GetLanguageString("set_serial_no"), EncodeForSettings<std::string>(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) {
Expand Down

0 comments on commit f44b870

Please sign in to comment.