847 lines
29 KiB
C++
847 lines
29 KiB
C++
#include "scene/setting/iplNCDSetting.h"
|
|
|
|
#include <revolution/ncd.h>
|
|
#include <revolution/net.h>
|
|
#include <revolution/os.h>
|
|
#include <revolution/sc.h>
|
|
|
|
#include "scene/setting/iplParental.h"
|
|
|
|
#include "utility/iplCharacterCode.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
namespace ipl {
|
|
namespace ncd {
|
|
// If you change one thing in this function, checkFlag will not match.
|
|
// Probably some stripped out function, but... I don't get MWCC
|
|
#ifndef NON_MATCHING
|
|
void NCDSetting::matchHack() {
|
|
u16 myNewMode;
|
|
|
|
if (mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode == 2 ||
|
|
(strlen((const char*)mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.wep104.key) > 20)) {
|
|
myNewMode = 2;
|
|
}
|
|
|
|
if (mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode != myNewMode) {
|
|
mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode = myNewMode;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
NCDConfig NCDSetting::mConfig;
|
|
NCDConfig NCDSetting::mSaveConfig;
|
|
u8 NCDSetting::mMac[0x20];
|
|
|
|
u16 NCDSetting::mID;
|
|
u32 NCDSetting::mMacNum;
|
|
|
|
void NCDSetting::init() {
|
|
memset(&mConfig, 0, sizeof(mConfig));
|
|
int status = NCDReadConfig(&mConfig);
|
|
OSReport("NCDReadConfig: %d\n", status);
|
|
makeMacAddr();
|
|
}
|
|
|
|
void NCDSetting::initSetID(u16 setID) {
|
|
mID = setID;
|
|
}
|
|
|
|
int NCDSetting::checkFlag(int id) {
|
|
int ret = 0;
|
|
int flags = mConfig.profiles[id].flags;
|
|
|
|
if (flags & NCD_DHCP_FLAG) {
|
|
return 1;
|
|
}
|
|
|
|
if (mConfig.profiles[id].netif.wireless.config.manual.ssidLength == 0 && mConfig.profiles[id].netif.wireless.configMethod == 0 &&
|
|
mConfig.profiles[id].netif.wireless.config.manual.privacy.mode == 0) {
|
|
return 0;
|
|
}
|
|
|
|
switch (mConfig.profiles[id].netif.wireless.configMethod) {
|
|
case 0: {
|
|
ret = 2;
|
|
break;
|
|
}
|
|
case 1: {
|
|
ret = 3;
|
|
break;
|
|
}
|
|
case 2: {
|
|
ret = 4;
|
|
break;
|
|
}
|
|
case 3: {
|
|
ret = 5;
|
|
break;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int NCDSetting::checkThisFlag() {
|
|
return checkFlag(mID);
|
|
}
|
|
|
|
bool NCDSetting::checkAllFlag() {
|
|
for (int i = 0; i < 3; i++) {
|
|
if (checkFlag(i) & 0xFF) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
u8 NCDSetting::checkConnectTestFlag() {
|
|
return (mConfig.profiles[mID].flags) >> NCD_CONNECT_TEST_FLAG & 1;
|
|
}
|
|
|
|
u8 NCDSetting::checkDHCPFlag() {
|
|
return (mConfig.profiles[mID].flags) >> NCD_DHCP_FLAG & 1;
|
|
}
|
|
|
|
u8 NCDSetting::checkDNSFlag() {
|
|
if ((mConfig.profiles[mID].flags & NCD_DNS_FLAG) != 0) {
|
|
return (u8)mConfig.profiles[mID].flags >> NCD_DNS_FLAG & 1;
|
|
} else {
|
|
setDNSFlag(0);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
void NCDSetting::checkDHCP_() {
|
|
if (checkDNSFlag()) {
|
|
memset(&mConfig.profiles[mID].ip.dns1, 0, sizeof(mConfig.profiles[mID].ip.dns1));
|
|
memset(&mConfig.profiles[mID].ip.dns2, 0, sizeof(mConfig.profiles[mID].ip.dns2));
|
|
} else {
|
|
// im sorry for this
|
|
int i = 0;
|
|
int remaining = 4;
|
|
|
|
for (; i < 4; i++) {
|
|
if (mConfig.profiles[mID].ip.dns1[i] != 0) {
|
|
break;
|
|
}
|
|
remaining--;
|
|
}
|
|
if (i == 4) {
|
|
i = 0;
|
|
remaining = 4;
|
|
for (; i < 4; i++) {
|
|
if (mConfig.profiles[mID].ip.dns2[i] != 0) {
|
|
break;
|
|
}
|
|
remaining--;
|
|
}
|
|
if (i == 4) {
|
|
mConfig.profiles[mID].flags |= 4;
|
|
}
|
|
}
|
|
}
|
|
if (checkDHCPFlag()) {
|
|
memset(&mConfig.profiles[mID].ip.addr, 0, sizeof(mConfig.profiles[mID].ip.addr));
|
|
memset(&mConfig.profiles[mID].ip.netmask, 0, sizeof(mConfig.profiles[mID].ip.netmask));
|
|
memset(&mConfig.profiles[mID].ip.gateway, 0, sizeof(mConfig.profiles[mID].ip.gateway));
|
|
}
|
|
return;
|
|
}
|
|
|
|
u8 NCDSetting::checkProxyFlag() {
|
|
return mConfig.profiles[mID].proxy.http.mode;
|
|
}
|
|
|
|
u8 NCDSetting::checkBasic() {
|
|
return mConfig.profiles[mID].proxy.http.authType;
|
|
}
|
|
|
|
bool NCDSetting::checkChangeEnable() {
|
|
u8 configMethod = mConfig.profiles[mID].netif.wireless.configMethod;
|
|
return (u8)(configMethod + (u8)-1) > 1;
|
|
}
|
|
|
|
bool NCDSetting::convert16toASCII(char hexHi, char hexLo, u8* byte) {
|
|
bool inRange = true;
|
|
|
|
if (hexHi >= '0' && hexHi <= '9') {
|
|
*byte = (hexHi - '0') << 4;
|
|
} else if (hexHi >= 'A' && hexHi <= 'F') {
|
|
*byte = (hexHi - 'A' + 10) << 4;
|
|
} else if (hexHi >= 'a' && hexHi <= 'f') {
|
|
*byte = (hexHi - 'a' + 10) << 4;
|
|
} else {
|
|
inRange = false;
|
|
}
|
|
|
|
if (hexLo >= '0' && hexLo <= '9') {
|
|
*byte = *byte + (u8)(hexLo - '0');
|
|
} else if (hexLo >= 'A' && hexLo <= 'F') {
|
|
*byte = *byte + (u8)(hexLo - 'A' + 10);
|
|
} else if (hexLo >= 'a' && hexLo <= 'f') {
|
|
*byte = *byte + (u8)(hexLo - 'a' + 10);
|
|
} else {
|
|
inRange = false;
|
|
}
|
|
|
|
return inRange;
|
|
}
|
|
|
|
int NCDSetting::checkWEPKey(char* key) {
|
|
int keyLen;
|
|
int ret;
|
|
u8 asciiKey[14];
|
|
|
|
keyLen = strlen(key);
|
|
ret = -1;
|
|
memset(asciiKey, 0, sizeof(asciiKey));
|
|
|
|
if (keyLen == 0) {
|
|
ret = 0;
|
|
} else {
|
|
if ((u16)getPrivacyMode() > 1) {
|
|
if (8 <= keyLen && keyLen < 64) {
|
|
ret = keyLen;
|
|
} else if (keyLen == 64) {
|
|
for (int i = 0; i < 64; i++) {
|
|
char c = key[i];
|
|
if ((c < '0' || '9' < c) && (c < 'A' || 'F' < c) && (c < 'a' || 'f' < c)) {
|
|
return -1;
|
|
}
|
|
}
|
|
ret = keyLen;
|
|
}
|
|
} else {
|
|
if (keyLen == 10 || keyLen == 26) {
|
|
int i = 0, outLen = 0;
|
|
while (i < keyLen) {
|
|
if (!convert16toASCII(key[i], key[i + 1], &asciiKey[outLen]))
|
|
return -1;
|
|
i += 2;
|
|
outLen++;
|
|
}
|
|
|
|
if (i == 10 || i == 26) {
|
|
memcpy(key, asciiKey, i);
|
|
mConfig.profiles[mID].netif.wireless.config.aoss.wep40.key[1][1] = 1;
|
|
return i / 2;
|
|
} else {
|
|
// I think this is unreachable?
|
|
return -1;
|
|
}
|
|
} else if (keyLen == 5 || keyLen == 13) {
|
|
mConfig.profiles[mID].netif.wireless.config.aoss.wep40.key[1][1] = 0;
|
|
ret = keyLen;
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// Proxy rules:
|
|
// - At most 255 chars
|
|
// - Cannot start with a dot
|
|
// - All chars must be alphanumeric, hypen, dot, or underscore
|
|
// - Cannot have consecutive dots
|
|
bool NCDSetting::checkProxy(char* proxy) {
|
|
int len;
|
|
char c;
|
|
int i;
|
|
|
|
len = strlen(proxy);
|
|
if (len >= 256) {
|
|
return false;
|
|
}
|
|
if (proxy[0] == '.') {
|
|
return false;
|
|
}
|
|
|
|
for (i = 0; i < len; i++) {
|
|
c = proxy[i];
|
|
// Allowed characters are alphanumeric, hyphen, dot, and underscore
|
|
// [0-9a-zA-Z_\-\.]
|
|
if ((c < '0' || '9' < c) && (c < 'a' || 'z' < c) && (c < 'A' || 'Z' < c) && c != '-' && c != '.' && c != '_') {
|
|
return false;
|
|
}
|
|
// No consecutive dots
|
|
if (c == '.' && proxy[i + 1] == '.') {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Checks that proxy is at most 32 chars and that all chars are
|
|
// printable ascii
|
|
bool NCDSetting::checkProxyBasic(char* proxy) {
|
|
int len = strlen(proxy);
|
|
if (len >= 33) {
|
|
return false;
|
|
} else {
|
|
for (int i = 0; i < len; i++) {
|
|
if ((proxy[i] < ' ') || (proxy[i] > '~')) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
void NCDSetting::adjustNCDData_() {
|
|
int i;
|
|
int theOne;
|
|
theOne = -1;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
if ((mConfig.profiles[i].flags & 0x80) != 0) {
|
|
adjustSelectMedia_(i);
|
|
adjustEnableFlag_(i);
|
|
theOne = i;
|
|
break;
|
|
}
|
|
if (theOne == -1 && mConfig.profiles[i].flags & 0x20) {
|
|
theOne = i;
|
|
}
|
|
if (i == 2 && theOne != -1) {
|
|
mConfig.profiles[theOne].flags |= 0x80;
|
|
adjustSelectMedia_(theOne);
|
|
adjustEnableFlag_(theOne);
|
|
}
|
|
}
|
|
if (theOne == -1) {
|
|
mConfig.selectedMedia = 0;
|
|
}
|
|
}
|
|
|
|
void NCDSetting::adjustSelectMedia_(int exclude) {
|
|
u8 flag = checkFlag(exclude);
|
|
switch (flag) {
|
|
case 1: {
|
|
mConfig.selectedMedia = 2;
|
|
break;
|
|
}
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5: {
|
|
mConfig.selectedMedia = 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void NCDSetting::adjustEnableFlag_(int exclude) {
|
|
for (int i = 0; i < 3; i++) {
|
|
if (exclude != i) {
|
|
mConfig.profiles[i].flags &= 0x7F;
|
|
}
|
|
}
|
|
}
|
|
|
|
void NCDSetting::setConnectTestFlag(bool newFlag) {
|
|
if (newFlag) {
|
|
mConfig.profiles[mID].flags |= 0x20;
|
|
for (int i = 0; i < 3; i++) {
|
|
if (mID == i) {
|
|
mConfig.profiles[mID].flags |= 0x80;
|
|
} else {
|
|
mConfig.profiles[i].flags &= 0x7F;
|
|
}
|
|
}
|
|
}
|
|
adjustNCDData_();
|
|
adjustNWC24FlagEx_();
|
|
NCDWriteConfig(&mConfig);
|
|
}
|
|
|
|
void NCDSetting::setDHCPFlag(u8 newFlag) {
|
|
if (newFlag != 0) {
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags | 2;
|
|
return;
|
|
}
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags & ~2;
|
|
}
|
|
|
|
void NCDSetting::setDNSFlag(u8 newFlag) {
|
|
if (newFlag != 0) {
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags | 4;
|
|
return;
|
|
}
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags & ~4;
|
|
}
|
|
|
|
void NCDSetting::setProxyFlag(u8 newFlag) {
|
|
mConfig.profiles[mID].proxy.http.mode = newFlag;
|
|
mConfig.profiles[mID].proxy.ssl.mode = newFlag;
|
|
if (newFlag != 0) {
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags | 0x10;
|
|
return;
|
|
}
|
|
mConfig.profiles[mID].flags = mConfig.profiles[mID].flags & ~0x10;
|
|
}
|
|
|
|
void NCDSetting::setBasicFlag(u8 newFlag) {
|
|
mConfig.profiles[mID].proxy.http.authType = newFlag;
|
|
mConfig.profiles[mID].proxy.ssl.authType = newFlag;
|
|
}
|
|
|
|
void NCDSetting::setWired() {
|
|
memset(&mConfig.profiles[mID], 0, sizeof(NCDProfile));
|
|
mConfig.version = 0;
|
|
mConfig.linkTimeout = 0;
|
|
mConfig.profiles[mID].flags = 7;
|
|
}
|
|
|
|
void NCDSetting::setWireless(u8 configMethod) {
|
|
memset(&mConfig.profiles[mID], 0, sizeof(NCDProfile));
|
|
|
|
mConfig.version = 0;
|
|
mConfig.linkTimeout = 0;
|
|
mConfig.profiles[mID].netif.wireless.configMethod = configMethod;
|
|
mConfig.profiles[mID].flags = 6;
|
|
if (configMethod == 0) {
|
|
memcpy(&mSaveConfig, &mConfig, sizeof(NCDConfig));
|
|
}
|
|
}
|
|
|
|
void NCDSetting::changeConnectType(u8 connectType) {
|
|
if (connectType == 1) {
|
|
mConfig.profiles[mID].flags |= 1;
|
|
return;
|
|
}
|
|
mConfig.profiles[mID].flags &= 0xfe;
|
|
}
|
|
|
|
void NCDSetting::setSSID(u8* newSSID) {
|
|
memcpy(mConfig.profiles[mID].netif.wireless.config.manual.ssid, newSSID, 32);
|
|
mConfig.profiles[mID].netif.wireless.config.manual.ssidLength = strlen((char*)newSSID);
|
|
}
|
|
|
|
void NCDSetting::setPrivacyMode(u16 newMode) {
|
|
u16 myNewMode;
|
|
|
|
switch (newMode) {
|
|
case 0: {
|
|
myNewMode = 0;
|
|
break;
|
|
}
|
|
case 1: {
|
|
if (mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode == 2 ||
|
|
(strlen((const char*)mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.wep104.key) > 20)) {
|
|
myNewMode = 2;
|
|
} else {
|
|
myNewMode = 1;
|
|
}
|
|
break;
|
|
}
|
|
case 2: {
|
|
myNewMode = 4;
|
|
break;
|
|
}
|
|
case 3: {
|
|
myNewMode = 6;
|
|
break;
|
|
}
|
|
case 4: {
|
|
myNewMode = 5;
|
|
break;
|
|
}
|
|
default: {
|
|
myNewMode = 0;
|
|
break;
|
|
}
|
|
}
|
|
if (mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode != myNewMode) {
|
|
mConfig.profiles[mID].netif.wireless.config.rakuraku.privacy.mode = myNewMode;
|
|
}
|
|
}
|
|
|
|
void NCDSetting::setWDPrivacyMode(u16 mode) {
|
|
u16 privacyMode;
|
|
|
|
switch (mode) {
|
|
case 0: {
|
|
privacyMode = 0;
|
|
break;
|
|
}
|
|
case 1: {
|
|
privacyMode = 1;
|
|
break;
|
|
}
|
|
case 2: {
|
|
privacyMode = 2;
|
|
break;
|
|
}
|
|
case 4: {
|
|
privacyMode = 4;
|
|
break;
|
|
}
|
|
case 5: {
|
|
privacyMode = 5;
|
|
break;
|
|
}
|
|
case 6: {
|
|
privacyMode = 6;
|
|
break;
|
|
}
|
|
case 7: {
|
|
privacyMode = 4;
|
|
break;
|
|
}
|
|
case 8: {
|
|
privacyMode = 1;
|
|
break;
|
|
}
|
|
default: {
|
|
privacyMode = 0;
|
|
break;
|
|
}
|
|
}
|
|
memset(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104, 0, 0x44);
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode = privacyMode;
|
|
}
|
|
|
|
void NCDSetting::setPrivacy(u8* newKey, int len) {
|
|
int i;
|
|
u8 mode;
|
|
mode = mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.reserved[0];
|
|
memset(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104, 0, 0x44);
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.reserved[0] = mode;
|
|
if (len == 0) {
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode = 0;
|
|
} else {
|
|
switch (mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode) {
|
|
case 1:
|
|
case 2: {
|
|
for (i = 0; i < 4; i++) {
|
|
if (len == 5) {
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode = 1;
|
|
memcpy(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.key[i], newKey,
|
|
sizeof(mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.key[i]));
|
|
} else if (len == 0xd) {
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode = 2;
|
|
memcpy(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104.key[i], newKey,
|
|
sizeof(mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104.key[i]));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case 4: {
|
|
memcpy(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.aes.key, newKey, len);
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.aes.keyLen = len;
|
|
break;
|
|
}
|
|
case 5:
|
|
case 6: {
|
|
memcpy(&mConfig.profiles[mID].netif.wireless.config.manual.privacy.tkip.key, newKey, len);
|
|
mConfig.profiles[mID].netif.wireless.config.manual.privacy.tkip.keyLen = len;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void NCDSetting::setIP(NCDIpProfile* ip) {
|
|
memcpy(&mConfig.profiles[mID].ip.addr, ip->addr, sizeof(mConfig.profiles[mID].ip.addr));
|
|
memcpy(&mConfig.profiles[mID].ip.netmask, ip->netmask, sizeof(mConfig.profiles[mID].ip.netmask));
|
|
memcpy(&mConfig.profiles[mID].ip.gateway, ip->gateway, sizeof(mConfig.profiles[mID].ip.gateway));
|
|
}
|
|
|
|
void NCDSetting::setDNS(NCDIpProfile* ip) {
|
|
memcpy(&mConfig.profiles[mID].ip.dns1, ip->dns1, sizeof(mConfig.profiles[mID].ip.dns1));
|
|
memcpy(&mConfig.profiles[mID].ip.dns2, ip->dns2, sizeof(mConfig.profiles[mID].ip.dns2));
|
|
}
|
|
|
|
void NCDSetting::setMTU(s32 mtu) {
|
|
mConfig.profiles[mID].adjust.maxTransferUnit = mtu;
|
|
mConfig.profiles[mID].adjust.tcpRetransTimeout = 0;
|
|
mConfig.profiles[mID].adjust.dhcpRetransCount = 0;
|
|
}
|
|
|
|
void NCDSetting::setProxy(NCDProxyServerProfile* proxyServerProfile) {
|
|
memcpy(&mConfig.profiles[mID].proxy.http.server, proxyServerProfile->server, sizeof(mConfig.profiles[mID].proxy.http.server));
|
|
memcpy(&mConfig.profiles[mID].proxy.ssl.server, proxyServerProfile->server, sizeof(mConfig.profiles[mID].proxy.ssl.server));
|
|
|
|
mConfig.profiles[mID].proxy.http.port = proxyServerProfile->port;
|
|
mConfig.profiles[mID].proxy.ssl.port = proxyServerProfile->port;
|
|
}
|
|
|
|
void NCDSetting::setBasic(NCDProxyServerProfile* proxyServerProfile) {
|
|
memcpy(mConfig.profiles[mID].proxy.http.username, proxyServerProfile->username, sizeof(mConfig.profiles[mID].proxy.http.username));
|
|
memcpy(mConfig.profiles[mID].proxy.ssl.username, proxyServerProfile->username, sizeof(mConfig.profiles[mID].proxy.ssl.username));
|
|
memcpy(mConfig.profiles[mID].proxy.http.password, proxyServerProfile->password, sizeof(mConfig.profiles[mID].proxy.http.password));
|
|
memcpy(mConfig.profiles[mID].proxy.ssl.password, proxyServerProfile->password, sizeof(mConfig.profiles[mID].proxy.ssl.password));
|
|
}
|
|
|
|
void NCDSetting::clearData() {
|
|
memset(&mConfig.profiles[mID].flags, 0, sizeof(NCDProfile));
|
|
adjustNCDData_();
|
|
adjustNWC24FlagEx_();
|
|
NCDWriteConfig(&mConfig);
|
|
}
|
|
|
|
void NCDSetting::clearLocal() {
|
|
memset(&mConfig.profiles[mID].flags, 0, sizeof(NCDProfile));
|
|
}
|
|
|
|
void NCDSetting::write() {
|
|
checkDHCP_();
|
|
if (mConfig.profiles[mID].flags & NCD_DHCP_FLAG) {
|
|
memset(&mConfig.profiles[mID].netif.wireless, 0, sizeof(NCDWirelessProfile));
|
|
}
|
|
|
|
mConfig.profiles[mID].flags &= ~0x20;
|
|
mConfig.profiles[mID].flags &= 0x7F;
|
|
adjustNCDData_();
|
|
adjustNWC24FlagEx_();
|
|
|
|
NCDWriteConfig(&mConfig);
|
|
}
|
|
|
|
void NCDSetting::backupData() {
|
|
memcpy(&mSaveConfig, &mConfig, sizeof(mSaveConfig));
|
|
}
|
|
|
|
void NCDSetting::resetData() {
|
|
memcpy(&mConfig, &mSaveConfig, sizeof(mConfig));
|
|
}
|
|
|
|
void NCDSetting::setUseProfileID() {
|
|
for (int i = 0; i < 3; i++) {
|
|
if (mID == i) {
|
|
mConfig.profiles[i].flags |= 0x80;
|
|
if (mConfig.profiles[i].flags & NCD_DHCP_FLAG) {
|
|
mConfig.selectedMedia = 2;
|
|
} else {
|
|
mConfig.selectedMedia = 1;
|
|
}
|
|
} else {
|
|
mConfig.profiles[i].flags &= 0x7F;
|
|
}
|
|
}
|
|
NCDWriteConfig(&mConfig);
|
|
}
|
|
|
|
void NCDSetting::setAOSSParams(const NCDAossConfig& src) {
|
|
mConfig.profiles[mID].netif.wireless.config.aoss = src;
|
|
}
|
|
|
|
void NCDSetting::setRakuParams(const NCDApConfig& src) {
|
|
mConfig.profiles[mID].netif.wireless.config.rakuraku = src;
|
|
}
|
|
|
|
u16 NCDSetting::getID() {
|
|
return mID & 0xFF;
|
|
}
|
|
|
|
NCDApConfig* NCDSetting::getSSID() {
|
|
return &mConfig.profiles[mID].netif.wireless.config.manual;
|
|
}
|
|
|
|
u16 NCDSetting::getUseProfileID() {
|
|
if (!(checkAllFlag() & 0xFF)) {
|
|
return 3;
|
|
} else {
|
|
for (int i = 0; i < 3; i++) {
|
|
if (mConfig.profiles[i].flags & 0x80 && mConfig.profiles[i].flags & 0x20) {
|
|
return i & 0xFF;
|
|
}
|
|
}
|
|
}
|
|
return 3;
|
|
}
|
|
|
|
int NCDSetting::getPrivacyMode() {
|
|
int ret = 0;
|
|
if (mConfig.profiles[mID].netif.wireless.configMethod == 0 || mConfig.profiles[mID].netif.wireless.configMethod == 3) {
|
|
u16 mode = mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode;
|
|
switch (mode) {
|
|
case 0: {
|
|
ret = 0;
|
|
break;
|
|
}
|
|
case 1: {
|
|
ret = 1;
|
|
break;
|
|
}
|
|
case 2: {
|
|
ret = 1;
|
|
break;
|
|
}
|
|
case 4: {
|
|
ret = 2;
|
|
break;
|
|
}
|
|
case 5: {
|
|
ret = 4;
|
|
break;
|
|
}
|
|
case 6: {
|
|
ret = 3;
|
|
break;
|
|
}
|
|
case 3: {
|
|
default:
|
|
ret = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
u16 NCDSetting::getNCDPrivacyMode() {
|
|
if (mConfig.profiles[mID].netif.wireless.configMethod == 0 || mConfig.profiles[mID].netif.wireless.configMethod == 3) {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
u8* NCDSetting::getPrivacy() {
|
|
u16 mode = mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode;
|
|
switch (mode) {
|
|
case 1: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.key[0];
|
|
}
|
|
case 2: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104.key[0];
|
|
}
|
|
case 4: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.tkip.key;
|
|
}
|
|
case 5:
|
|
case 6: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.aes.key;
|
|
}
|
|
default: {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
u16 NCDSetting::getPrivacyLen() {
|
|
u16 mode = mConfig.profiles[mID].netif.wireless.config.manual.privacy.mode;
|
|
switch (mode) {
|
|
case 1: {
|
|
if (mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep40.reserved[0] == 0) {
|
|
return 5;
|
|
}
|
|
return 10;
|
|
}
|
|
case 2: {
|
|
if (mConfig.profiles[mID].netif.wireless.config.manual.privacy.wep104.reserved[0] == 0) {
|
|
return 13;
|
|
}
|
|
return 26;
|
|
}
|
|
case 4: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.tkip.keyLen;
|
|
}
|
|
case 5:
|
|
case 6: {
|
|
return mConfig.profiles[mID].netif.wireless.config.manual.privacy.aes.keyLen;
|
|
}
|
|
default: {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
NCDIpProfile* NCDSetting::getIP() {
|
|
return &mConfig.profiles[mID].ip;
|
|
}
|
|
|
|
u32 NCDSetting::getMacNum() {
|
|
return mMacNum;
|
|
}
|
|
|
|
u8* NCDSetting::getMacAddr() {
|
|
return mMac;
|
|
}
|
|
|
|
void NCDSetting::makeMacAddr() {
|
|
u8 macAddress[7];
|
|
u64 macRemainder;
|
|
union {
|
|
char str[sizeof("XX-XX-XX-XX-XX-XX")];
|
|
u64 num;
|
|
u8 bytes[8];
|
|
} PACKED mac;
|
|
|
|
NCDErr err = NETGetWirelessMacAddress(macAddress);
|
|
switch (err) {
|
|
case NCD_RESULT_SUCCESS: {
|
|
sprintf(mac.str, "%02x-%02x-%02x-%02x-%02x-%02x", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4],
|
|
macAddress[5]);
|
|
OSReport("MAC: %s\n", &mac);
|
|
|
|
utility::CharacterCode::ANSIToUTF8((char*)mMac, (u8*)&mac);
|
|
|
|
memset(&mac, 0, sizeof(mac.str));
|
|
memcpy(mac.bytes + 2, &macAddress, 6);
|
|
|
|
mMacNum = mac.num % 100000000;
|
|
OSReport("%lld %d\n", mMacNum, mac.num, mMacNum);
|
|
return;
|
|
}
|
|
case NCD_RESULT_INPROGRESS:
|
|
case NCD_RESULT_4: {
|
|
OSHalt("try again!!", 1078);
|
|
return;
|
|
}
|
|
default: {
|
|
OSHalt("Unrecoverable Error!!", 1083);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
NCDProxyProfile* NCDSetting::getProxy() {
|
|
return &mConfig.profiles[mID].proxy;
|
|
}
|
|
|
|
s32 NCDSetting::getMTU() {
|
|
return mConfig.profiles[mID].adjust.maxTransferUnit;
|
|
}
|
|
|
|
NCDConfig* NCDSetting::getData() {
|
|
return &mConfig;
|
|
}
|
|
|
|
bool NCDSetting::getConnectEnableFlag() {
|
|
memset(&mConfig, 0, sizeof(mConfig));
|
|
NCDErr err = NCDReadConfig(&mConfig);
|
|
OSReport("NCDReadConfig: %d\n", err);
|
|
return getEnableFlag();
|
|
}
|
|
|
|
bool NCDSetting::getEnableFlag() {
|
|
for (int i = 0; i < 3; i++) {
|
|
if (mConfig.profiles[i].flags & 0x80 && mConfig.profiles[i].flags & 0x20) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
NCDErr NCDSetting::adjustNWC24Flag() {
|
|
adjustNWC24FlagEx_();
|
|
return NCDWriteConfig(&mConfig);
|
|
}
|
|
|
|
void NCDSetting::adjustNWC24FlagEx_() {
|
|
u32 wcFlags = SCGetWCFlags() & 1;
|
|
u32 contentRestrictions = SCGetNetContentRestrictions() & 2;
|
|
mConfig.nwc24Permission = 0;
|
|
if (wcFlags && SCGetEULA()) {
|
|
mConfig.nwc24Permission |= 4;
|
|
if (!(parental::Parental::checkFlags() & 0xFF) || ((parental::Parental::checkFlags() & 0xFF) && !contentRestrictions)) {
|
|
mConfig.nwc24Permission |= 3;
|
|
}
|
|
}
|
|
}
|
|
} // namespace ncd
|
|
} // namespace ipl
|