libctru/libctru/source/services/ac.c

53 lines
1016 B
C
Raw Normal View History

2014-04-22 04:58:05 +02:00
#include <stdlib.h>
#include <3ds/types.h>
#include <3ds/result.h>
#include <3ds/svc.h>
#include <3ds/srv.h>
#include <3ds/synchronization.h>
#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;
static int acRefCount;
2014-08-25 18:14:48 +02:00
Result acInit(void)
2014-08-25 18:14:48 +02: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
}
void acExit(void)
2014-08-25 18:14:48 +02: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
}
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
if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret;
2014-04-22 04:58:05 +02:00
*out = cmdbuf[2];
return (Result)cmdbuf[1];
}