Added WifiWebAuthApplet launching

This commit is contained in:
p-sam 2019-01-18 21:40:03 +00:00
parent 40d5fb8587
commit 2b129f9935
3 changed files with 86 additions and 0 deletions

View File

@ -101,6 +101,7 @@ extern "C" {
#include "switch/applets/libapplet.h"
#include "switch/applets/swkbd.h"
#include "switch/applets/web_wifi.h"
#include "switch/runtime/env.h"
#include "switch/runtime/nxlink.h"

View File

@ -0,0 +1,28 @@
/**
* @file web_wifi.h
* @brief Wrapper for using the WifiWebAuthApplet LibraryApplet.
* @author p-sam
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/applet.h"
typedef struct {
u8 unk1[0x4];
char url[0xFC];
} WebWifiPageArgUrl;
typedef struct {
WebWifiPageArgUrl url1;
WebWifiPageArgUrl url2;
u8 gap1[0x300];
u8 unk2[0x18];
} WebWifiPageArg;
typedef struct {
WebWifiPageArg arg;
} WebWifiConfig;
void webWifiCreate(WebWifiConfig* config, const char* url);
Result webWifiShow(WebWifiConfig* config);

View File

@ -0,0 +1,57 @@
#include <string.h>
#include <malloc.h>
#include "types.h"
#include "result.h"
#include "services/applet.h"
#include "applets/libapplet.h"
#include "applets/web_wifi.h"
static void _webWifiUrlCreate(WebWifiPageArgUrl* argUrl, const char* url) {
strncpy(argUrl->url, url, sizeof(argUrl->url)-1);
}
void webWifiCreate(WebWifiConfig* config, const char* url) {
memset(config, 0, sizeof(WebWifiConfig));
_webWifiUrlCreate(&config->arg.url1, url);
_webWifiUrlCreate(&config->arg.url2, url);
}
Result webWifiShow(WebWifiConfig* config) {
Result rc = 0;
AppletHolder holder;
AppletStorage storage;
memset(&storage, 0, sizeof(AppletStorage));
rc = appletCreateLibraryApplet(&holder, AppletId_wifiWebAuth, LibAppletMode_AllForeground);
if (R_FAILED(rc)) return rc;
LibAppletArgs commonargs;
libappletArgsCreate(&commonargs, 0);
rc = libappletArgsPush(&commonargs, &holder);
if (R_SUCCEEDED(rc)) rc = libappletPushInData(&holder, &config->arg, sizeof(config->arg));
if (R_SUCCEEDED(rc)) rc = appletHolderStart(&holder);
if (R_SUCCEEDED(rc)) {
while(appletHolderWaitInteractiveOut(&holder)) {
//TODO: Handle Interactive data here. (nothing to handle at this moment)
}
}
if (R_SUCCEEDED(rc)) {
appletHolderJoin(&holder);
LibAppletExitReason reason = appletHolderGetExitReason(&holder);
if (reason == LibAppletExitReason_Canceled || reason == LibAppletExitReason_Abnormal || reason == LibAppletExitReason_Unexpected) {
rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
}
}
appletHolderClose(&holder);
return rc;
}