Beispiel #1
0
Result hidInit(void)
{
	u8 val=0;
	Result ret=0;

	if (AtomicPostIncrement(&hidRefCount)) return 0;

	// Request service.
	ret = srvGetServiceHandle(&hidHandle, "hid:USER");
	if (R_FAILED(ret)) ret = srvGetServiceHandle(&hidHandle, "hid:SPVR");
	if (R_FAILED(ret)) goto cleanup0;

	// Get sharedmem handle.
	if(R_FAILED(ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;

	// Map HID shared memory.
	hidSharedMem=(vu32*)mappableAlloc(0x2b0);
	if(!hidSharedMem)
	{
		ret = -1;
		goto cleanup1;
	}

	if(R_FAILED(ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;

	APT_CheckNew3DS(&val);

	if(val)
	{
		ret = irrstInit();
	}

	// Reset internal state.
	kOld = kHeld = kDown = kUp = 0;
	return ret;

cleanup2:
	svcCloseHandle(hidMemHandle);
	if(hidSharedMem != NULL)
	{
		mappableFree((void*) hidSharedMem);
		hidSharedMem = NULL;
	}
cleanup1:
	svcCloseHandle(hidHandle);
cleanup0:
	AtomicDecrement(&hidRefCount);
	return ret;
}
Beispiel #2
0
Result camInit(void) {
	Result ret = 0;

	if (AtomicPostIncrement(&camRefCount)) return 0;

	ret = srvGetServiceHandle(&camHandle, "cam:u");
	if (R_SUCCEEDED(ret))
	{
		ret = CAMU_DriverInitialize();
		if (R_FAILED(ret)) svcCloseHandle(camHandle);
	}
	if (R_FAILED(ret)) AtomicDecrement(&camRefCount);

	return ret;
}
Beispiel #3
0
Result y2rInit(void)
{
	Result ret = 0;

	if (AtomicPostIncrement(&y2rRefCount)) return 0;

	ret = srvGetServiceHandle(&y2rHandle, "y2r:u");
	if (R_SUCCEEDED(ret))
	{
		ret = Y2RU_DriverInitialize();
		if (R_FAILED(ret)) svcCloseHandle(y2rHandle);
	}
	if (R_FAILED(ret)) AtomicDecrement(&y2rRefCount);
	return ret;
}
Beispiel #4
0
Result nfcInit(void)
{
	Result ret=0;

	if (AtomicPostIncrement(&nfcRefCount)) return 0;

	ret = srvGetServiceHandle(&nfcHandle, "nfc:u");
	if (R_SUCCEEDED(ret))
	{
		ret = NFC_Initialize(0x02);
		if (R_FAILED(ret)) svcCloseHandle(nfcHandle);
	}
	if (R_FAILED(ret)) AtomicDecrement(&nfcRefCount);

	return ret;
}
Beispiel #5
0
Result udsInit(size_t sharedmem_size, const char *username)
{
	Result ret=0;
	u32 ndm_state = 0;

	if (AtomicPostIncrement(&__uds_refcount)) return 0;

	ret = ndmuInit();
	if(R_SUCCEEDED(ret))
	{
		ndm_state = 1;
		ret = ndmuEnterExclusiveState(EXCLUSIVE_STATE_LOCAL_COMMUNICATIONS);
		if(R_SUCCEEDED(ret))
		{
			ndm_state = 2;
		}
	}

	if(R_SUCCEEDED(ret))
	{
		ret = srvGetServiceHandle(&__uds_servhandle, "nwm::UDS");
		if(R_SUCCEEDED(ret))
		{
			ret = uds_Initialize(sharedmem_size, username);
			if (R_FAILED(ret))
			{
				svcCloseHandle(__uds_servhandle);
				__uds_servhandle = 0;
			}
		}
	}

	if (R_FAILED(ret))
	{
		if(ndm_state)
		{
			if(ndm_state==2)ndmuLeaveExclusiveState();
			ndmuExit();
		}

		AtomicDecrement(&__uds_refcount);
	}

	bind_allocbitmask = 0;

	return ret;
}
Beispiel #6
0
Result irrstInit(void)
{
	if (AtomicPostIncrement(&irrstRefCount)) return 0;

	Result ret=0;

	// Request service.
	if(R_FAILED(ret=srvGetServiceHandle(&irrstHandle, "ir:rst"))) goto cleanup0;

	// Get sharedmem handle.
	if(R_FAILED(ret=IRRST_GetHandles(&irrstMemHandle, &irrstEvent))) goto cleanup1;

	// Initialize ir:rst
	if(envGetHandle("ir:rst") == 0) ret = IRRST_Initialize(10, 0);

	// Map ir:rst shared memory.
	irrstSharedMem=(vu32*)mappableAlloc(0x98);
	if(!irrstSharedMem)
	{
		ret = -1;
		goto cleanup1;
	}

	if(R_FAILED(ret = svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000))) goto cleanup2;

	// Reset internal state.
	kHeld = 0;
	return 0;

cleanup2:
	svcCloseHandle(irrstMemHandle);
	if(irrstSharedMem != NULL)
	{
		mappableFree((void*) irrstSharedMem);
		irrstSharedMem = NULL;
	}
cleanup1:
	svcCloseHandle(irrstHandle);
cleanup0:
	AtomicDecrement(&irrstRefCount);
	return ret;
}
Beispiel #7
0
Result fsldrInit(void)
{
  Result ret = 0;

  if (AtomicPostIncrement(&fsldrRefCount)) return 0;

  ret = srvSysGetServiceHandle(&fsldrHandle, "fs:LDR");
  if (R_SUCCEEDED(ret))
  {
    fsldrPatchPermissions();
    ret = FSLDR_InitializeWithSdkVersion(fsldrHandle, SDK_VERSION);
    ret = FSLDR_SetPriority(0);
    if (R_FAILED(ret)) svcBreak(USERBREAK_ASSERT);
  }
  else
  {
    AtomicDecrement(&fsldrRefCount);
  }

  return ret;
}
Beispiel #8
0
Result aptInit(void)
{
	Result ret=0;

	if (AtomicPostIncrement(&aptRefCount)) return 0;

	// Initialize APT stuff, escape load screen.
	ret = __apt_initservicehandle();
	if(R_FAILED(ret)) goto _fail;
	if(R_FAILED(ret=APT_GetLockHandle(0x0, &aptLockHandle))) goto _fail;
	svcCloseHandle(aptuHandle);

	currentAppId = envGetAptAppId();

	svcCreateEvent(&aptStatusEvent, 0);
	svcCreateEvent(&aptSleepSync, 0);
	LightLock_Init(&aptStatusMutex);
	aptStatus=0;

	if(!aptIsCrippled())
	{
		aptOpenSession();
		if(R_FAILED(ret=APT_Initialize(currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
		aptCloseSession();
		
		aptOpenSession();
		if(R_FAILED(ret=APT_Enable(0x0))) goto _fail;
		aptCloseSession();
		
		// create APT close event
		svcCreateEvent(&aptEvents[2], 0);

		// After a cycle of APT_Finalize+APT_Initialize APT thinks the
		// application is suspended, so we need to tell it to unsuspend us.
		if (aptIsReinit())
		{
			aptOpenSession();
			APT_PrepareToJumpToApplication(0x0);
			aptCloseSession();

			aptOpenSession();
			APT_JumpToApplication(0x0, 0x0, 0x0);
			aptCloseSession();
		}
		
		aptOpenSession();
		if(R_FAILED(ret=APT_NotifyToWait(currentAppId)))goto _fail;
		aptCloseSession();

		// create APT event handler thread
		aptEventHandlerThread = threadCreate(aptEventHandler, 0x0, APT_HANDLER_STACKSIZE, 0x31, -2, true);

		// Wait for the state to become APT_RUNNING
		aptWaitStatusEvent();
	} else
		aptAppStarted();

	return 0;

_fail:
	AtomicDecrement(&aptRefCount);
	return ret;
}