Skip to content

Commit

Permalink
Fix typo in nsysnet and add more nn::ac functions. (#401)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel K. O. (dkosmari) <none@none>
  • Loading branch information
dkosmari and Daniel K. O. (dkosmari) authored Oct 1, 2024
1 parent ad730b9 commit 8b65fd6
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 88 deletions.
254 changes: 170 additions & 84 deletions include/nn/ac/ac_cpp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <wut.h>
#include <nn/result.h>
#include <nsysnet/netconfig.h>

/**
* \defgroup nn_ac_cpp Auto Connect C++ API
Expand All @@ -24,138 +25,223 @@ namespace ac
* An ID number representing a network configuration. These are the same IDs as
* shown in System Settings' Connection List.
*/
typedef uint32_t ConfigIdNum;
using ConfigIdNum = uint32_t;

/**
* C++ linkage for the autoconnect API, see \link nn::ac \endlink for use.
* Cafe provides mangled symbols for C++ APIs, so nn::ac is actually static
* inline calls to the mangled symbols under nn::ac::detail.
* The configuration for a given network profile (from 1 to 6).
* \sa NetConfCfg
*/
namespace detail
{
extern "C"
{
using Config = NetConfCfg;

using ErrorCode = uint32_t;

enum Status {
STATUS_FAILED = -1,
STATUS_OK = 0,
STATUS_PROCESSING = 1,
};


nn::Result
BeginLocalConnection(bool unknown)
asm("BeginLocalConnection__Q2_2nn2acFb");

nn::Result Initialize__Q2_2nn2acFv();
void Finalize__Q2_2nn2acFv();
nn::Result Connect__Q2_2nn2acFv();
nn::Result ConnectAsync__Q2_2nn2acFv();
nn::Result Close__Q2_2nn2acFv();
nn::Result GetCloseStatus__Q2_2nn2acFPQ3_2nn2ac6Status();
nn::Result GetStartupId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum(ConfigIdNum *id);
nn::Result Connect__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum(ConfigIdNum id);
nn::Result GetAssignedAddress__Q2_2nn2acFPUl(uint32_t *ip);
void
ClearConfig(Config *cfg)
asm("ClearConfig__Q2_2nn2acFP16netconf_profile_");

} // extern "C"
} // namespace detail
nn::Result
Close()
asm("Close__Q2_2nn2acFv");

nn::Result
CloseAll()
asm("CloseAll__Q2_2nn2acFv");

nn::Result
Connect(const Config *cfg)
asm("Connect__Q2_2nn2acFPC16netconf_profile_");

nn::Result
Connect(ConfigIdNum id)
asm("Connect__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum");

nn::Result
Connect()
asm("Connect__Q2_2nn2acFv");

nn::Result
ConnectAsync(const Config *cfg)
asm("ConnectAsync__Q2_2nn2acFPC16netconf_profile_");

/**
* Initialise the Auto Connect library. Call this function before any other nn::ac
* functions.
* Connects to a network, using the configuration represented by the given
* \link ConfigIdNum \endlink.
*
* \param id
* The \link ConfigIdNum \endlink representing the network to connect to.
*
* \return
* A \link nn::Result Result\endlink - see \link nn::Result::IsSuccess \endlink
* and \link nn::Result::IsFailure \endlink.
*
* \sa
* - \link Finalize \endlink
*/
static inline nn::Result
Initialize()
{
return detail::Initialize__Q2_2nn2acFv();
}
nn::Result
ConnectAsync(ConfigIdNum id)
asm("ConnectAsync__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum");

nn::Result
ConnectAsync()
asm("ConnectAsync__Q2_2nn2acFv");

nn::Result
ConnectWithRetry()
asm("ConnectWithRetry__Q2_2nn2acFv");

nn::Result
DeleteConfig(ConfigIdNum id)
asm("DeleteConfig__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum");

nn::Result
EndLocalConnection()
asm("EndLocalConnection__Q2_2nn2acFv");

/**
* Cleanup the Auto Connect library. Do not call any nn::ac functions (other
* Cleans up the Auto Connect library. Do not call any nn::ac functions (other
* than \link Initialize \endlink) after calling this function.
*
* \sa
* - \link Initialize \endlink
*/
static inline void
void
Finalize()
{
return detail::Finalize__Q2_2nn2acFv();
}

asm("Finalize__Q2_2nn2acFv");

/**
* Gets the default connection configuration id. This is the default as marked
* in System Settings.
* Gets the IP address assosciated with the currently active connection.
*
* \param id
* A pointer to an \link ConfigIdNum \endlink to write the config ID to. Must
* not be a \c nullptr.
* \param ip
* A pointer to write the IP address to, in
* <a href="https://en.wikipedia.org/wiki/IPv4#Address_representations"
* target="_blank">numerical</a> form.
*
* \return
* A \link nn::Result Result\endlink - see \link nn::Result::IsSuccess \endlink
* and \link nn::Result::IsFailure \endlink.
*/
static inline nn::Result
GetStartupId(ConfigIdNum *id)
{
return detail::GetStartupId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum(id);
}
nn::Result
GetAssignedAddress(uint32_t *ip)
asm("GetAssignedAddress__Q2_2nn2acFPUl");

static inline nn::Result
Connect()
{
return detail::Connect__Q2_2nn2acFv();
}
nn::Result
GetAssignedAlternativeDns(uint32_t *ip)
asm("GetAssignedAlternativeDns__Q2_2nn2acFPUl");

static inline nn::Result
ConnectAsync()
{
return detail::ConnectAsync__Q2_2nn2acFv();
}
nn::Result
GetAssignedGateway(uint32_t *ip)
asm("GetAssignedGateway__Q2_2nn2acFPUl");

static inline nn::Result
Close()
{
return detail::Close__Q2_2nn2acFv();
}
nn::Result
GetAssignedPreferedDns(uint32_t *ip)
asm("GetAssignedPreferedDns__Q2_2nn2acFPUl");

static inline nn::Result
GetCloseStatus()
{
return detail::GetCloseStatus__Q2_2nn2acFPQ3_2nn2ac6Status();
}
nn::Result
GetAssignedSubnet(uint32_t *ip)
asm("GetAssignedSubnet__Q2_2nn2acFPUl");

nn::Result
GetCloseStatus(Status *status)
asm("GetCloseStatus__Q2_2nn2acFPQ3_2nn2ac6Status");

nn::Result
GetCompatId(ConfigIdNum *id)
asm("GetCompatId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum");

nn::Result
GetConnectResult(nn::Result *result)
asm("GetConnectResult__Q2_2nn2acFPQ2_2nn6Result");

nn::Result
GetConnectStatus(Status *status)
asm("GetConnectStatus__Q2_2nn2acFPQ3_2nn2ac6Status");

nn::Result
GetLastErrorCode(ErrorCode *error)
asm("GetLastErrorCode__Q2_2nn2acFPUi");

nn::Result
GetRunningConfig(Config *cfg)
asm("GetRunningConfig__Q2_2nn2acFP16netconf_profile_");

/**
* Connects to a network, using the configuration represented by the given
* \link ConfigIdNum \endlink.
* Gets the default connection configuration id. This is the default as marked
* in System Settings.
*
* \param id
* The \link ConfigIdNum \endlink representing the network to connect to.
* A pointer to an \link ConfigIdNum \endlink to write the config ID to. Must
* not be a \c nullptr.
*
* \return
* A \link nn::Result Result\endlink - see \link nn::Result::IsSuccess \endlink
* and \link nn::Result::IsFailure \endlink.
*/
static inline nn::Result
Connect(ConfigIdNum id)
{
return detail::Connect__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum(id);
}
nn::Result
GetStartupId(ConfigIdNum *id)
asm("GetStartupId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum");

/**
* Gets the IP address assosciated with the currently active connection.
*
* \param ip
* A pointer to write the IP address to, in
* <a href="https://en.wikipedia.org/wiki/IPv4#Address_representations"
* target="_blank">numerical</a> form.
* Initializes the Auto Connect library. Call this function before any other nn::ac
* functions.
*
* \return
* A \link nn::Result Result\endlink - see \link nn::Result::IsSuccess \endlink
* and \link nn::Result::IsFailure \endlink.
*
* \sa
* - \link Finalize \endlink
*/
static inline nn::Result
GetAssignedAddress(uint32_t *ip)
{
return detail::GetAssignedAddress__Q2_2nn2acFPUl(ip);
}
nn::Result
Initialize()
asm("Initialize__Q2_2nn2acFv");

nn::Result
IsAnyKeepingConnect(bool keeping)
asm("IsAnyKeepingConnect__Q2_2nn2acFPb");

nn::Result
IsApplicationConnected(bool *connected)
asm("IsApplicationConnected__Q2_2nn2acFPb");

nn::Result
IsAutoConnectionFatallyFailed(nn::Result *failed)
asm("IsAutoConnectionFatallyFailed__Q2_2nn2acFQ2_2nn6Result");

nn::Result
IsConfigExisting(ConfigIdNum id, bool *existing)
asm("IsConfigExisting__Q2_2nn2acFQ3_2nn2ac11ConfigIdNumPb");

nn::Result
IsKeepingConnect(bool *keeping)
asm("IsKeepingConnect__Q2_2nn2acFPb");

nn::Result
IsReadyToConnect(bool *ready)
asm("IsReadyToConnect__Q2_2nn2acFPb");

nn::Result
ReadConfig(ConfigIdNum id, Config *cfg)
asm("ReadConfig__Q2_2nn2acFQ3_2nn2ac11ConfigIdNumP16netconf_profile_");

nn::Result
SetCompatId(ConfigIdNum id)
asm("SetCompatId__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum");

nn::Result
SetStartupId(ConfigIdNum id)
asm("SetStartupId__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum");

nn::Result
WriteConfig(ConfigIdNum id, const Config *cfg)
asm("WriteConfig__Q2_2nn2acFQ3_2nn2ac11ConfigIdNumPC16netconf_profile_");

} // namespace ac
} // namespace nn
Expand Down
5 changes: 5 additions & 0 deletions include/nn/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ class Result
};

