2014-04-22 04:58:05 +02:00
|
|
|
#include <stdlib.h>
|
2014-12-13 17:36:54 +01:00
|
|
|
#include <3ds/types.h>
|
2015-11-07 01:25:31 +01:00
|
|
|
#include <3ds/result.h>
|
2014-12-13 17:36:54 +01:00
|
|
|
#include <3ds/svc.h>
|
|
|
|
#include <3ds/srv.h>
|
2015-11-07 01:25:31 +01:00
|
|
|
#include <3ds/synchronization.h>
|
2014-12-13 17:36:54 +01:00
|
|
|
#include <3ds/services/ac.h>
|
2015-09-09 16:00:46 +02:00
|
|
|
#include <3ds/ipc.h>
|
2014-04-22 04:58:05 +02:00
|
|
|
|
2014-08-25 18:14:48 +02:00
|
|
|
static Handle acHandle;
|
2015-11-07 01:25:31 +01:00
|
|
|
static int acRefCount;
|
2014-08-25 18:14:48 +02:00
|
|
|
|
2015-09-06 18:13:31 +02:00
|
|
|
Result acInit(void)
|
2014-08-25 18:14:48 +02:00
|
|
|
{
|
2015-11-07 01:25:31 +01:00
|
|
|
Result ret;
|
|
|
|
|
|
|
|
if (AtomicPostIncrement(&acRefCount)) return 0;
|
|
|
|
|
|
|
|
ret = srvGetServiceHandle(&acHandle, "ac:u");
|
|
|
|
if(R_FAILED(ret)) ret = srvGetServiceHandle(&acHandle, "ac:i");
|
|
|
|
if(R_FAILED(ret)) AtomicDecrement(&acRefCount);
|
|
|
|
|
|
|
|
return ret;
|
2014-08-25 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2015-11-07 01:25:31 +01:00
|
|
|
void acExit(void)
|
2014-08-25 18:14:48 +02:00
|
|
|
{
|
2015-11-07 01:25:31 +01:00
|
|
|
if (AtomicDecrement(&acRefCount)) return;
|
|
|
|
svcCloseHandle(acHandle);
|
2014-08-25 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2015-11-11 05:33:37 +01:00
|
|
|
Result acWaitInternetConnection(void)
|
2014-04-22 04:58:05 +02:00
|
|
|
{
|
2015-11-11 05:33:37 +01:00
|
|
|
Result ret = 0;
|
|
|
|
u32 status = 0;
|
|
|
|
while(R_SUCCEEDED(ret = ACU_GetWifiStatus(&status)) && status == 0);
|
|
|
|
return ret;
|
2014-04-22 04:58:05 +02:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:48:23 +01:00
|
|
|
Result ACU_GetWifiStatus(u32 *out)
|
2014-04-22 04:58:05 +02:00
|
|
|
{
|
|
|
|
Result ret=0;
|
|
|
|
u32 *cmdbuf = getThreadCommandBuffer();
|
|
|
|
|
2015-09-09 16:00:46 +02:00
|
|
|
cmdbuf[0] = IPC_MakeHeader(0xD,0,0); // 0x000D0000
|
2014-04-22 04:58:05 +02:00
|
|
|
|
2015-11-07 01:25:31 +01:00
|
|
|
if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret;
|
2014-04-22 04:58:05 +02:00
|
|
|
|
|
|
|
*out = cmdbuf[2];
|
|
|
|
|
|
|
|
return (Result)cmdbuf[1];
|
|
|
|
}
|