Added WifiWebAuthApplet launching (#233)

* Added WifiWebAuthApplet launching
This commit is contained in:
Samuel P 2019-01-19 02:00:34 +01:00 committed by yellows8
parent 40d5fb8587
commit 8360e561c5
3 changed files with 76 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.h"
#include "switch/runtime/env.h"
#include "switch/runtime/nxlink.h"

View File

@ -0,0 +1,28 @@
/**
* @file web.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 unk_x0[0x4];
char url[0xFC];
} WebWifiPageArgUrl;
typedef struct {
WebWifiPageArgUrl url1;
WebWifiPageArgUrl url2;
u8 unk_x200[0x300];
u8 unk_x500[0x18];
} WebWifiPageArg;
typedef struct {
WebWifiPageArg arg;
} WebWifiConfig;
void webWifiCreate(WebWifiConfig* config, const char* url);
Result webWifiShow(WebWifiConfig* config);

47
nx/source/applets/web.c Normal file
View File

@ -0,0 +1,47 @@
#include <string.h>
#include <malloc.h>
#include "types.h"
#include "result.h"
#include "services/applet.h"
#include "applets/libapplet.h"
#include "applets/web.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;
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)) {
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;
}