public:
Result() :
mValue(0)
{
}

Result(Level level, Module module, unsigned description) :
mValue(((level & 0x7) << 29) | ((module & 0x1FF) << 20) | (description & 0xFFFFF))
{
Expand Down
8 changes: 4 additions & 4 deletions include/nsysnet/netconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ WUT_CHECK_OFFSET(NetConfWifiConfigDataPrivacy, 0x06, aes_key);
WUT_CHECK_SIZE(NetConfWifiConfigDataPrivacy, 0x48);

struct WUT_PACKED NetConfWifiConfigData {
uint8_t ssid[0x20];
char ssid[0x20];
uint16_t ssidlength;
WUT_PADDING_BYTES(2);
NetConfWifiConfigDataPrivacy privacy;
Expand All @@ -198,12 +198,12 @@ WUT_CHECK_SIZE(NetConfOpt, 0x2c1);

struct WUT_PACKED NetConfInterface {
uint16_t if_index;
uint16_t if_sate;
uint16_t if_state;
uint32_t if_mtu;
NetConfIPv4Info ipv4Info;
};
WUT_CHECK_OFFSET(NetConfInterface, 0x00, if_index);
WUT_CHECK_OFFSET(NetConfInterface, 0x02, if_sate);
WUT_CHECK_OFFSET(NetConfInterface, 0x02, if_state);
WUT_CHECK_OFFSET(NetConfInterface, 0x04, if_mtu);
WUT_CHECK_OFFSET(NetConfInterface, 0x08, ipv4Info);
WUT_CHECK_SIZE(NetConfInterface, 0x20);
Expand Down Expand Up @@ -457,4 +457,4 @@ netconf_write_compat_profile_id(uint32_t unk1);
}
#endif

/** @} */
/** @} */

0 comments on commit 8b65fd6

Please sign in to comment.