int ethSMBConnect(void) { int ret; smbLogOn_in_t logon; smbEcho_in_t echo; smbOpenShare_in_t openshare; // open tcp connection with the server / logon to SMB server sprintf(logon.serverIP, "%d.%d.%d.%d", pc_ip[0], pc_ip[1], pc_ip[2], pc_ip[3]); logon.serverPort = gPCPort; if (strlen(gPCPassword) > 0) { smbGetPasswordHashes_in_t passwd; smbGetPasswordHashes_out_t passwdhashes; // we'll try to generate hashed password first strncpy(logon.User, gPCUserName, 32); strncpy(passwd.password, gPCPassword, 32); ret = fileXioDevctl(ethPrefix, SMB_DEVCTL_GETPASSWORDHASHES, (void *)&passwd, sizeof(passwd), (void *)&passwdhashes, sizeof(passwdhashes)); if (ret == 0) { // hash generated okay, can use memcpy((void *)logon.Password, (void *)&passwdhashes, sizeof(passwdhashes)); logon.PasswordType = HASHED_PASSWORD; memcpy((void *)openshare.Password, (void *)&passwdhashes, sizeof(passwdhashes)); openshare.PasswordType = HASHED_PASSWORD; } else { // failed hashing, failback to plaintext strncpy(logon.Password, gPCPassword, 32); logon.PasswordType = PLAINTEXT_PASSWORD; strncpy(openshare.Password, gPCPassword, 32); openshare.PasswordType = PLAINTEXT_PASSWORD; } } else { strncpy(logon.User, gPCUserName, 32); logon.PasswordType = NO_PASSWORD; openshare.PasswordType = NO_PASSWORD; } ret = fileXioDevctl(ethPrefix, SMB_DEVCTL_LOGON, (void *)&logon, sizeof(logon), NULL, 0); if (ret < 0) return -2; // SMB server alive test strcpy(echo.echo, "ALIVE ECHO TEST"); echo.len = strlen("ALIVE ECHO TEST"); ret = fileXioDevctl(ethPrefix, SMB_DEVCTL_ECHO, (void *)&echo, sizeof(echo), NULL, 0); if (ret < 0) return -3; // connect to the share strcpy(openshare.ShareName, gPCShareName); ret = fileXioDevctl(ethPrefix, SMB_DEVCTL_OPENSHARE, (void *)&openshare, sizeof(openshare), NULL, 0); if (ret < 0) return -4; return 0; }
static void hddUpdateInfo() { iox_dirent_t infoDirEnt; int rv; int hddFd, hddUsed = 0; hddSize = fileXioDevctl("hdd0:", HDDCTL_TOTAL_SECTORS, NULL, 0, NULL, 0) * 512 / 1024 / 1024; /* This seems to give in-accurate results fileXioDevctl("hdd0:", HDDCTL_FREE_SECTORS, NULL, 0, &rv, 4); hddFree = rv * 512 / 1024 / 1024; */ hddFd = fileXioDopen("hdd0:"); if(hddFd < 0) // For when a HDD is not connected! return; rv = fileXioDread(hddFd, &infoDirEnt); while(rv > 0) { if(infoDirEnt.stat.mode != FS_TYPE_EMPTY) hddUsed += infoDirEnt.stat.size * 512 / 1024 / 1024; rv = fileXioDread(hddFd, &infoDirEnt); } fileXioDclose(hddFd); hddFree = hddSize - hddUsed; hddMaxPartitionSize = fileXioDevctl("hdd0:", HDDCTL_MAX_SECTORS, NULL, 0, NULL, 0) * 512 / 1024 / 1024; hddStatusCurrent = 1; }
static int ethSMBDisconnect(void) { int ret; // closing share ret = fileXioDevctl(ethBase, SMB_DEVCTL_CLOSESHARE, NULL, 0, NULL, 0); if (ret < 0) return -1; // logoff/close tcp connection from SMB server: ret = fileXioDevctl(ethBase, SMB_DEVCTL_LOGOFF, NULL, 0, NULL, 0); if (ret < 0) return -2; return 0; }
//--------------------------------------------------------------------------- //Function to log on to an index selected server //------------------------------ int smbLogon_Server(int Index) { int ret; smbLogOn_in_t logon; load_smbman(); if (smbServerList[Index].Server_Logon_f == 1) { printf("smbLogon_Server: Request for duplicate logon noted.\n"); return -1; } if (smbServerList[Index].Username[0] == 0) //if Username invalid strcpy(smbServerList[Index].Username, "GUEST"); if ((smbServerList[Index].PasswordType > 0) //if hashing wanted && (smbServerList[Index].PassHash_f == 0)) { ret = fileXioDevctl("smb:", SMB_DEVCTL_GETPASSWORDHASHES, (void *)&smbServerList[Index].Password, sizeof(smbServerList[Index].Password), (void *)&smbServerList[Index].PassHash, sizeof(smbServerList[Index].PassHash)); if (ret) { printf("smbLogon_Server: PassHash error %d\n", ret); return -1; } smbServerList[Index].PassHash_f = 1; //PassHash is now valid for future use } strcpy(logon.serverIP, smbServerList[Index].Server_IP); logon.serverPort = smbServerList[Index].Server_Port; strcpy(logon.User, smbServerList[Index].Username); if (smbServerList[Index].PasswordType > 0) //if hashing wanted memcpy((void *)logon.Password, (void *)smbServerList[Index].PassHash, sizeof(smbServerList[Index].PassHash)); else strcpy(logon.Password, smbServerList[Index].Password); logon.PasswordType = smbServerList[Index].PasswordType; ret = fileXioDevctl("smb:", SMB_DEVCTL_LOGON, (void *)&logon, sizeof(logon), NULL, 0); if (ret) { printf("smbLogon_Server: Logon Error %d\n", ret); return -1; } smbServerList[Index].Server_Logon_f = 1; printf("smbLogon_Server: Logon succeeded!\n"); return 0; //Here basic Logon has been achieved }
int hddCheckFormatted() { int rv; if(!hddStatusCurrent) hddUpdateInfo(); rv = fileXioDevctl("hdd0:", HDDCTL_STATUS, NULL, 0, NULL, 0); if((rv >= 1) || (rv < 0)) return -1; else return 0; }
static void poweroffCallback(void *arg) { #if 0 /* Close all files and unmount all partitions. */ close(fd); /* If you use PFS, close all files and unmount all partitions. */ fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0) /* Shut down DEV9, if you used it. */ while(fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0) < 0){}; #endif printf("Shutdown!"); poweroffShutdown(); }
static int ethUpdateGameList(void) { int result; if (gNetworkStartup != 0) return 0; if (gPCShareName[0]) { if((result = sbReadList(ðGames, ethPrefix, ðULSizePrev, ðGameCount)) < 0){ gNetworkStartup = ERROR_ETH_SMB_LISTGAMES; ethDisplayErrorStatus(); } } else { int i, count; ShareEntry_t sharelist[128]; smbGetShareList_in_t getsharelist; getsharelist.EE_addr = (void *)&sharelist[0]; getsharelist.maxent = 128; count = fileXioDevctl(ethBase, SMB_DEVCTL_GETSHARELIST, (void *)&getsharelist, sizeof(getsharelist), NULL, 0); if (count > 0) { free(ethGames); ethGames = (base_game_info_t*)malloc(sizeof(base_game_info_t) * count); for (i = 0; i < count; i++) { LOG("ETHSUPPORT Share found: %s\n", sharelist[i].ShareName); base_game_info_t *g = ðGames[i]; memcpy(g->name, sharelist[i].ShareName, 32); g->name[31] = '\0'; sprintf(g->startup, "SHARE"); g->extension[0] = '\0'; g->parts = 0x00; g->media = 0x00; g->format = GAME_FORMAT_USBLD; g->sizeMB = 0; } ethGameCount = count; }else if(count < 0){ gNetworkStartup = ERROR_ETH_SMB_LISTSHARES; ethDisplayErrorStatus(); } } return ethGameCount; }
static void ethSMBConnect(void) { unsigned char share_ip_address[4]; smbLogOn_in_t logon; smbEcho_in_t echo; smbOpenShare_in_t openshare; int result; if (gETHPrefix[0] != '\0') sprintf(ethPrefix, "%s%s\\", ethBase, gETHPrefix); else sprintf(ethPrefix, ethBase); // open tcp connection with the server / logon to SMB server if(gPCShareAddressIsNetBIOS) { if(nbnsFindName(gPCShareNBAddress, share_ip_address) != 0) { gNetworkStartup = ERROR_ETH_SMB_CONN; return; } sprintf(logon.serverIP, "%u.%u.%u.%u", share_ip_address[0], share_ip_address[1], share_ip_address[2], share_ip_address[3]); } else { sprintf(logon.serverIP, "%u.%u.%u.%u", pc_ip[0], pc_ip[1], pc_ip[2], pc_ip[3]); } logon.serverPort = gPCPort; if (strlen(gPCPassword) > 0) { smbGetPasswordHashes_in_t passwd; smbGetPasswordHashes_out_t passwdhashes; // we'll try to generate hashed password first strncpy(logon.User, gPCUserName, sizeof(logon.User)); strncpy(passwd.password, gPCPassword, sizeof(passwd.password)); if (fileXioDevctl(ethBase, SMB_DEVCTL_GETPASSWORDHASHES, (void *)&passwd, sizeof(passwd), (void *)&passwdhashes, sizeof(passwdhashes)) == 0) { // hash generated okay, can use memcpy((void *)logon.Password, (void *)&passwdhashes, sizeof(passwdhashes)); logon.PasswordType = HASHED_PASSWORD; memcpy((void *)openshare.Password, (void *)&passwdhashes, sizeof(passwdhashes)); openshare.PasswordType = HASHED_PASSWORD; } else { // failed hashing, failback to plaintext strncpy(logon.Password, gPCPassword, sizeof(logon.Password)); logon.PasswordType = PLAINTEXT_PASSWORD; strncpy(openshare.Password, gPCPassword, sizeof(openshare.Password)); openshare.PasswordType = PLAINTEXT_PASSWORD; } } else { strncpy(logon.User, gPCUserName, sizeof(logon.User)); logon.PasswordType = NO_PASSWORD; openshare.PasswordType = NO_PASSWORD; } if ((result=fileXioDevctl(ethBase, SMB_DEVCTL_LOGON, (void *)&logon, sizeof(logon), NULL, 0)) >= 0) { // SMB server alive test strcpy(echo.echo, "ALIVE ECHO TEST"); echo.len = strlen("ALIVE ECHO TEST"); if (gPCShareAddressIsNetBIOS) { // Since the SMB server can be connected to, update the IP address. pc_ip[0] = share_ip_address[0]; pc_ip[1] = share_ip_address[1]; pc_ip[2] = share_ip_address[2]; pc_ip[3] = share_ip_address[3]; } if (fileXioDevctl(ethBase, SMB_DEVCTL_ECHO, (void *)&echo, sizeof(echo), NULL, 0) >= 0) { gNetworkStartup = ERROR_ETH_SMB_OPENSHARE; if (gPCShareName[0]) { // connect to the share strcpy(openshare.ShareName, gPCShareName); if (fileXioDevctl(ethBase, SMB_DEVCTL_OPENSHARE, (void *)&openshare, sizeof(openshare), NULL, 0) >= 0) { // everything is ok gNetworkStartup = 0; } } } else{ gNetworkStartup = ERROR_ETH_SMB_ECHO; } } else{ gNetworkStartup = (result==-SMB_DEVCTL_LOGON_ERR_CONN)? ERROR_ETH_SMB_CONN : ERROR_ETH_SMB_LOGON; } }
int hddGetFilesystemList(t_hddFilesystem hddFs[], int maxEntries) { iox_dirent_t dirEnt; int count = 0; u32 size = 0; int hddFd; int rv; if(!hddStatusCurrent) hddUpdateInfo(); hddFd = fileXioDopen("hdd0:"); if(hddFd < 0) return hddFd; rv = fileXioDread(hddFd, &dirEnt); while((rv > 0) && (count < maxEntries)) { int i; int partitionFd; u32 zoneFree, zoneSize; // We only want to know about main partitions (non-empty ones at that :P) if((dirEnt.stat.attr & ATTR_SUB_PARTITION) || (dirEnt.stat.mode == FS_TYPE_EMPTY)) { rv = fileXioDread(hddFd, &dirEnt); continue; } memset(&hddFs[count], 0, sizeof(t_hddFilesystem)); sprintf(hddFs[count].filename, "hdd0:%s", dirEnt.name); // Work out filesystem type if((dirEnt.name[0] == '_') && (dirEnt.name[1] == '_')) { hddFs[count].fileSystemGroup = FS_GROUP_SYSTEM; strcpy(hddFs[count].name, &dirEnt.name[2]); } else if(dirEnt.name[0] == FS_COMMON_PREFIX) { hddFs[count].fileSystemGroup = FS_GROUP_COMMON; strcpy(hddFs[count].name, &dirEnt.name[1]); } else { hddFs[count].fileSystemGroup = FS_GROUP_APPLICATION; strcpy(hddFs[count].name, dirEnt.name); } #ifdef _OMIT_SYSTEM_PARTITION if((hddFs[count].fileSystemGroup == FS_GROUP_SYSTEM) && strcmp(hddFs[count].name, "boot")) { rv = fileXioDread(hddFd, &dirEnt); continue; } #endif #ifdef DEBUG printf("> Filename: %s\n> Name: %s\n> Type: %d\n", hddFs[count].filename, hddFs[count].name, hddFs[count].fileSystemGroup); #endif // Calculate filesystem size partitionFd = fileXioOpen(hddFs[count].filename, O_RDONLY, 0); // If we failed to open the partition, then a password is probably set // (usually this means we have tried to access a game partition). We // dont want to return un-accessible game partitions in the filesystem list.. if(partitionFd < 0) { rv = fileXioDread(hddFd, &dirEnt); continue; } for(i = 0, size = 0; i < dirEnt.stat.private_0 + 1; i++) { rv = fileXioIoctl2(partitionFd, HDDIO_GETSIZE, &i, 4, NULL, 0); size += rv * 512 / 1024 / 1024; } fileXioClose(partitionFd); hddFs[count].size = size; // Get filesystem free space & format status hddFs[count].freeSpace = 0; hddFs[count].formatted = 0; if(dirEnt.stat.mode == FS_TYPE_PFS) { rv = fileXioMount("pfs0:", hddFs[count].filename, FIO_MT_RDONLY); if(rv == 0) { zoneFree = fileXioDevctl("pfs0:", PFSCTL_GET_ZONE_FREE, NULL, 0, NULL, 0); zoneSize = fileXioDevctl("pfs0:", PFSCTL_GET_ZONE_SIZE, NULL, 0, NULL, 0); hddFs[count].freeSpace = zoneFree * zoneSize / 1024 / 1024; hddFs[count].formatted = 1; fileXioUmount("pfs0:"); } } #ifdef DEBUG printf("> Formatted: %d\n> Size: %d\n> Free: %d\n", hddFs[count].formatted, (int)hddFs[count].size, (int)hddFs[count].freeSpace); #endif count++; rv = fileXioDread(hddFd, &dirEnt); } rv = fileXioDclose(hddFd); return count; }