1
0
mirror of https://github.com/switchbrew/libnx.git synced 2025-07-13 22:42:14 +02:00

Compare commits

...

13 Commits

Author SHA1 Message Date
MasaGratoR
96f063ac13
Cover new Chinese and Brazilian Portuguese language IDs for nacpGetLanguageEntry 2025-07-13 20:32:04 +02:00
yellows8
70ea18a477
ldn: Added *ActionFrame, ldnSetHomeChannel, *TxPower. 2025-06-30 15:48:05 -04:00
MasaGratoR
18002c9735
Update SetSysEdid to include different types of Extension blocks () 2025-06-25 09:08:53 +01:00
ITotalJustice
f094767faf
add usbDsGetSpeed and missing speed enum entries. () 2025-06-25 07:44:46 +01:00
yellows8
1ff513dc17
ldn: Updated docs. 2025-06-24 12:54:32 -04:00
Dave Murphy
2680749e8c
ensure libs rebuilt on code changes 2025-06-24 16:05:12 +01:00
yellows8
dfee0c8ba2
ldn: Added ldnSetProtocol. 2025-06-18 18:17:05 -04:00
Dave Murphy
0a4ac1b87c
remove unused dist-bin target 2025-06-12 16:06:29 +01:00
Dave Murphy
638624cf02
actually install libs too. Closes 2025-06-12 08:40:44 +01:00
Dave Murphy
2f471a1c26
remove unused version number in Makefile ()
* remove unused version number in Makefile
* add dist-src target using git tag
2025-06-10 18:01:55 +01:00
ndeadly
d1dbd8db51 btdrv: fix struct alignment issue in BtdrvBleEventInfo 2025-06-09 21:26:36 +02:00
XorTroll
de7cfeb3d9
nfp: Improve types and enums 2025-05-18 01:09:53 +02:00
ndeadly
2fc81d8f35 btdrv: label proto_mode field in data_report event info 2025-05-18 01:08:51 +02:00
11 changed files with 472 additions and 144 deletions
nx
Makefile
include/switch/services
source

View File

@ -8,13 +8,6 @@ endif
include $(DEVKITPRO)/devkitA64/base_rules
export LIBNX_MAJOR := 4
export LIBNX_MINOR := 7
export LIBNX_PATCH := 0
VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH)
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
@ -90,22 +83,19 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
-I. \
-iquote $(CURDIR)/include/switch/
.PHONY: clean all
.PHONY: clean all lib/libnx.a lib/libnxd.a
#---------------------------------------------------------------------------------
all: lib/libnx.a lib/libnxd.a
dist-bin: all
@tar --exclude=*~ -cjf libnx-$(VERSION).tar.bz2 include lib default_icon.jpg switch_rules switch.ld switch.specs -C external/bsd include
install: lib/libnx.a lib/libnxd.a
@mkdir -p $(DESTDIR)$(DEVKITPRO)/libnx
@cp -v default_icon.jpg switch_rules switch.ld switch.specs $(DESTDIR)$(DEVKITPRO)/libnx/
@cp -rv include lib $(DESTDIR)$(DEVKITPRO)/libnx/
@cp -rv external/bsd/include $(DESTDIR)$(DEVKITPRO)/libnx/
dist-src:
@tar --exclude=*~ -cjf libnx-src-$(VERSION).tar.bz2 include source data external Makefile default_icon.jpg switch_rules switch.ld switch.specs
dist: dist-src dist-bin
install: dist-bin
mkdir -p $(DESTDIR)$(DEVKITPRO)/libnx
bzip2 -cd libnx-$(VERSION).tar.bz2 | tar -xf - -C $(DESTDIR)$(DEVKITPRO)/libnx
@tar -cjf libnx-`git describe --tags | sed 's/^v//'`.tar.bz2 include source data external Makefile default_icon.jpg switch_rules switch.ld switch.specs
#dox:
# @doxygen Doxyfile

View File

