Services

Services

Services are an abstraction of ports and are the commonly used way of inter-process communication outside of the kernel. While handles of regular ports are retrieved from svcConnectToPort, service handles are retrieved through the port srv: (“service manager”).

When a service is registered, svcCreatePort is used without a port-name. This means that the port is inaccessible via the port SVCs outside of sm-module. See below for getting a session handle for sending commands to services.

Processes with PID less than or equal to the number of NATIVE_FIRM built-in modules (fs, sm, pm, pxi, ldr) have access to all services. This value is obtained from svcGetSystemInfo. Other processes are limited to access services listed in their service access control list, as passed to SRVPM:RegisterProcess.

Attempting to use GetServiceHandle with a service that the process has access to when that service isn’t registered will block until it is registered.

Service Manager Port “srv:” #

Command HeaderDescription
0x00010002RegisterClient
0x00020000EnableNotification
0x00030100RegisterService
0x000400C0UnregisterService
0x00050100GetServiceHandle
0x000600C2RegisterPort
0x000700C0UnregisterPort
0x00080100GetPort
0x00090040Subscribe
0x000A0040Unsubscribe
0x000B0000ReceiveNotification
0x000C0080PublishToSubscriber
0x000D0040PublishAndGetSubscriber
0x000E00C0IsServiceRegistered

It appears these “port” commands can be used for transferring arbitrary handles, however GetPort still uses the same service-access-control validation as GetServiceHandle. Despite this fact, it appears that a “port” and a service with the same name can coexist independently.

Service Manager Process-Manager Port/Service “srv:pm” #

Command Header (port), prior to 7.0.0-13Command Header (service), post 7.0.0-13Description
0x040100420x00010042PublishToProcess
0x040200400x00020040PublishToAll
0x040300820x00030082RegisterProcess
0x040400400x00040040UnregisterProcess

Prior to to 7.0.0-13, the commands listed for “srv:” were also accessible under this port with the same command-headers. Starting with 7.0.0-13, the “srv:pm” port was changed to a service. With this change, commandIDs for these commands were changed. “srv:pm” was originally vulnerable, this was fixed with 7.0.0-13, see here. Originally any process could use “srv:pm”, however starting with 7.0.0-13 only the built-in NATIVE_FIRM sysmodules have access to it. The only system title which uses “srv:pm” is the Process Manager.

Notifications #

IDPublished bySubscribed byDescription
0x100Not NeededThis indicates that the recipient must terminate.
0x101PTMNSSignaled on sleep mode entry.
0x102PTMNSSleep Mode related?
0x103PTMNS, CSND, NWM, AC, NIMFired on sleep mode entry (Kernel state is modified by PTM after publishing this)
0x104PTMHIDThis indicates that the system is entering sleep mode. (Kernel state is modified by PTM before publishing this)
0x105PTMNS, DSP, CSND, GSP, CODEC, CAMERA, HID, QTM, MIC, IR, NWM, FRIENDS, AC, CECD, ACT, NDM, NIMThis indicates that the system has exited sleep mode.
0x106PTMNS, MIC, AC, NEWS, CECD, BOSSFired after sleep mode exit.
0x107PTMNWM, CECD, BOSS, NDM, NIM, NEWSUnknown.
0x108PTMGSP, QTMSystem is going to Power Down.
0x109CFGGSPCFG block 0x00050001 has been modified, change LCD brightness/PWM settings
0x10BCFGCAMERA?
0x10CPMA Regular application has started.
0x110-0x11FPMNSSent on application exit. See PM launch flags.
0x179PMPTM, NSAll processes other than PTM and NS have terminated.
0x200NSSignaled just before sleep mode is exited from.
0x202MCUNSPOWER button pressed
0x203MCUNSPOWER button held long
0x204MCUNSHOME button pressed
0x205MCUNSHOME button released
0x206MCU / NWMNWMThe physical Wi-Fi slider state changed
0x207MENUSD card inserted
0x208MENUGame cartridge inserted
0x209NS, MENUSD card removed
0x20ANS, MENUGame cartridge removed
0x20BNS, MENUGame cartridge inserted or removed
0x20CMCUPTMPublished on a fatal hardware condition, when the MCU WDT triggers, ptm throws fatal error F960D407 in receipt of this
0x20DMCUGSPCharger plugged out.
0x20EMCUGSPCharger plugged in.
0x20FMCUPublished by the mcu module when (bitmask & 0x8000) is true (started charging). This bitmask is obtained by reading i2c register 0x10.
0x210MCUPublished by the mcu module when (bitmask & 0x4000) is true (stopped charging). This bitmask is obtained by reading i2c register 0x10.
0x211PTMBattery very low (5%)
0x212PTMBattery low (10%)
0x213NSCODEC, HID, GSP, CAMERA, MIC, NDM, QTM, PTMShell opened.
0x214NSCODEC, HID, GSP, CAMERA, MIC, NDM, QTM, PTM.Shell closed.
0x300ACNDM, MENUSignaled after sleep mode exit and during system boot.
0x301ACFRIENDS, NDMSignaled just before sleep mode is exited from.
0x302NWMNDM, SOCKET, FRIENDS, ACWiFi is turning off, triggered by using the WiFi switch on O3DS models and the toggle in the N3DS HOME menu (maybe disconnecting from any connected networks?)
0x303NWMCECD, NDMWiFi has turned off. (fires shortly after 0x302)
0x304NWMCECD, NDM, SOCKETWiFi was turned on.