...
 
Commits (8)
image: devkitpro/devkita64:latest
stages:
- package
- create image
package:
stage: package
before_script:
- dkp-pacman -S --noconfirm devkitARM
- export DEVKITPRO=/opt/devkitpro
- export DEVKITARM=/opt/devkitpro/devkitARM
script:
- make -j10
- make install
- rm -rf libnx/
- mv /opt/devkitpro/libnx libnx/
artifacts:
name: libnx
paths:
- libnx/
docker image:
stage: create image
script:
- "curl -X POST -F token=$TOKEN_DOCKER_IMAGE -F ref=master https://git.m4xw.net/api/v4/projects/103/trigger/pipeline"
when: on_success
only:
- master
nightly image:
stage: create image
script:
- "curl -X POST -F token=$TOKEN_DOCKER_IMAGE -F ref=develop https://git.m4xw.net/api/v4/projects/103/trigger/pipeline"
when: on_success
only:
- develop
- cicd/updates
......@@ -33,7 +33,7 @@ INCLUDES := include external/bsd/include
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
CFLAGS := -g -Wall -Werror \
CFLAGS := -g -Wall \
-ffunction-sections \
-fdata-sections \
$(ARCH) \
......@@ -122,7 +122,7 @@ debug:
lib/libnx.a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
BUILD_CFLAGS="-DNDEBUG=1 -O3 -ffast-math" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
......
/**
* @file hidsys.h
* @brief hid:sys service IPC wrapper.
* @author exelix
* @author exelix, yellows8
*/
#pragma once
#include "../types.h"
#include "../kernel/event.h"
#include "../services/hid.h"
#include "../services/sm.h"
/// Structure for \ref hidsysSetNotificationLedPattern.
typedef struct {
u8 unk_x0[0x48]; ///< TODO
} HidsysNotificationLedPattern;
Result hidsysInitialize(void);
void hidsysExit(void);
......@@ -21,3 +27,29 @@ Result hidsysAcquireHomeButtonEventHandle(Event* event_out);
Result hidsysActivateHomeButton(void);
Result hidsysActivateSleepButton(void);
Result hidsysActivateCaptureButton(void);
/**
* @brief Gets the UniquePadIds for the specified controller.
* @note Only available on [3.0.0+].
* @param id Controller ID. Must not be CONTROLLER_P1_AUTO.
* @param UniquePadIds Output array of UniquePadIds.
* @param Max number of entries for the UniquePadIds array.
* @param total_entries Total output array entries. Optional, can be NULL.
*/
Result hidsysGetUniquePadsFromNpad(HidControllerID id, u64 *UniquePadIds, size_t count, size_t *total_entries);
/**
* @brief Gets a list of all UniquePadIds.
* @param UniquePadIds Output array of UniquePadIds.
* @param Max number of entries for the UniquePadIds array.
* @param total_entries Total output array entries. Optional, can be NULL.
*/
Result hidsysGetUniquePadIds(u64 *UniquePadIds, size_t count, size_t *total_entries);
/**
* @brief Sets the HOME-button notification LED pattern, for the specified controller.
* @param pattern \ref HidsysNotificationLedPattern
* @param UniquePadId UniquePadId for the controller.
*/
Result hidsysSetNotificationLedPattern(const HidsysNotificationLedPattern *pattern, u64 UniquePadId);
......@@ -8,9 +8,94 @@
#include "../types.h"
typedef enum {
PcvModule_Cpu = 0,
PcvModule_Gpu = 1,
PcvModule_Emc = 56,
PcvModule_CpuBus = 0,
PcvModule_GPU = 1,
PcvModule_I2S1 = 2,
PcvModule_I2S2 = 3,
PcvModule_I2S3 = 4,
PcvModule_PWM = 5,
PcvModule_I2C1 = 6,
PcvModule_I2C2 = 7,
PcvModule_I2C3 = 8,
PcvModule_I2C4 = 9,
PcvModule_I2C5 = 10,
PcvModule_I2C6 = 11,
PcvModule_SPI1 = 12,
PcvModule_SPI2 = 13,
PcvModule_SPI3 = 14,
PcvModule_SPI4 = 15,
PcvModule_DISP1 = 16,
PcvModule_DISP2 = 17,
PcvModule_ISP = 18,
PcvModule_VI = 19,
PcvModule_SDMMC1 = 20,
PcvModule_SDMMC2 = 21,
PcvModule_SDMMC3 = 22,
PcvModule_SDMMC4 = 23,
PcvModule_OWR = 24,
PcvModule_CSITE = 25,
PcvModule_TSEC = 26,
PcvModule_MSELECT = 27,
PcvModule_HDA2CODEC_2X = 28,
PcvModule_ACTMON = 29,
PcvModule_I2C_SLOW = 30,
PcvModule_SOR1 = 31,
PcvModule_SATA = 32,
PcvModule_HDA = 33,
PcvModule_XUSB_CORE_HOST = 34,
PcvModule_XUSB_FALCON = 35,
PcvModule_XUSB_FS = 36,
PcvModule_XUSB_CORE_DEV = 37,
PcvModule_XUSB_SS_HOSTDEV = 38,
PcvModule_UARTA = 39,
PcvModule_UARTB = 40,
PcvModule_UARTC = 41,
PcvModule_UARTD = 42,
PcvModule_HOST1X = 43,
PcvModule_ENTROPY = 44,
PcvModule_SOC_THERM = 45,
PcvModule_VIC = 46,
PcvModule_NVENC = 47,
PcvModule_NVJPG = 48,
PcvModule_NVDEC = 49,
PcvModule_QSPI = 50,
PcvModule_VI_I2C = 51,
PcvModule_TSECB = 52,
PcvModule_APE = 53,
PcvModule_ACLK = 54,
PcvModule_UARTAPE = 55,
PcvModule_EMC = 56,
PcvModule_PLLE0_0 = 57,
PcvModule_PLLE0_1 = 58,
PcvModule_DSI = 59,
PcvModule_MAUD = 60,
PcvModule_DPAUX1 = 61,
PcvModule_MIPI_CAL = 62,
PcvModule_UART_FST_MIPI_CAL = 63,
PcvModule_OSC = 64,
PcvModule_SCLK = 65,
PcvModule_SOR_SAFE = 66,
PcvModule_XUSB_SS = 67,
PcvModule_XUSB_HOST = 68,
PcvModule_XUSB_DEV = 69,
PcvModule_EXTPERIPH1 = 70,
PcvModule_AHUB = 71,
PcvModule_HDA2HDMICODEC = 72,
PcvModule_PLLP5 = 73,
PcvModule_USBD = 74,
PcvModule_USB2 = 75,
PcvModule_PCIE = 76,
PcvModule_AFI = 77,
PcvModule_PCIEXCLK = 78,
PcvModule_PEX_USB_UPHY = 79,
PcvModule_XUSB_PADCTL = 80,
PcvModule_APBDMA = 81,
PcvModule_USB2_TRK = 82,
PcvModule_PLLE0_2 = 83,
PcvModule_PLLE0_3 = 84,
PcvModule_CEC = 85,
PcvModule_EXTPERIPH2 = 86,
PcvModule_Count // Not a real module, used to know how many modules there are.
} PcvModule;
/// Module id returned by [8.0.0+] pcv services
......@@ -34,10 +119,13 @@ typedef enum {
PcvModuleId_SPI4 = 0x07000003,
PcvModuleId_DISP1 = 0x40000011,
PcvModuleId_DISP2 = 0x40000012,
PcvModuleId_ISP = 0x40000013,
PcvModuleId_VI = 0x40000014,
PcvModuleId_SDMMC1 = 0x40000015,
PcvModuleId_SDMMC2 = 0x40000016,
PcvModuleId_SDMMC3 = 0x40000017,
PcvModuleId_SDMMC4 = 0x40000018,
PcvModuleId_OWR = 0x40000019,
PcvModuleId_CSITE = 0x4000001A,
PcvModuleId_TSEC = 0x4000001B,
PcvModuleId_MSELECT = 0x4000001C,
......@@ -45,6 +133,7 @@ typedef enum {
PcvModuleId_ACTMON = 0x4000001E,
PcvModuleId_I2C_SLOW = 0x4000001F,
PcvModuleId_SOR1 = 0x40000020,
PcvModuleId_SATA = 0x40000021,
PcvModuleId_HDA = 0x40000022,
PcvModuleId_XUSB_CORE_HOST = 0x40000023,
PcvModuleId_XUSB_FALCON = 0x40000024,
......@@ -63,6 +152,7 @@ typedef enum {
PcvModuleId_NVJPG = 0x40000031,
PcvModuleId_NVDEC = 0x40000032,
PcvModuleId_QSPI = 0x40000033,
PcvModuleId_VI_I2C = 0x40000034,
PcvModuleId_TSECB = 0x40000035,
PcvModuleId_APE = 0x40000036,
PcvModuleId_ACLK = 0x40000037,
......@@ -103,6 +193,8 @@ typedef enum {
Result pcvInitialize(void);
void pcvExit(void);
Result pcvGetModuleId(PcvModuleId *module_id, PcvModule module);
Result pcvGetClockRate(PcvModule module, u32 *out_hz);
Result pcvSetClockRate(PcvModule module, u32 hz);
Result pcvSetVoltageEnabled(bool state, u32 voltage);
......
......@@ -64,7 +64,7 @@ Result splCryptoGenerateAesKek(const void *wrapped_kek, u32 key_generation, u32
Result splCryptoLoadAesKey(const void *sealed_kek, const void *wrapped_key, u32 keyslot);
Result splCryptoGenerateAesKey(const void *sealed_kek, const void *wrapped_key, void *out_sealed_key);
Result splCryptoDecryptAesKey(const void *wrapped_key, u32 key_generation, u32 option, void *out_sealed_key);
Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, const void *ctr);
Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, u32 keyslot, const void *ctr);
Result splCryptoComputeCmac(const void *input, size_t size, u32 keyslot, void *out_cmac);
Result splCryptoLockAesEngine(u32 *out_keyslot);
Result splCryptoUnlockAesEngine(u32 keyslot);
......
......@@ -6,7 +6,9 @@
#include "kernel/event.h"
#include "services/applet.h"
#include "services/hidsys.h"
#include "services/hid.h"
#include "services/sm.h"
#include "runtime/hosversion.h"
static Service g_hidsysSrv;
static u64 g_hidsysRefCnt;
......@@ -179,3 +181,123 @@ Result hidsysActivateSleepButton(void) {
Result hidsysActivateCaptureButton(void) {
return _hidsysCmdWithResIdAndPid(151);
}
Result hidsysGetUniquePadsFromNpad(HidControllerID id, u64 *UniquePadIds, size_t count, size_t *total_entries) {
if (hosversionBefore(3,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Result rc;
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u32 id;
} PACKED *raw;
ipcAddRecvStatic(&c, UniquePadIds, sizeof(u64)*count, 0);
raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 321;
raw->id = hidControllerIDToOfficial(id);
rc = serviceIpcDispatch(&g_hidsysSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u64 total_entries;
} *resp;
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw;
if (R_SUCCEEDED(rc) && total_entries) *total_entries = resp->total_entries;
}
return rc;
}
Result hidsysGetUniquePadIds(u64 *UniquePadIds, size_t count, size_t *total_entries) {
Result rc;
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
} *raw;
ipcAddRecvStatic(&c, UniquePadIds, sizeof(u64)*count, 0);
raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 703;
rc = serviceIpcDispatch(&g_hidsysSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u64 total_entries;
} *resp;
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw;
if (R_SUCCEEDED(rc) && total_entries) *total_entries = resp->total_entries;
}
return rc;
}
Result hidsysSetNotificationLedPattern(const HidsysNotificationLedPattern *pattern, u64 UniquePadId) {
if (hosversionBefore(7,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Result rc;
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
HidsysNotificationLedPattern pattern;
u64 UniquePadId;
} *raw;
raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 830;
memcpy(&raw->pattern, pattern, sizeof(*pattern));
raw->UniquePadId = UniquePadId;
rc = serviceIpcDispatch(&g_hidsysSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u64 total_entries;
} *resp;
serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp));
resp = r.Raw;
}
return rc;
}
......@@ -30,6 +30,40 @@ void pcvExit(void) {
}
}
Result pcvGetModuleId(PcvModuleId *module_id, PcvModule module) {
static const PcvModuleId s_moduleIdMap[PcvModule_Count] = {
PcvModuleId_CpuBus, PcvModuleId_GPU, PcvModuleId_I2S1, PcvModuleId_I2S2,
PcvModuleId_I2S3, PcvModuleId_PWM, PcvModuleId_I2C1, PcvModuleId_I2C2,
PcvModuleId_I2C3, PcvModuleId_I2C4, PcvModuleId_I2C5, PcvModuleId_I2C6,
PcvModuleId_SPI1, PcvModuleId_SPI2, PcvModuleId_SPI3, PcvModuleId_SPI4,
PcvModuleId_DISP1, PcvModuleId_DISP2, PcvModuleId_ISP, PcvModuleId_VI,
PcvModuleId_SDMMC1, PcvModuleId_SDMMC2, PcvModuleId_SDMMC3, PcvModuleId_SDMMC4,
PcvModuleId_OWR, PcvModuleId_CSITE, PcvModuleId_TSEC, PcvModuleId_MSELECT,
PcvModuleId_HDA2CODEC_2X, PcvModuleId_ACTMON, PcvModuleId_I2C_SLOW, PcvModuleId_SOR1,
PcvModuleId_SATA, PcvModuleId_HDA, PcvModuleId_XUSB_CORE_HOST, PcvModuleId_XUSB_FALCON,
PcvModuleId_XUSB_FS, PcvModuleId_XUSB_CORE_DEV, PcvModuleId_XUSB_SS_HOSTDEV, PcvModuleId_UARTA,
PcvModuleId_UARTB, PcvModuleId_UARTC, PcvModuleId_UARTD, PcvModuleId_HOST1X,
PcvModuleId_ENTROPY, PcvModuleId_SOC_THERM, PcvModuleId_VIC, PcvModuleId_NVENC,
PcvModuleId_NVJPG, PcvModuleId_NVDEC, PcvModuleId_QSPI, PcvModuleId_VI_I2C,
PcvModuleId_TSECB, PcvModuleId_APE, PcvModuleId_ACLK, PcvModuleId_UARTAPE,
PcvModuleId_EMC, PcvModuleId_PLLE0_0, PcvModuleId_PLLE0_1, PcvModuleId_DSI,
PcvModuleId_MAUD, PcvModuleId_DPAUX1, PcvModuleId_MIPI_CAL, PcvModuleId_UART_FST_MIPI_CAL,
PcvModuleId_OSC, PcvModuleId_SCLK, PcvModuleId_SOR_SAFE, PcvModuleId_XUSB_SS,
PcvModuleId_XUSB_HOST, PcvModuleId_XUSB_DEV, PcvModuleId_EXTPERIPH1, PcvModuleId_AHUB,
PcvModuleId_HDA2HDMICODEC, PcvModuleId_PLLP5, PcvModuleId_USBD, PcvModuleId_USB2,
PcvModuleId_PCIE, PcvModuleId_AFI, PcvModuleId_PCIEXCLK, PcvModuleId_PEX_USB_UPHY,
PcvModuleId_XUSB_PADCTL, PcvModuleId_APBDMA, PcvModuleId_USB2_TRK, PcvModuleId_PLLE0_2,
PcvModuleId_PLLE0_3, PcvModuleId_CEC, PcvModuleId_EXTPERIPH2,
};
if (module >= PcvModule_Count) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
*module_id = s_moduleIdMap[module];
return 0;
}
Result pcvSetClockRate(PcvModule module, u32 hz) {
if(hosversionAtLeast(8,0,0)) {
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
......
......@@ -56,8 +56,12 @@ Result smInitialize(void)
return 0;
Result rc = svcConnectToNamedPort(&g_smHandle, "sm:");
Handle tmp;
while (R_VALUE(rc) == KERNELRESULT(NotFound)) {
svcSleepThread(50000000ul);
rc = svcConnectToNamedPort(&g_smHandle, "sm:");
}
Handle tmp;
if (R_SUCCEEDED(rc) && smGetServiceOriginal(&tmp, smEncodeName("")) == 0x415) {
IpcCommand c;
ipcInitialize(&c);
......
......@@ -572,7 +572,7 @@ Result splCryptoDecryptAesKey(const void *wrapped_key, u32 key_generation, u32 o
return rc;
}
Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, const void *ctr) {
Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, u32 keyslot, const void *ctr) {
IpcCommand c;
ipcInitialize(&c);
......@@ -583,6 +583,7 @@ Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, const
u64 magic;
u64 cmd_id;
u8 ctr[0x10];
u32 keyslot;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
......@@ -590,6 +591,7 @@ Result splCryptoCryptAesCtr(const void *input, void *output, size_t size, const
raw->magic = SFCI_MAGIC;
raw->cmd_id = 15;
memcpy(raw->ctr, ctr, sizeof(raw->ctr));
raw->keyslot = keyslot;
Result rc = serviceIpcDispatch(_splGetCryptoSrv());
......