@ -242,7 +242,7 @@ typedef struct {
struct {
u32 res; ///< Always 0.
u8 unk_x4; ///< Always 0.
u8 proto_mode; ///< Protocol mode. Always 0 (report mode).
BtdrvAddress addr; ///< \ref BtdrvAddress
u8 pad; ///< Padding
BtdrvHidReport report;
@ -372,8 +372,8 @@ typedef struct {
struct {
u32 result; ///< 0 for success, non-zero for error.
u8 status; ///< Connection status. 0 = Connected, 2 = Disconnected
u16 server_if; ///< Server interface handle
u8 pad; ///< Padding
u8 server_if; ///< Server interface handle
u8 pad[2]; ///< Padding
u32 conn_id; ///< Connection ID
BtdrvAddress address; ///< Device address
u16 reason; ///< Disconnection reason

View File

@ -67,6 +67,12 @@ typedef enum {
LdnWirelessControllerRestriction_Unknown1 = 1, ///< Unknown
} LdnWirelessControllerRestriction;
/// Protocol
typedef enum {
LdnProtocol_NX = 1, ///< NX (default)
LdnProtocol_Unknown3 = 3, ///< (NXAndOunce?)
} LdnProtocol;
/// Ipv4Address. This is essentially the same as struct in_addr - hence this can be used with standard sockets (byteswap required).
typedef struct {
u32 addr; ///< Address
@ -187,6 +193,15 @@ typedef struct {
u8 reserved_x16[0xA]; ///< Cleared to zero for the tmp struct.
} LdnNetworkConfig;
/// ActionFrameSettings
typedef struct {
s64 local_communication_id; ///< LocalCommunicationId (Same handling as LdnNetworkConfig::local_communication_id)
u8 reserved[0x34]; ///< Reserved
u16 security_mode; ///< SecurityMode (Must be 1-2, internally this is overriden)
u16 passphrase_size; ///< PassphraseSize (Must be 0x10-0x40)
u8 passphrase[0x40]; ///< Passphrase
} LdnActionFrameSettings;
///@name ldn:m
///@{
@ -331,6 +346,14 @@ Result ldnScanPrivate(s32 channel, const LdnScanFilter *filter, LdnNetworkInfo *
*/
Result ldnSetWirelessControllerRestriction(LdnWirelessControllerRestriction restriction);
/**
* @brief SetProtocol
* @note This is only usable with [20.0.0+] (with [18.0.0-19-0.1] this is available but not usable).
* @note \ref LdnState must be ::LdnState_Initialized. If a non-default Protocol is wanted, use this after \ref ldnInitialize.
* @param[in] protocol \ref LdnProtocol
*/
Result ldnSetProtocol(LdnProtocol protocol);
/**
* @brief OpenAccessPoint
* @note \ref LdnState must be ::LdnState_Initialized, this eventually sets the State to ::LdnState_AccessPointOpened.
@ -462,5 +485,71 @@ Result ldnDisconnect(void);
*/
Result ldnSetOperationMode(LdnOperationMode mode);
/**
* @brief EnableActionFrame
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_Initialized.
* @param[in] settings \ref LdnActionFrameSettings
*/
Result ldnEnableActionFrame(const LdnActionFrameSettings *settings);
/**
* @brief DisableActionFrame
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_Initialized.
*/
Result ldnDisableActionFrame(void);
/**
* @brief SendActionFrame
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_AccessPointCreated / ::LdnState_StationOpened.
* @param[in] data Data buffer.
* @param[in] size Data buffer size.
* @param[in] destination Destination \ref LdnMacAddress.
* @param[in] bssid Bssid \ref LdnMacAddress.
* @param[in] channel Channel, must be non-zero.
* @param[in] flags MessageFlag bit0 clear = block until the data can be sent, set = return error when the data can't be sent.
*/
Result ldnSendActionFrame(const void* data, size_t size, LdnMacAddress destination, LdnMacAddress bssid, s16 channel, u32 flags);
/**
* @brief RecvActionFrame
* @note Only available on [18.0.0+].
* @note \ref ldnEnableActionFrame must be used prior to this.
* @param[out] data Output data buffer.
* @param[in] size Max size of the data buffer.
* @param[out] addr0 First \ref LdnMacAddress.
* @param[out] addr1 Second \ref LdnMacAddress.
* @param[out] channel Channel
* @param[out] out_size Output size.
* @param[out] link_level LinkLevel
* @param[in] flags MessageFlag bit0 clear = block until data is available, set = return error when data is not available.
*/
Result ldnRecvActionFrame(void* data, size_t size, LdnMacAddress *addr0, LdnMacAddress *addr1, s16 *channel, u32 *out_size, s32 *link_level, u32 flags);
/**
* @brief SetHomeChannel
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_StationOpened.
* @param[in] channel Channel, must be non-zero.
*/
Result ldnSetHomeChannel(s16 channel);
/**
* @brief SetTxPower
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_AccessPoint* / ::LdnState_Station*.
* @param[in] power Power, must be 0x0..0xFF.
*/
Result ldnSetTxPower(s16 power);
/**
* @brief ResetTxPower
* @note Only available on [18.0.0+].
* @note \ref LdnState must be ::LdnState_AccessPoint* / ::LdnState_Station*.
*/
Result ldnResetTxPower(void);
///@}

View File

@ -113,6 +113,15 @@ typedef struct {
u8 unk_x57;
} MiiCharInfo;
typedef struct {
u8 data[0x44];
} MiiStoreData;
// Mii format used in 3DS (https://www.3dbrew.org/wiki/Mii#Mii_format).
typedef struct {
u8 data[0x5C];
} MiiVer3StoreData;
// Original Mii colors and types before Ver3StoreData conversion
typedef struct {
u8 faceline_color;

View File

@ -23,11 +23,6 @@ typedef enum {
NfcServiceType_System = 1, ///< Initializes nfc:sys.
} NfcServiceType;
typedef enum {
NfpState_NonInitialized = 0,
NfpState_Initialized = 1,
} NfpState;
typedef enum {
NfcState_NonInitialized = 0,
NfcState_Initialized = 1,
@ -40,7 +35,6 @@ typedef enum {
NfpDeviceState_TagRemoved = 3,
NfpDeviceState_TagMounted = 4,
NfpDeviceState_Unavailable = 5,
NfpDeviceState_Finalized = 6,
} NfpDeviceState;
typedef enum {
@ -49,16 +43,23 @@ typedef enum {
NfcDeviceState_TagFound = 2,
NfcDeviceState_TagRemoved = 3,
NfcDeviceState_TagMounted = 4,
NfcDeviceState_Unavailable = 5,
NfcDeviceState_Finalized = 6,
} NfcDeviceState;
typedef enum {
NfpApplicationAreaVersion_3DS = 0,
NfpApplicationAreaVersion_WiiU = 1,
NfpApplicationAreaVersion_3DSv2 = 2,
NfpApplicationAreaVersion_Switch = 3,
NfpApplicationAreaVersion_NotSet = 0xFF,
NfcMifareDeviceState_Initialized = 0,
NfcMifareDeviceState_SearchingForTag = 1,
NfcMifareDeviceState_TagFound = 2,
NfcMifareDeviceState_TagRemoved = 3,
NfcMifareDeviceState_TagMounted = 4,
NfcMifareDeviceState_Unavailable = 5,
} NfcMifareDeviceState;
typedef enum {
NfpApplicationAreaVersion_3DS = 0, ///< Application area created by a 3DS game.
NfpApplicationAreaVersion_WiiU = 1, ///< Application area created by a Wii U game.
NfpApplicationAreaVersion_3DSv2 = 2, ///< Application area created by a (new?) 3DS game.
NfpApplicationAreaVersion_Switch = 3, ///< Application area created by a Switch game.
NfpApplicationAreaVersion_Invalid = 0xFF, ///< Invalid value (application area not created).
} NfpApplicationAreaVersion;
typedef enum {
@ -66,9 +67,9 @@ typedef enum {
} NfpDeviceType;
typedef enum {
NfpMountTarget_Rom = 1,
NfpMountTarget_Ram = 2,
NfpMountTarget_All = 3,
NfpMountTarget_Rom = BIT(0),
NfpMountTarget_Ram = BIT(1),
NfpMountTarget_All = NfpMountTarget_Rom | NfpMountTarget_Ram,
} NfpMountTarget;
typedef enum {
@ -102,104 +103,123 @@ typedef enum {
NfcMifareCommand_Store = 0xC2,
} NfcMifareCommand;
typedef struct {
u8 uuid[10];
u8 uuid_length;
u8 reserved1[0x15];
u32 protocol;
u32 tag_type;
u8 reserved2[0x30];
} NX_PACKED NfpTagInfo;
typedef enum {
NfpAmiiboFlag_Valid = BIT(0), ///< Initialized in system settings.
NfpAmiiboFlag_ApplicationAreaExists = BIT(1), ///< Application area exists.
} NfpAmiiboFlag;
typedef enum {
NfpBreakType_Flush = 0,
NfpBreakType_Break1 = 1,
NfpBreakType_Break2 = 2,
} NfpBreakType;
typedef struct {
u8 uuid[10];
u8 uuid_length;
u8 reserved1[0x15];
u32 protocol;
u32 tag_type;
u8 reserved2[0x30];
} NX_PACKED NfcTagInfo;
u16 year;
u8 month;
u8 day;
} NfpDate;
typedef struct {
u16 last_write_year;
u8 last_write_month;
u8 last_write_day;
u8 uid[10]; ///< UUID.
u8 uid_length; ///< UUID length.
u8 reserved[0x15];
} NfcTagUid;
typedef struct {
NfcTagUid uid; ///< UUID.
u32 protocol; ///< \ref NfcProtocol
u32 tag_type; ///< \ref NfcTagType
u8 reserved[0x30];
} NfpTagInfo;
typedef struct {
NfcTagUid uid; ///< UUID.
u32 protocol; ///< \ref NfcProtocol
u32 tag_type; ///< \ref NfcTagType
u8 reserved[0x30];
} NfcTagInfo;
typedef struct {
NfpDate last_write_date;
u16 write_counter;
u16 version;
u32 application_area_size;
u8 reserved[0x34];
} NX_PACKED NfpCommonInfo;
u8 reserved[0x34];
} NfpCommonInfo;
typedef struct {
u8 amiibo_id[0x8];
u8 reserved[0x38];
} NX_PACKED NfpModelInfo;
union {
u8 character_id[3];
struct {
u16 game_character_id;
u8 character_variant;
} NX_PACKED;
};
u8 series_id; ///< Series.
u16 numbering_id; ///< Model number.
u8 nfp_type; ///< Figure type.
u8 reserved[0x39];
} NfpModelInfo;
typedef struct {
MiiCharInfo mii;
u16 first_write_year;
u8 first_write_month;
u8 first_write_day;
char amiibo_name[(10*4)+1]; ///< utf-8, null-terminated
NfpDate first_write_date;
char amiibo_name[(10*4)+1]; ///< Amiibo name (utf-8, null-terminated).
u8 font_region;
u8 reserved[0x7A];
} NX_PACKED NfpRegisterInfo;
} NfpRegisterInfo;
typedef struct {
u8 mii_store_data[0x44];
u16 first_write_year;
u8 first_write_month;
u8 first_write_day;
char amiibo_name[(10*4)+1]; ///< utf-8, null-terminated
MiiStoreData mii_store_data;
NfpDate first_write_date;
char amiibo_name[(10*4)+1]; ///< Amiibo name (utf-8, null-terminated).
u8 font_region;
u8 reserved[0x8E];
} NX_PACKED NfpRegisterInfoPrivate;
} NfpRegisterInfoPrivate;
typedef struct {
u64 application_id;
u32 application_area_id;
u16 crc_change_counter;
u32 access_id;
u16 crc32_change_counter;
u8 flags;
u8 tag_type;
u8 application_area_version;
u8 reserved[0x2F];
} NX_PACKED NfpAdminInfo;
} NfpAdminInfo;
typedef struct {
u8 magic;
u8 tag_magic; ///< Tag magic (always 0xA5: https://www.3dbrew.org/wiki/Amiibo#Page_layout).
u8 reserved1[0x1];
u8 write_counter;
u8 reserved2[0x1];
u32 settings_crc;
u8 reserved3[0x38];
u16 last_write_year;
u8 last_write_month;
u8 last_write_day;
u16 application_write_counter;
u16 version;
u32 application_area_size;
u8 reserved4[0x34];
MiiCharInfo mii;
MiiNfpStoreDataExtension mii_store_data_extension;
u16 first_write_year;
u8 first_write_month;
u8 first_write_day;
u16 amiibo_name[10+1]; ///< utf-16, null-terminated
u8 settings_flag; ///< bit4 = amiibo was initialized in console settings, bit5 = has application area
u8 unknown1; ///< Normally zero
u32 register_info_crc;
u32 unknown2[0x5]; ///< Normally zero
u8 reserved5[0x64];
u64 application_id;
u32 access_id;
u16 settings_crc_counter;
u8 font_region;
u8 tag_type;
u8 console_type;
u8 application_id_byte; ///< (Original Program ID >> 0x24) & 0xF byte (Program ID has this byte swapped with console type)
u8 reserved6[0x2E];
u8 application_area[0xD8];
} NX_PACKED NfpData;
u16 tag_write_counter; ///< Incremented every tag write.
u32 crc32_1; ///< CRC32 of some internal 8-byte data.
u8 reserved2[0x38];
NfpDate last_write_date; ///< Updated every write.
u16 write_counter; ///< Incremented every write, until it maxes out at 0xFFFF.
u16 version; ///< Version.
u32 application_area_size; ///< Size of the application area.
u8 reserved3[0x34];
MiiVer3StoreData mii_v3; ///< Ver3StoreData (Mii format used in 3DS).
u8 pad[0x2];
u16 mii_v3_crc16; ///< CRC16 of Ver3StoreData.
MiiNfpStoreDataExtension mii_store_data_extension; ///< StoreDataExtension
NfpDate first_write_date; ///< Set when the amiibo is first written to.
u16 amiibo_name[10+1]; ///< Amiibo name (utf-16, null-terminated).
u8 font_region; ///< Font region.
u8 unknown1; ///< Normally zero
u32 crc32_2; ///< CRC32 of Ver3StoreData + application_id_byte + unknown1 + StoreDataExtension + unknown2 (0x7E bytes total)
u32 unknown2[0x5]; ///< Normally zero
u8 reserved4[0x64];
u64 application_id; ///< Modified application ID (Application ID & 0xFFFFFFFF0FFFFFFF | 0x30000000)
u32 access_id; ///< Application area access ID
u16 settings_crc32_change_counter;
u8 flags; ///< \ref NfpAmiiboFlag
u8 tag_type; ///< \ref NfcTagType
u8 application_area_version; ///< \ref NfpApplicationAreaVersion
u8 application_id_byte; ///< Application ID byte ((Application ID >> 28) & 0xFF)
u8 reserved5[0x2E];
u8 application_area[0xD8]; ///< Application area.
} NfpData;
typedef struct {
u8 mifare_command;
@ -292,21 +312,29 @@ Result nfcMfStartDetection(const NfcDeviceHandle *handle);
Result nfcMfStopDetection(const NfcDeviceHandle *handle);
/// Not available with ::NfpServiceType_System.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpOpenApplicationArea(const NfcDeviceHandle *handle, u32 app_id);
/// Not available with ::NfpServiceType_System.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram, and the application area to be opened.
Result nfpGetApplicationArea(const NfcDeviceHandle *handle, void* buf, size_t buf_size, u32 *out_size);
/// Not available with ::NfpServiceType_System.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram, and the application area to be opened.
Result nfpSetApplicationArea(const NfcDeviceHandle *handle, const void* buf, size_t buf_size);
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpFlush(const NfcDeviceHandle *handle);
Result nfpRestore(const NfcDeviceHandle *handle);
/// Not available with ::NfpServiceType_System.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpCreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void* buf, size_t buf_size);
/// Not available with ::NfpServiceType_System.
/// Only available with [3.0.0+].
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram, and the application area to be opened.
Result nfpRecreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void* buf, size_t buf_size);
/// Not available with ::NfpServiceType_System.
@ -319,10 +347,18 @@ Result nfpDeleteApplicationArea(const NfcDeviceHandle *handle);
Result nfpExistsApplicationArea(const NfcDeviceHandle *handle, bool *out);
Result nfpGetTagInfo(const NfcDeviceHandle *handle, NfpTagInfo *out);
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpGetRegisterInfo(const NfcDeviceHandle *handle, NfpRegisterInfo *out);
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpGetCommonInfo(const NfcDeviceHandle *handle, NfpCommonInfo *out);
/// Requires the amiibo to be mounted with ::NfpMountTarget_Rom.
Result nfpGetModelInfo(const NfcDeviceHandle *handle, NfpModelInfo *out);
/// Not available with ::NfpServiceType_User.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpGetAdminInfo(const NfcDeviceHandle *handle, NfpAdminInfo *out);
/// Only available with [4.0.0+].
@ -347,7 +383,7 @@ Result nfcMfAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event)
/// Returned event will have autoclear off.
Result nfcMfAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event);
Result nfpGetState(NfpState *out);
Result nfpGetState(NfcState *out);
Result nfpGetDeviceState(const NfcDeviceHandle *handle, NfpDeviceState *out);
Result nfpGetNpadId(const NfcDeviceHandle *handle, u32 *out);
@ -359,7 +395,7 @@ Result nfcGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out);
Result nfcGetNpadId(const NfcDeviceHandle *handle, u32 *out);
Result nfcMfGetState(NfcState *out);
Result nfcMfGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out);
Result nfcMfGetDeviceState(const NfcDeviceHandle *handle, NfcMifareDeviceState *out);
Result nfcMfGetNpadId(const NfcDeviceHandle *handle, u32 *out);
/// Returned event will have autoclear on.
@ -375,25 +411,39 @@ Result nfcMfAttachAvailabilityChangeEvent(Event *out_event);
Result nfpFormat(const NfcDeviceHandle *handle);
/// Not available with ::NfpServiceType_User.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpGetRegisterInfoPrivate(const NfcDeviceHandle *handle, NfpRegisterInfoPrivate *out);
/// Not available with ::NfpServiceType_User.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpSetRegisterInfoPrivate(const NfcDeviceHandle *handle, const NfpRegisterInfoPrivate *register_info_private);
/// Not available with ::NfpServiceType_User.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpDeleteRegisterInfo(const NfcDeviceHandle *handle);
/// Only available with ::NfpServiceType_Debug.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpGetAll(const NfcDeviceHandle *handle, NfpData *out);
/// Only available with ::NfpServiceType_Debug.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpSetAll(const NfcDeviceHandle *handle, const NfpData *nfp_data);
/// Only available with ::NfpServiceType_Debug.
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpFlushDebug(const NfcDeviceHandle *handle);
/// Only available with ::NfpServiceType_Debug.
Result nfpBreakTag(const NfcDeviceHandle *handle, u32 break_type);
/// Requires the amiibo to be mounted with ::NfpMountTarget_Ram.
Result nfpBreakTag(const NfcDeviceHandle *handle, NfpBreakType break_type);
/// Only available with ::NfpServiceType_Debug.
Result nfpReadBackupData(const NfcDeviceHandle *handle, void* out_buf, size_t buf_size, u32 *out_size);
/// Only available with ::NfpServiceType_Debug.
Result nfpWriteBackupData(const NfcDeviceHandle *handle, const void* buf, size_t buf_size);
/// Only available with ::NfpServiceType_Debug.
Result nfpWriteNtf(const NfcDeviceHandle *handle, u32 write_type, const void* buf, size_t buf_size);

