From df19b05818ae900a08ad05629a71d9c56107a689 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 07:05:09 +0000 Subject: [PATCH 1/3] Match NWC24 standard API --- configure.py | 2 +- libs/RevoEX/include/private/nwc24/NWC24Std.h | 2 +- libs/RevoEX/src/nwc24/NWC24StdAPI.c | 373 +++++++++++++++++-- 3 files changed, 344 insertions(+), 33 deletions(-) diff --git a/configure.py b/configure.py index e3e34657..5536ea7a 100644 --- a/configure.py +++ b/configure.py @@ -1068,7 +1068,7 @@ config.libs = [ ] ), RevoEXLib("nwc24", [ - Object(NonMatching, "nwc24/NWC24StdAPI.c"), + Object(Matching, "nwc24/NWC24StdAPI.c"), Object(Matching, "nwc24/NWC24FileAPI.c"), Object(Matching, "nwc24/NWC24Config.c"), Object(Matching, "nwc24/NWC24Utils.c"), diff --git a/libs/RevoEX/include/private/nwc24/NWC24Std.h b/libs/RevoEX/include/private/nwc24/NWC24Std.h index 92d90241..571db322 100644 --- a/libs/RevoEX/include/private/nwc24/NWC24Std.h +++ b/libs/RevoEX/include/private/nwc24/NWC24Std.h @@ -16,7 +16,7 @@ int STD_strnlen(const char* str, u32 len); int Util_xtoi(char ch); -void* Mail_memcpy(void* dest, void* src, u32 len); +void* Mail_memcpy(void* dest, const void* src, u32 len); void* Mail_memset(void* dest, int fill, u32 count); int Mail_strlen(const char* str); diff --git a/libs/RevoEX/src/nwc24/NWC24StdAPI.c b/libs/RevoEX/src/nwc24/NWC24StdAPI.c index 38a8b0da..78a505ae 100644 --- a/libs/RevoEX/src/nwc24/NWC24StdAPI.c +++ b/libs/RevoEX/src/nwc24/NWC24StdAPI.c @@ -3,48 +3,91 @@ #include -char* Mail_strcpy(char* dest, const char* src) { - char* pDest; - char cSrc; - for (pDest = dest; *src != 0; pDest++) { - cSrc = *src++; - *pDest = cSrc; +char* Mail_strcpy(char* pDst, const char* pSrc) { + char* pOrigin = pDst; + + while (*pSrc != '\0') { + *pDst++ = *pSrc++; } - *pDest = 0; - return dest; + + *pDst = '\0'; + return pOrigin; } -int Mail_strlen(const char* str) { - int i; - for (i = 0; *str != 0; i++, str++) { +int Mail_strlen(const char* pStr) { + int len = 0; + + while (pStr[len] != '\0') { + len++; } - return i; + + return len; } -char* Mail_strcat(char* dest, const char* src) { - int i; - char* pDest; +int STD_strnlen(const char* pStr, size_t maxlen) { + size_t len = 0; - pDest = dest; - for (i = 0; *pDest != 0; pDest++, i++) { - } - pDest = dest + i; - while (*src != 0) { - *pDest++ = *src++; - } - *pDest = 0; - return dest; -} - -int STD_strnlen(const char* str, u32 len) { - int i; - for (i = 0; i < len; i++, str++) { - if (*str == 0) { + for (; len < maxlen; len++) { + if (pStr[len] == '\0') { break; } } - return i; + + return len; +} + +void* Mail_memcpy(void* pDst, const void* pSrc, u32 n) { + size_t i; + + for (i = 0; i < n; i++) { + ((u8*)pDst)[i] = ((u8*)pSrc)[i]; + } + + return pDst; +} + +void* Mail_memset(void* pDst, int ch, u32 n) { + size_t i; + + for (i = 0; i < n; i++) { + ((u8*)pDst)[i] = ch; + } + + return pDst; +} + +char* Mail_strncpy(char* dest, const char* src, u32 len) { + u32 i; + + i = 0; + for (; i < len; i++) { + dest[i] = src[i]; + if (src[i] == 0) { + while (++i < len) { + dest[i] = 0; + } + return dest; + } + } + return dest; +} + +char* Mail_strcat(char* pDst, const char* pSrc) { + Mail_strcpy(pDst + Mail_strlen(pDst), pSrc); + return pDst; +} + +char* Mail_strncat(char* pDst, const char* pSrc, u32 maxlen) { + int len = Mail_strlen(pDst); + int i; + + for (i = 0; i < maxlen && pSrc[i] != '\0'; i++) { + pDst[len + i] = pSrc[i]; + } + + pDst[len + i] = '\0'; + return pDst; } int Mail_strncmp(const char* str1, const char* str2, u32 len) { @@ -98,3 +141,271 @@ int Mail_tolower(int ch) { } return ch; } + +static void set_to_head(char* pStr, char ch) { + int i; + + for (i = Mail_strlen(pStr); i >= 0; i--) { + pStr[i + 1] = pStr[i]; + } + + *pStr = ch; +} + +static void set_to_tail(char* pStr, char ch) { + int i = Mail_strlen(pStr); + + pStr[i++] = ch; + pStr[i] = '\0'; +} + +static s32 convNum(char* pDst, u32 number, s32 numberBase, char charBase, + BOOL isSigned, s32 width, char specifierChar, + char justifyChar) { + + s32 charsWritten; + s32 digitsWritten; + char remainder; + + if (isSigned && (number & 0x80000000)) { + isSigned = TRUE; + number = -number; + } else { + isSigned = FALSE; + number = number; + } + + charsWritten = digitsWritten = 0; + + while (number != 0) { + remainder = number % numberBase; + number /= numberBase; + + set_to_head(pDst, remainder + (char)(remainder > 9 ? charBase : '0')); + digitsWritten++; + charsWritten++; + } + + if (*pDst == '\0') { + set_to_head(pDst, '0'); + digitsWritten++; + charsWritten++; + } + + if (specifierChar != '0') { + specifierChar = ' '; + } + + digitsWritten += isSigned; + + while (digitsWritten < width) { + if (justifyChar == 'L') { + set_to_tail(pDst, ' '); + charsWritten++; + } else { + set_to_head(pDst, specifierChar); + charsWritten++; + } + + digitsWritten++; + } + + if (isSigned) { + set_to_head(pDst, '-'); + } + + return charsWritten; +} + + + +int Mail_sprintf(char* pDst, char* pFmt, ...) { + va_list argv; + int ret; + + va_start(argv, pFmt); + ret = Mail_vsprintf(pDst, pFmt, &argv); + va_end(argv); + + return ret; +} + +int Mail_vsprintf(char* pDst, char* pFmt, va_list* argv) { + int charsWritten; + BOOL isNumberFormat; + BOOL isSigned; + s32 stringLength; + s32 numberBase; + s32 width; + char formatChar; + char justifyChar; + char specifierChar; + char charBase; + char* pStrArg; + char longFlag; + u32 number; + + *pDst = 0; + charsWritten = 0; + + while ((formatChar = *pFmt++) != '\0') { + while (*pDst != '\0') { + pDst++; + } + + if (formatChar == '%') { + formatChar = *pFmt++; + + if (formatChar == '%') { + set_to_tail(pDst++, formatChar); + charsWritten++; + } else { + justifyChar = formatChar; + if (formatChar == '-') { + formatChar = *pFmt++; + } + + specifierChar = formatChar; + isSigned = FALSE; + numberBase = 10; + charBase = '0'; + isNumberFormat = FALSE; + + if (formatChar == '*') { + width = va_arg(*argv, s32); + formatChar = *pFmt++; + } else { + width = 0; + + while (formatChar >= '0' && formatChar <= '9') { + width = width * 10 + formatChar - '0'; + formatChar = *pFmt++; + } + } + + if ((longFlag = formatChar & (u8)~0x20) == 'L') { + formatChar = *pFmt++; + } + + switch (formatChar) { + case 'd': { + isNumberFormat = TRUE; + isSigned = TRUE; + break; + } + + case 'o': { + isNumberFormat = TRUE; + numberBase = 8; + break; + } + + case 'u': { + isNumberFormat = TRUE; + break; + } + + case 'x': { + isNumberFormat = TRUE; + numberBase = 16; + charBase = 'a' - 10; + break; + } + + case 'X': { + isNumberFormat = TRUE; + numberBase = 16; + charBase = 'A' - 10; + break; + } + + case 'c': { + formatChar = va_arg(*argv, s32); + set_to_tail(pDst++, formatChar); + charsWritten++; + break; + } + + case 's': { + pStrArg = va_arg(*argv, char*); + + if (pStrArg) { + stringLength = Mail_strlen(pStrArg); + Mail_strcat(pDst, pStrArg); + } else { + stringLength = 0; + } + + charsWritten += stringLength; + + while (stringLength < width) { + charsWritten++; + + if (justifyChar == '-') { + set_to_tail(pDst, ' '); + } else { + set_to_head(pDst, ' '); + } + + stringLength++; + } + break; + } + } + + if (isNumberFormat) { + if (longFlag == 'L') { + number = va_arg(*argv, u32); + } else if (isSigned) { + number = va_arg(*argv, s32); + } else { + number = va_arg(*argv, u32); + } + + charsWritten += + convNum(pDst, number, numberBase, charBase, isSigned, + width, specifierChar, justifyChar); + } + } + + } else { + set_to_tail(pDst++, formatChar); + charsWritten++; + } + } + + return charsWritten; +} + +int Mail_strnicmp(const char* str1, const char* str2, int len) { + int i; + int c2; + int c1; + int result; + + result = 0; + for (i = 0; i < len; i++) { + c1 = *str1; + c2 = *str2; + if (c1 >= 'A') { + if (c1 <= 'Z') { + c1 += 0x20; + } + } + if (c2 >= 'A') { + if (c2 <= 'Z') { + c2 += 0x20; + } + } + result = c1 - c2; + if (result != 0) { + break; + } + if (c2 == 0) { + break; + } + str2++; + str1++; + } + return result; +} -- 2.49.1 From 7bf0665f404fc4172c5481ebc9c2429848bbc90a Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 07:05:55 +0000 Subject: [PATCH 2/3] Link eZiText zaddress unit --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 3b254487..080fb783 100644 --- a/configure.py +++ b/configure.py @@ -980,7 +980,7 @@ config.libs = [ ] ), ZI8Lib("zi8clib", [ - Object(NonMatching, "clib/zaddress.c"), + Object(Matching, "clib/zaddress.c"), Object(NonMatching, "clib/zconvert.c"), Object(NonMatching, "clib/zi81key.c"), Object(NonMatching, "clib/zi8alpha.c"), -- 2.49.1 From cd2a12624327f6a44efd233af0cdacd8e7e3cffc Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 07:06:07 +0000 Subject: [PATCH 3/3] decomp: match RevoEX ncdsystem --- libs/RevoEX/src/ncd/ncdsystem.c | 585 ++++++++++++++++++++++++++++++++ 1 file changed, 585 insertions(+) create mode 100644 libs/RevoEX/src/ncd/ncdsystem.c diff --git a/libs/RevoEX/src/ncd/ncdsystem.c b/libs/RevoEX/src/ncd/ncdsystem.c new file mode 100644 index 00000000..5a320518 --- /dev/null +++ b/libs/RevoEX/src/ncd/ncdsystem.c @@ -0,0 +1,585 @@ +#include +#include +#include +#include +#include + +#include + +#define NCD_IPC_HEAP_SIZE 0x1B60 +#define NCD_MAX_PROFILE 3 + +static u32 ncdInitialized; +static NCDConfig* ncdCommonBuffer; + +struct NCDMutex { + OSMutex mutex; + u8 padding[8]; +} ncdMutex; +s32 ncdCommonResult[8] ATTRIBUTE_ALIGN(32); +IOSIoVector ncdCommonVector[4] ATTRIBUTE_ALIGN(32); + +const char* __NCDVersion = "<< RVL_SDK - NCD \trelease build: Dec 12 2008 03:06:03 (0x4199_60831) >>"; +const char* __NCDUnofficialVersion = "<< RVL_SDK - NCD \trelease build: Dec 12 2008 03:06:03 (0x4199_60831) UNOFFICIAL >>"; + +static void LockRight(void); +static NCDErr ExecConfigCommand(const char* name, NCDConfig* config, u32 command); +static NCDErr NCDiGetWirelessMacAddress(u8* macAddr); + +NCDErr NCDReadConfig(NCDConfig* config) { + if (config == NULL) { + return -3; + } + + return ExecConfigCommand("NCDReadConfig", config, 5); +} + +NCDErr NCDWriteConfig(const NCDConfig* config) { + BOOL enabled; + + enabled = OSDisableInterrupts(); + if (!(ncdInitialized & 2)) { + OSRegisterVersion(__NCDUnofficialVersion); + ncdInitialized |= 2; + } + OSRestoreInterrupts(enabled); + + if (config == NULL) { + return -3; + } + + return ExecConfigCommand("NCDWriteConfig", (NCDConfig*)config, 6); +} + +NCDErr NCDSetIfConfig(NCDIfConfig* ifConfig) { + union { + BOOL enabled; + NCDConfig* config; + } state; + NCDErr lockErr; + NCDProfile* profile; + NCDErr result; + s32 i; + u32 count; + + state.enabled = OSDisableInterrupts(); + if (!(ncdInitialized & 2)) { + OSRegisterVersion(__NCDUnofficialVersion); + ncdInitialized |= 2; + } + OSRestoreInterrupts(state.enabled); + + + if (ifConfig == NULL) { + return -3; + } + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + lockErr = NWC24iLockSocket(); + if (lockErr == 0) { + result = ExecConfigCommand("NCDSetIfConfig", NULL, 3); + if (result == 0) { + state.config = ncdCommonBuffer; + + if (ifConfig->selectedMedia != 1 && ifConfig->selectedMedia != 2) { + state.config->selectedMedia = 0; + } else { + state.config->selectedMedia = ifConfig->selectedMedia; + profile = state.config->profiles; + i = 0; + state.config->linkTimeout = ifConfig->linkTimeout; + count = 0; + for (; i < NCD_MAX_PROFILE; i++, profile++) { + if (state.config->profiles[i].flags & 0x80) { + switch (ifConfig->selectedMedia) { + case 1: + state.config->profiles[i].flags &= ~1; + memcpy(&profile->netif, &ifConfig->netif, 0x15c); + break; + case 2: + state.config->profiles[i].flags |= 1; + memcpy(&profile->netif, &ifConfig->netif, 4); + break; + } + count++; + } + } + + if (count == 0) { + state.config->profiles[0].flags |= 0x80; + switch (ifConfig->selectedMedia) { + case 1: + state.config->profiles[0].flags &= ~1; + memcpy(&state.config->profiles[0].netif.wireless, &ifConfig->netif, 0x15c); + break; + case 2: + state.config->profiles[0].flags |= 1; + memcpy(&state.config->profiles[0].netif.wired, &ifConfig->netif, 4); + break; + } + memset(&state.config->profiles[0].adjust, 0, 0xc); + state.config->profiles[0].flags |= 6; + memset(&state.config->profiles[0].ip, 0, 0x14); + state.config->profiles[0].flags &= ~0x10; + memset(&state.config->profiles[0].proxy, 0, 0x79c); + } + } + result = ExecConfigCommand("NCDSetIfConfig", NULL, 4); + } + NWC24iUnlockSocket(); + } else if (lockErr == -0x16) { + result = -4; + } else if (lockErr == -0x1d) { + result = -8; + } else { + result = -2; + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return result; +} + +NCDErr NCDSetIpConfig(NCDIpConfig* ipConfig) { + NCDErr err; + BOOL enabled; + s32 i; + u32 count; + NCDConfig* config; + + enabled = OSDisableInterrupts(); + if (!(ncdInitialized & 2)) { + OSRegisterVersion(__NCDUnofficialVersion); + ncdInitialized |= 2; + } + OSRestoreInterrupts(enabled); + + if (ipConfig == NULL) { + return -3; + } + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + err = NWC24iLockSocket(); + if (err == 0) { + err = ExecConfigCommand("NCDSetIpConfig", NULL, 3); + if (err == 0) { + i = 0; + count = 0; + config = ncdCommonBuffer; + for (; i < NCD_MAX_PROFILE; i++) { + if (config->profiles[i].flags & 0x80) { + NCDProfile* profile = &config->profiles[i]; + + memcpy(&profile->adjust, &ipConfig->adjust, 0xc); + if (ipConfig->useDhcp == 1) { + config->profiles[i].flags |= 6; + memcpy(&profile->ip, &ipConfig->ip, 0x14); + } else { + config->profiles[i].flags &= ~6; + memcpy(&profile->ip, &ipConfig->ip, 0x14); + } + if (ipConfig->useProxy == 1) { + config->profiles[i].flags |= 0x10; + memcpy(&profile->proxy, &ipConfig->proxy, 0x79c); + } else { + config->profiles[i].flags &= ~0x10; + memset(&profile->proxy, 0, 0x79c); + } + count++; + } + } + + if (count == 0) { + NCDProfile* profile = config->profiles; + profile->flags |= 0x80; + memcpy(&profile->adjust, &ipConfig->adjust, 0xc); + if (ipConfig->useDhcp == 1) { + profile->flags |= 6; + memcpy(&profile->ip, &ipConfig->ip, 0x14); + } else { + profile->flags &= ~6; + memcpy(&profile->ip, &ipConfig->ip, 0x14); + } + if (ipConfig->useProxy == 1) { + profile->flags |= 0x10; + memcpy(&profile->proxy, &ipConfig->proxy, 0x79c); + } else { + profile->flags &= ~0x10; + memset(&profile->proxy, 0, 0x79c); + } + profile->flags = profile->flags & ~1; + memset(&profile->netif, 0, 0x15c); + } + err = ExecConfigCommand("NCDSetIpConfig", NULL, 4); + } + NWC24iUnlockSocket(); + } else if (err == -0x16) { + err = -4; + } else if (err == -0x1d) { + err = -8; + } else { + err = -2; + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +NCDErr NCDGetCurrentIpConfig(NCDIpConfig* ipConfig) { + NCDErr err = 0; + NCDConfig* config; + s32 idx; + + if (ipConfig == NULL) { + return -3; + } + + LockRight(); + err = ExecConfigCommand("NCDGetCurrentIpConfig", 0, 3); + if (err == 0) { + config = ncdCommonBuffer; + idx = ncdCommonResult[1]; + + if (idx < 0 || idx >= NCD_MAX_PROFILE) { + err = -7; + } else { + memcpy(&ipConfig->adjust, &config->profiles[idx].adjust, 0xc); + + if (config->profiles[idx].flags & 0x6) { + ipConfig->useDhcp = TRUE; + memcpy(&ipConfig->ip, &config->profiles[idx].ip, 0x14); + } else { + ipConfig->useDhcp = FALSE; + memcpy(&ipConfig->ip, &config->profiles[idx].ip, 0x14); + } + + if (config->profiles[idx].flags & 0x10) { + ipConfig->useProxy = TRUE; + memcpy(&ipConfig->proxy, &config->profiles[idx].proxy, 0x79c); + } else { + ipConfig->useProxy = FALSE; + memset(&ipConfig->proxy, 0, 0x79c); + } + } + } + + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +NCDErr NCDGetLinkStatus(void) { + NCDErr err; + s32 fd; + + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + fd = IOS_Open("/dev/net/ncd/manage", 0); + if (fd < 0) { + if (fd == -6) { + err = -8; + } else { + err = -2; + } + } else { + ncdCommonVector[0].base = (u8*)ncdCommonResult; + ncdCommonVector[0].length = sizeof(ncdCommonResult); + if (IOS_Ioctlv(fd, 7, 0, 1, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + if (err == 0) { + err = ncdCommonResult[1]; + err = err >= 0 ? err : -1; + } + } + if (IOS_Close(fd) < 0) { + err = -1; + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +BOOL NCDIsInterfaceDecided(void) { + NCDErr err = NCDGetLinkStatus(); + + switch (err) { + case 3: + case 4: + case 5: + return TRUE; + default: + return FALSE; + } +} + +NCDErr NCDGetWirelessMacAddress(u8* macAddr) { + return NCDiGetWirelessMacAddress(macAddr); +} + +static NCDErr NCDiGetWirelessMacAddress(u8* macAddr) { + NCDErr err = 0; + s32 fd; + + if (macAddr == NULL) { + return -3; + } + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + fd = IOS_Open("/dev/net/ncd/manage", 0); + if (fd < 0) { + if (fd == -6) { + err = -8; + } else { + err = -2; + } + } else { + ncdCommonVector[0].base = (u8*)ncdCommonResult; + ncdCommonVector[0].length = sizeof(ncdCommonResult); + ncdCommonVector[1].base = (u8*)ncdCommonBuffer; + ncdCommonVector[1].length = NCD_MAC_ADDRESS_LENGTH; + if (IOS_Ioctlv(fd, 8, 0, 2, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + if (err == 0) { + memcpy(macAddr, ncdCommonBuffer, NCD_MAC_ADDRESS_LENGTH); + } + } + if (IOS_Close(fd) < 0) { + err = -1; + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +NCDErr NCDLockWirelessDriver(void) { + NCDErr err; + s32 fd; + + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + fd = IOS_Open("/dev/net/ncd/manage", 0); + if (fd < 0) { + if (fd == -6) { + err = -8; + } else { + err = -2; + } + } else { + ncdCommonVector[0].base = (u8*)ncdCommonResult; + ncdCommonVector[0].length = sizeof(ncdCommonResult); + if (IOS_Ioctlv(fd, 1, 0, 1, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + if (err == 0) { + err = ncdCommonResult[1]; + err = err > 0 ? err : -1; + } + } + if (IOS_Close(fd) < 0) { + err = -1; + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +NCDErr NCDUnlockWirelessDriver(s32 id) { + NCDErr err; + s32 fd; + + if (id <= 0) { + return -3; + } + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + fd = IOS_Open("/dev/net/ncd/manage", 0); + if (fd < 0) { + if (fd == -6) { + err = -8; + } else { + err = -2; + } + } else { + ncdCommonVector[0].base = (u8*)ncdCommonBuffer; + ncdCommonVector[0].length = 4; + ncdCommonVector[1].base = (u8*)ncdCommonResult; + ncdCommonVector[1].length = sizeof(ncdCommonResult); + ncdCommonBuffer->version = id; + if (IOS_Ioctlv(fd, 2, 1, 1, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + } + if (IOS_Close(fd) < 0) { + err = -1; + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +s32 NCDRestoreConfig(void) { + NCDErr err; + + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + err = NWC24iLockSocket(); + if (err == 0) { + err = ExecConfigCommand("NCDRestoreConfig", NULL, 5); + if (err == 0) { + err = ExecConfigCommand("NCDRestoreConfig", NULL, 4); + } + NWC24iUnlockSocket(); + } else if (err == -0x16) { + err = -4; + } else if (err == -0x1d) { + err = -8; + } else { + err = -2; + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +NCDErr NCDiGetEnabledConfigList(u32* list0, u32* list1, u32* list2) { + NCDErr err; + u32 mask0 = 0; + u32 mask1 = 0; + u32 mask2 = 0; + u8 flags; + u32 i; + + LockRight(); + err = ExecConfigCommand("NCDiGetEnabledConfigList", NULL, 3); + if (err == 0) { + for (i = 0; i < NCD_MAX_PROFILE; i++) { + NCDProfile* profile = &ncdCommonBuffer->profiles[i]; + + flags = profile->flags; + + if (flags & 0x80) { + if (flags & 1) { + mask0 |= 1 << i; + } else { + if (profile->netif.wireless.configMethod != 1) { + mask1 |= 1 << i; + } + if (ncdCommonBuffer->profiles[i].netif.wireless.configMethod == 1) { + mask2 |= 1 << i; + } + } + } + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + + if (list0 != NULL) { + *list0 = mask0; + } + if (list1 != NULL) { + *list1 = mask1; + } + if (list2 != NULL) { + *list2 = mask2; + } + return err; +} + +static NCDErr ExecConfigCommand(const char* name, NCDConfig* config, u32 command) { + NCDErr err = 0; + s32 fd; + + if (!OSGetCurrentThread()) { + return -5; + } + + LockRight(); + fd = IOS_Open("/dev/net/ncd/manage", 0); + if (fd < 0) { + if (fd == -6) { + err = -8; + } else { + err = -2; + } + } else { + ncdCommonVector[0].base = (u8*)ncdCommonBuffer; + ncdCommonVector[0].length = sizeof(NCDConfig); + ncdCommonVector[1].base = (u8*)ncdCommonResult; + ncdCommonVector[1].length = sizeof(ncdCommonResult); + + switch (command) { + case 3: + case 5: + if (IOS_Ioctlv(fd, command, 0, 2, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + if (err == 0 && config != NULL) { + memcpy(config, ncdCommonBuffer, sizeof(NCDConfig)); + } + } + break; + case 4: + case 6: + if (config != NULL) { + memcpy(ncdCommonBuffer, config, sizeof(NCDConfig)); + } + if (IOS_Ioctlv(fd, command, 1, 1, ncdCommonVector) < 0) { + err = -2; + } else { + err = ncdCommonResult[0]; + } + break; + } + if (IOS_Close(fd) < 0) { + err = -1; + } + } + OSUnlockMutex((OSMutex*)&ncdMutex); + return err; +} + +static void LockRight(void) { + BOOL enabled; + void* lo; + + enabled = OSDisableInterrupts(); + if (!(ncdInitialized & 1)) { + OSRegisterVersion(__NCDVersion); + OSInitMutex((OSMutex*)&ncdMutex); + lo = (void*)OSRoundUp32B(IPCGetBufferLo()); + if ((u32)IPCGetBufferHi() - (u32)lo < NCD_IPC_HEAP_SIZE) { + OSPanic("ncdsystem.c", 0x5B1, "Could not reserve heap for NCD library from IPC arena"); + } + IPCSetBufferLo((u8*)lo + NCD_IPC_HEAP_SIZE); + ncdCommonBuffer = (NCDConfig*)lo; + memset(ncdCommonBuffer, 0, NCD_IPC_HEAP_SIZE); + memset(ncdCommonResult, 0, sizeof(ncdCommonResult)); + memset(ncdCommonVector, 0, sizeof(ncdCommonVector)); + ncdInitialized |= 1; + } + OSRestoreInterrupts(enabled); + OSLockMutex((OSMutex*)&ncdMutex); +} -- 2.49.1