Skip to content

Commit

Permalink
- Enable networking to function with alternative interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Sep 15, 2023
1 parent 0ba680e commit a15183a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 9 deletions.
1 change: 0 additions & 1 deletion cube/swiss/include/bba.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <network.h>

extern int net_initialized;
extern int bba_exists;
extern struct in_addr bba_localip;
extern struct in_addr bba_netmask;
extern struct in_addr bba_gateway;
Expand Down
9 changes: 6 additions & 3 deletions cube/swiss/source/bba.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <ogcsys.h>
#include "exi.h"
#include "swiss.h"
#include "deviceHandler.h"

/* Network Globals */
int net_initialized = 0;
int bba_exists = 0;
struct in_addr bba_localip;
struct in_addr bba_netmask;
struct in_addr bba_gateway;
Expand All @@ -18,8 +18,7 @@ void init_network(void *args) {

int res = 0;

bba_exists = exi_bba_exists();
if(bba_exists && !net_initialized) {
if(!net_initialized) {
inet_aton(swissSettings.bbaLocalIp, &bba_localip);
bba_netmask.s_addr = INADDR_BROADCAST << (32 - swissSettings.bbaNetmask);
inet_aton(swissSettings.bbaGateway, &bba_gateway);
Expand All @@ -34,6 +33,10 @@ void init_network(void *args) {
else {
net_initialized = 0;
}

deviceHandler_setDeviceAvailable(&__device_smb, deviceHandler_SMB_test());
deviceHandler_setDeviceAvailable(&__device_ftp, deviceHandler_FTP_test());
deviceHandler_setDeviceAvailable(&__device_fsp, deviceHandler_FSP_test());
}
}

16 changes: 15 additions & 1 deletion cube/swiss/source/devices/fsp/deviceHandler-FSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,21 @@ s32 deviceHandler_FSP_makeDir(file_handle* dir) {
}

bool deviceHandler_FSP_test() {
return exi_bba_exists();
char ifname[4];
if(if_indextoname(1, ifname)) {
if(ifname[0] == 'E') {
__device_fsp.hwName = "ENC28J60";
__device_fsp.features = FEAT_READ|FEAT_WRITE;
__device_fsp.emulable = EMU_NONE;
if(ifname[1] == '0')
__device_fsp.location = LOC_MEMCARD_SLOT_A;
else if(ifname[1] == '1')
__device_fsp.location = LOC_MEMCARD_SLOT_B;
else if(ifname[1] == '2')
__device_fsp.location = LOC_SERIAL_PORT_2;
}
}
return net_initialized || exi_bba_exists();
}

u32 deviceHandler_FSP_emulated() {
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/source/devices/fsp/deviceHandler-FSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@

extern DEVICEHANDLER_INTERFACE __device_fsp;

extern bool deviceHandler_FSP_test();

#endif

14 changes: 13 additions & 1 deletion cube/swiss/source/devices/ftp/deviceHandler-FTP.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,19 @@ s32 deviceHandler_FTP_makeDir(file_handle* dir) {
}

bool deviceHandler_FTP_test() {
return exi_bba_exists();
char ifname[4];
if(if_indextoname(1, ifname)) {
if(ifname[0] == 'E') {
__device_ftp.hwName = "ENC28J60";
if(ifname[1] == '0')
__device_ftp.location = LOC_MEMCARD_SLOT_A;
else if(ifname[1] == '1')
__device_ftp.location = LOC_MEMCARD_SLOT_B;
else if(ifname[1] == '2')
__device_ftp.location = LOC_SERIAL_PORT_2;
}
}
return net_initialized || exi_bba_exists();
}

char* deviceHandler_FTP_status(file_handle* file) {
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/devices/ftp/deviceHandler-FTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

extern DEVICEHANDLER_INTERFACE __device_ftp;

extern bool deviceHandler_FTP_test();

#endif

14 changes: 13 additions & 1 deletion cube/swiss/source/devices/smb/deviceHandler-SMB.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,19 @@ s32 deviceHandler_SMB_makeDir(file_handle* dir) {
}

bool deviceHandler_SMB_test() {
return exi_bba_exists();
char ifname[4];
if(if_indextoname(1, ifname)) {
if(ifname[0] == 'E') {
__device_smb.hwName = "ENC28J60";
if(ifname[1] == '0')
__device_smb.location = LOC_MEMCARD_SLOT_A;
else if(ifname[1] == '1')
__device_smb.location = LOC_MEMCARD_SLOT_B;
else if(ifname[1] == '2')
__device_smb.location = LOC_SERIAL_PORT_2;
}
}
return net_initialized || exi_bba_exists();
}

char* deviceHandler_SMB_status(file_handle* file) {
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/devices/smb/deviceHandler-SMB.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

extern DEVICEHANDLER_INTERFACE __device_smb;

extern bool deviceHandler_SMB_test();

#endif

5 changes: 3 additions & 2 deletions cube/swiss/source/gui/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "config.h"
#include "settings.h"
#include "exi.h"
#include "bba.h"

#define page_x_ofs_key (30)
#define page_x_ofs_val (410)
Expand Down Expand Up @@ -278,10 +279,10 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
int scrollBarTabHeight = (int)((float)scrollBarHeight/(float)SET_PAGE_2_BACK);
DrawAddChild(page, DrawVertScrollBar(getVideoMode()->fbWidth-45, page_y_ofs, 25, scrollBarHeight, (float)((float)option/(float)(SET_PAGE_2_BACK-1)),scrollBarTabHeight));
DrawAddChild(page, DrawLabel(page_x_ofs_key, 65, "Network Settings (2/5):"));
bool netEnable = exi_bba_exists();
bool netEnable = net_initialized || exi_bba_exists();
// TODO settings to a new typedef that ties type etc all together, then draw a "page" of these rather than this at some point.
if(option < SET_FTP_USER) {
drawSettingEntryBoolean(page, &page_y_ofs, "Init network at startup:", swissSettings.initNetworkAtStart, option == SET_INIT_NET, netEnable);
drawSettingEntryBoolean(page, &page_y_ofs, "Init network at startup:", swissSettings.initNetworkAtStart, option == SET_INIT_NET, true);
drawSettingEntryString(page, &page_y_ofs, "IPv4 Address:", swissSettings.bbaLocalIp, option == SET_BBA_LOCALIP, netEnable);
drawSettingEntryNumeric(page, &page_y_ofs, "IPv4 Netmask:", swissSettings.bbaNetmask, option == SET_BBA_NETMASK, netEnable);
drawSettingEntryString(page, &page_y_ofs, "IPv4 Gateway:", swissSettings.bbaGateway, option == SET_BBA_GATEWAY, netEnable);
Expand Down

0 comments on commit a15183a

Please sign in to comment.