View File

@ -487,6 +487,30 @@ typedef struct {
u8 padding[2];
} SetSysDataBlock;
typedef struct {
u8 extension_tag; ///< 2 = CEA EDID timing extension, 0x70 = DisplayID Extension Block, 0xF0 = EDID Extension Block Map
union {
struct {
u8 revision;
u8 dtd_start;
u8 native_dtd_count : 4;
u8 native_dtd_feature_bitmap : 4;
SetSysDataBlock data_block;
SetSysModeLine extended_timing_descriptor[5];
u8 padding[5];
} NX_PACKED cea; ///< CEA EDID timing extension
struct {
u8 data[0x7E];
} display_id; ///< [13.0.0+] DisplayID Extension Block
struct {
u8 second_block_extension_tag;
u8 third_block_extension_tag;
u8 padding[0x7C];
} block_map; ///< [13.0.0+] EDID Extension Block Map
} extension_block;
u8 extended_checksum; ///< Sum of 128 extended bytes should equal 0 mod 256.
} SetSysExtensionBlock;
/// Edid
typedef struct {
u8 pattern[8]; ///< Fixed pattern 00 FF FF FF FF FF FF 00.
@ -494,7 +518,7 @@ typedef struct {
u16 product_code;
u32 serial_number;
u8 manufacture_week;
u8 manufacture_year; ///< Real value is val - 10.
u8 manufacture_year; ///< Real year is 1990 + val.
u8 edid_version;
u8 edid_revision;
u8 video_input_parameters_bitmap;
@ -545,20 +569,12 @@ typedef struct {
u8 extended_timing_info;
u8 padding[7];
} display_descriptor_range_limits;
u8 extension_count; ///< Always 1.
u8 extension_count;
u8 checksum; ///< Sum of all 128 bytes should equal 0 mod 256.
///< Extended data.
u8 extension_tag; ///< Always 2 = CEA EDID timing extension.
u8 revision;
u8 dtd_start;
u8 native_dtd_count : 4;
u8 native_dtd_feature_bitmap : 4;
SetSysDataBlock data_block;
SetSysModeLine extended_timing_descriptor[5];
u8 padding[5];
u8 extended_checksum; ///< Sum of 128 extended bytes should equal 0 mod 256.
u8 data2[0x80]; ///< [13.0.0+]
u8 data3[0x80]; ///< [13.0.0+]
SetSysExtensionBlock data1;
SetSysExtensionBlock data2; ///< [13.0.0+]
SetSysExtensionBlock data3; ///< [13.0.0+]
} SetSysEdid;
/// DataDeletionSettings

View File

@ -55,6 +55,8 @@ typedef enum {
} UsbComplexId;
typedef enum {
UsbDeviceSpeed_None = 0x0,
UsbDeviceSpeed_Low = 0x1, ///< USB 1.0 Low Speed
UsbDeviceSpeed_Full = 0x2, ///< USB 1.1 Full Speed
UsbDeviceSpeed_High = 0x3, ///< USB 2.0 High Speed
UsbDeviceSpeed_Super = 0x4, ///< USB 3.0 Super Speed
@ -119,6 +121,9 @@ Result usbDsEnable(void);
/// Only available on [5.0.0+].
Result usbDsDisable(void);
/// Only available on [8.0.0+].
Result usbDsGetSpeed(UsbDeviceSpeed *out);
///@}
///@name IDsInterface
@ -158,4 +163,3 @@ Result usbDsEndpoint_Stall(UsbDsEndpoint* endpoint);
Result usbDsEndpoint_SetZlt(UsbDsEndpoint* endpoint, bool zlt); // Sets Zero Length Termination for endpoint
///@}

View File

@ -7,22 +7,25 @@
#include "services/set.h"
#include "nacp.h"
static u32 g_nacpLanguageTable[15] = {
[SetLanguage_JA] = 2,
[SetLanguage_ENUS] = 0,
[SetLanguage_ENGB] = 1,
[SetLanguage_FR] = 3,
[SetLanguage_DE] = 4,
[SetLanguage_ES419] = 5,
[SetLanguage_ES] = 6,
[SetLanguage_IT] = 7,
[SetLanguage_NL] = 8,
[SetLanguage_FRCA] = 9,
[SetLanguage_PT] = 10,
[SetLanguage_RU] = 11,
[SetLanguage_KO] = 12,
[SetLanguage_ZHTW] = 13,
[SetLanguage_ZHCN] = 14,
static u32 g_nacpLanguageTable[18] = {
[SetLanguage_JA] = 2,
[SetLanguage_ENUS] = 0,
[SetLanguage_ENGB] = 1,
[SetLanguage_FR] = 3,
[SetLanguage_DE] = 4,
[SetLanguage_ES419] = 5,
[SetLanguage_ES] = 6,
[SetLanguage_IT] = 7,
[SetLanguage_NL] = 8,
[SetLanguage_FRCA] = 9,
[SetLanguage_PT] = 10,
[SetLanguage_RU] = 11,
[SetLanguage_KO] = 12,
[SetLanguage_ZHTW] = 13,
[SetLanguage_ZHHANT] = 13,
[SetLanguage_ZHCN] = 14,
[SetLanguage_ZHHANS] = 14,
[SetLanguage_PTBR] = 15
};
//Official sw uses nsam for this, but since that's a privileged service, use set-service instead for compatibility with newer system-versions.
@ -49,7 +52,7 @@ Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry) {
if (Language < 0)
rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
if (R_SUCCEEDED(rc) && Language >= 15)
if (R_SUCCEEDED(rc) && Language >= 18)
Language = SetLanguage_ENUS;//Use ENUS for unsupported system languages.
setExit();

View File

@ -140,6 +140,10 @@ static Result _ldnCmdInU32NoOut(Service* srv, u32 in, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, in);
}
static Result _ldnCmdInU16NoOut(Service* srv, u16 in, u32 cmd_id) {
return serviceDispatchIn(srv, cmd_id, in);
}
static Result _ldnCmdNoInOutU32(Service* srv, u32 *out, u32 cmd_id) {
return serviceDispatchOut(srv, cmd_id, *out);
}
@ -226,6 +230,26 @@ static void _ldnCopyNetworkConfig(const LdnNetworkConfig *in, LdnNetworkConfig *
out->local_communication_version = in->local_communication_version;
}
static s16 _ldnChannelToOldBand(s16 channel) {
if (channel < 15) return 24;
else return 50;
}
static u16 _ldnChannelToChannelBand(s16 channel) {
if (!channel) return channel;
u16 tmp_channel = channel & 0x3FF; // Official sw just masks with u16.
u16 band = 0x3F; // Invalid
if (tmp_channel < 15) band = 2;
else if (tmp_channel >= 32 && tmp_channel < 178) band = 5;
return channel | (band<<10);
}
static s16 _ldnChannelBandToChannel(u16 val) {
return val & 0x3FF;
}
Result ldnGetState(LdnState *out) {
u32 tmp=0;
Result rc = _ldnCmdNoInOutU32(&g_ldnSrv, &tmp, 0);
@ -289,6 +313,13 @@ Result ldnSetWirelessControllerRestriction(LdnWirelessControllerRestriction rest
return _ldnCmdInU32NoOut(&g_ldnSrv, restriction, 104);
}
Result ldnSetProtocol(LdnProtocol protocol) {
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ldnCmdInU32NoOut(&g_ldnSrv, protocol, 106);
}
Result ldnOpenAccessPoint(void) {
return _ldnCmdNoIO(&g_ldnSrv, 200);
}
@ -419,3 +450,132 @@ Result ldnSetOperationMode(LdnOperationMode mode) {
return _ldnCmdInU32NoOut(&g_ldnSrv, mode, 402);
}
Result ldnEnableActionFrame(const LdnActionFrameSettings *settings) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return serviceDispatchIn(&g_ldnSrv, 500, *settings);
}
Result ldnDisableActionFrame(void) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ldnCmdNoIO(&g_ldnSrv, 501);
}
Result ldnSendActionFrame(const void* data, size_t size, LdnMacAddress destination, LdnMacAddress bssid, s16 channel, u32 flags) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
s16 tmp_band = 0, tmp_channel = 0;
if (hosversionBefore(20,0,0)) {
tmp_channel = channel;
tmp_band = _ldnChannelToOldBand(channel);
}
else
tmp_band = _ldnChannelToChannelBand(channel);
const struct {
LdnMacAddress destination;
LdnMacAddress bssid;
s16 band; // These are a single u16 with [20.0.0+].
s16 channel;
u32 flags;
} in = { destination, bssid, tmp_band, tmp_channel, flags};
return serviceDispatchIn(&g_ldnSrv, 502, in,
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_In },
.buffers = { { data, size } },
);
}
Result ldnRecvActionFrame(void* data, size_t size, LdnMacAddress *addr0, LdnMacAddress *addr1, s16 *channel, u32 *out_size, s32 *link_level, u32 flags) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
struct {
LdnMacAddress addr0;
LdnMacAddress addr1;
s16 band; // These are a single u16 with [20.0.0+].
s16 channel;
u32 size;
s32 link_level;
} out;
Result rc = serviceDispatchInOut(&g_ldnSrv, 503, flags, out,
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
.buffers = { { data, size } },
);
if (R_SUCCEEDED(rc)) {
if (addr0) *addr0 = out.addr0;
if (addr1) *addr1 = out.addr1;
if (channel) {
if (hosversionBefore(20,0,0))
*channel = out.channel;
else
*channel = _ldnChannelBandToChannel(out.band);
}
if (out_size) *out_size = out.size;
if (link_level) *link_level = out.link_level;
}
return rc;
}
Result ldnSetHomeChannel(s16 channel) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
s16 tmp_band = 0, tmp_channel = 0;
if (hosversionBefore(20,0,0)) {
tmp_channel = channel;
tmp_band = _ldnChannelToOldBand(channel);
const struct {
s16 band;
s16 channel;
} in = { tmp_band, tmp_channel };
return serviceDispatchIn(&g_ldnSrv, 505, in);
}
else
tmp_band = _ldnChannelToChannelBand(channel);
return _ldnCmdInU16NoOut(&g_ldnSrv, tmp_band, 505);
}
Result ldnSetTxPower(s16 power) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ldnCmdInU16NoOut(&g_ldnSrv, power, 600);
}
Result ldnResetTxPower(void) {
if (!serviceIsActive(&g_ldnSrv) || g_ldnServiceType != LdnServiceType_System)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(18,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _ldnCmdNoIO(&g_ldnSrv, 601);
}

View File

@ -493,7 +493,7 @@ Result nfcMfAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_even
return _nfcCmdInDevhandleOutEvent(&g_nfcMfInterface, handle, out_event, 9);
}
Result nfpGetState(NfpState *out) {
Result nfpGetState(NfcState *out) {
u32 tmp=0;
Result rc = _nfcCmdNoInOutU32(&g_nfpInterface, &tmp, 19);
if (R_SUCCEEDED(rc) && out) *out = tmp;
@ -531,7 +531,7 @@ Result nfcGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out) {
return rc;
}
Result nfcMfGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out) {
Result nfcMfGetDeviceState(const NfcDeviceHandle *handle, NfcMifareDeviceState *out) {
u32 tmp=0;
Result rc = _nfcCmdInDevhandleOutU32(&g_nfcMfInterface, handle, &tmp, 11);
if (R_SUCCEEDED(rc) && out) *out = tmp;
@ -620,7 +620,7 @@ Result nfpFlushDebug(const NfcDeviceHandle *handle) {
return _nfcCmdInDevhandleNoOut(&g_nfcInterface, handle, 202);
}
Result nfpBreakTag(const NfcDeviceHandle *handle, u32 break_type) {
Result nfpBreakTag(const NfcDeviceHandle *handle, NfpBreakType break_type) {
if (g_nfpServiceType != NfpServiceType_Debug)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);

View File

@ -558,6 +558,14 @@ Result usbDsDisable(void) {
return _usbDsCmdNoIO(&g_usbDsSrv, hosversionAtLeast(11,0,0) ? 10 : 11);
}
Result usbDsGetSpeed(UsbDeviceSpeed *out) {
if (hosversionBefore(8,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
_Static_assert(sizeof(*out) == sizeof(u32));
return _usbDsCmdNoInOutU32(&g_usbDsSrv, (u32*)out, hosversionAtLeast(11,0,0) ? 11 : 12);
}
//IDsInterface
@ -729,4 +737,3 @@ Result usbDsEndpoint_SetZlt(UsbDsEndpoint* endpoint, bool zlt) {
return _usbDsCmdInBoolNoOut(&endpoint->s, zlt, 5);
}