Moved code to dolphin for network
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
networkdolphin.c
|
||||
)
|
||||
@@ -0,0 +1,114 @@
|
||||
// /**
|
||||
// * Copyright (c) 2026 Dominic Masters
|
||||
// *
|
||||
// * This software is released under the MIT License.
|
||||
// * https://opensource.org/licenses/MIT
|
||||
// */
|
||||
|
||||
#include "network/network.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
errorret_t networkDolphinInit() {
|
||||
// s32 ret = net_init();
|
||||
// if(ret < 0) errorThrow("Failed to init network stack: %d", ret);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t networkDolphinUpdate() {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t networkDolphinDispose() {
|
||||
// #ifdef DUSK_WII
|
||||
// net_deinit();
|
||||
// #endif
|
||||
errorOk();
|
||||
}
|
||||
|
||||
bool_t networkDolphinIsConnected() {
|
||||
return NETWORK.state == NETWORK_STATE_CONNECTED;
|
||||
}
|
||||
|
||||
void networkDolphinRequestConnection(
|
||||
void (*onConnected)(void *user),
|
||||
void (*onFailed)(errorret_t error, void *user),
|
||||
void (*onDisconnect)(errorret_t error, void *user),
|
||||
void *user
|
||||
) {
|
||||
assertTrue(
|
||||
NETWORK.state == NETWORK_STATE_CONNECTING,
|
||||
"Network host should be in a connecting state."
|
||||
);
|
||||
|
||||
NETWORK.platform.onConnected = onConnected;
|
||||
NETWORK.platform.onFailed = onFailed;
|
||||
NETWORK.platform.onConnectedUser = user;
|
||||
|
||||
memoryZero(NETWORK.platform.ip, sizeof(NETWORK.platform.ip));
|
||||
memoryZero(NETWORK.platform.netmask, sizeof(NETWORK.platform.netmask));
|
||||
memoryZero(NETWORK.platform.gateway, sizeof(NETWORK.platform.gateway));
|
||||
|
||||
// Negotiate DHCP using the Wi-Fi settings saved in Wii System Menu.
|
||||
// This call blocks until the interface is configured or times out.
|
||||
s32 ret = if_config(
|
||||
NETWORK.platform.ip,
|
||||
NETWORK.platform.netmask,
|
||||
NETWORK.platform.gateway,
|
||||
true,
|
||||
20
|
||||
);
|
||||
|
||||
if(ret >= 0) {
|
||||
NETWORK.state = NETWORK_STATE_CONNECTED;
|
||||
assertNotNull(
|
||||
NETWORK.platform.onConnected,
|
||||
"Network platform onConnected callback should be set."
|
||||
);
|
||||
NETWORK.platform.onConnected(NETWORK.platform.onConnectedUser);
|
||||
} else {
|
||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||
assertNotNull(
|
||||
NETWORK.platform.onFailed,
|
||||
"Network platform onFailed callback should be set."
|
||||
);
|
||||
errorret_t error = errorThrowImpl(
|
||||
&NETWORK.errorState,
|
||||
ERROR_NOT_OK,
|
||||
__FILE__, __func__, __LINE__,
|
||||
"Failed to connect to network"
|
||||
);
|
||||
NETWORK.platform.onFailed(error, NETWORK.platform.onConnectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
void networkDolphinRequestDisconnection(
|
||||
void (*onComplete)(void *user),
|
||||
void *user
|
||||
) {
|
||||
assertTrue(
|
||||
NETWORK.state == NETWORK_STATE_DISCONNECTING,
|
||||
"Network host should be in a disconnecting state."
|
||||
);
|
||||
|
||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||
onComplete(user);
|
||||
}
|
||||
|
||||
networkinfo_t networkDolphinGetInfo() {
|
||||
networkinfo_t info;
|
||||
memoryZero(&info, sizeof(networkinfo_t));
|
||||
|
||||
info.type = NETWORK_TYPE_IPV4;
|
||||
int ret = sscanf(
|
||||
NETWORK.platform.ip,
|
||||
"%hhu.%hhu.%hhu.%hhu",
|
||||
&info.ipv4.ip[0],
|
||||
&info.ipv4.ip[1],
|
||||
&info.ipv4.ip[2],
|
||||
&info.ipv4.ip[3]
|
||||
);
|
||||
assertTrue(ret == 4, "Failed to parse IP address");
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "network/networkinfo.h"
|
||||
#include <network.h>
|
||||
|
||||
#define NETWORK_DOLPHIN_IP_MAX 16
|
||||
|
||||
typedef struct {
|
||||
char_t ip[NETWORK_DOLPHIN_IP_MAX];
|
||||
char_t netmask[NETWORK_DOLPHIN_IP_MAX];
|
||||
char_t gateway[NETWORK_DOLPHIN_IP_MAX];
|
||||
|
||||
void *onConnectedUser;
|
||||
void (*onConnected)(void *user);
|
||||
void (*onFailed)(errorret_t error, void *user);
|
||||
} networkdolphin_t;
|
||||
|
||||
/**
|
||||
* Initializes the Wii network stack via IOS. Does not connect; use
|
||||
* networkDolphinRequestConnection for that.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkDolphinInit();
|
||||
|
||||
/**
|
||||
* Called each frame. No-op on Wii since connection is synchronous.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkDolphinUpdate();
|
||||
|
||||
/**
|
||||
* Disposes the Wii network stack.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkDolphinDispose();
|
||||
|
||||
/**
|
||||
* Returns true if the Wii is connected to a network.
|
||||
*
|
||||
* @return True if connected.
|
||||
*/
|
||||
bool_t networkDolphinIsConnected();
|
||||
|
||||
/**
|
||||
* Requests the Wii to connect to the network using the Wi-Fi settings saved
|
||||
* in the Wii System Menu. Blocks until connected or failed.
|
||||
*
|
||||
* @param onConnected Callback on successful connection.
|
||||
* @param onFailed Callback if connection fails.
|
||||
* @param onDisconnect Callback when connection is later lost.
|
||||
* @param user User data passed to all callbacks.
|
||||
*/
|
||||
void networkDolphinRequestConnection(
|
||||
void (*onConnected)(void *user),
|
||||
void (*onFailed)(errorret_t error, void *user),
|
||||
void (*onDisconnect)(errorret_t error, void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Requests the Wii to disconnect from the network.
|
||||
*
|
||||
* @param onComplete Callback when disconnection is complete.
|
||||
* @param user User data passed to the callback.
|
||||
*/
|
||||
void networkDolphinRequestDisconnection(
|
||||
void (*onComplete)(void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the current network IP information.
|
||||
*
|
||||
* @return Network info for the active connection.
|
||||
*/
|
||||
networkinfo_t networkDolphinGetInfo();
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "networkdolphin.h"
|
||||
|
||||
#define networkPlatformInit networkDolphinInit
|
||||
#define networkPlatformUpdate networkDolphinUpdate
|
||||
#define networkPlatformDispose networkDolphinDispose
|
||||
#define networkPlatformIsConnected networkDolphinIsConnected
|
||||
#define networkPlatformRequestConnection networkDolphinRequestConnection
|
||||
#define networkPlatformRequestDisconnection networkDolphinRequestDisconnection
|
||||
#define networkPlatformGetInfo networkDolphinGetInfo
|
||||
|
||||
typedef networkdolphin_t networkplatform_t;
|
||||
Reference in New Issue
Block a user