apt.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "common/swap.h"
  7. #include "core/hle/kernel/kernel.h"
  8. namespace Service {
  9. class Interface;
  10. namespace APT {
  11. /// Each APT service can only have up to 2 sessions connected at the same time.
  12. static const u32 MaxAPTSessions = 2;
  13. /// Holds information about the parameters used in Send/Glance/ReceiveParameter
  14. struct MessageParameter {
  15. u32 sender_id = 0;
  16. u32 destination_id = 0;
  17. u32 signal = 0;
  18. Kernel::SharedPtr<Kernel::Object> object = nullptr;
  19. std::vector<u8> buffer;
  20. };
  21. /// Holds information about the parameters used in StartLibraryApplet
  22. struct AppletStartupParameter {
  23. Kernel::SharedPtr<Kernel::Object> object = nullptr;
  24. std::vector<u8> buffer;
  25. };
  26. /// Used by the application to pass information about the current framebuffer to applets.
  27. struct CaptureBufferInfo {
  28. u32_le size;
  29. u8 is_3d;
  30. INSERT_PADDING_BYTES(0x3); // Padding for alignment
  31. u32_le top_screen_left_offset;
  32. u32_le top_screen_right_offset;
  33. u32_le top_screen_format;
  34. u32_le bottom_screen_left_offset;
  35. u32_le bottom_screen_right_offset;
  36. u32_le bottom_screen_format;
  37. };
  38. static_assert(sizeof(CaptureBufferInfo) == 0x20, "CaptureBufferInfo struct has incorrect size");
  39. /// Signals used by APT functions
  40. enum class SignalType : u32 {
  41. None = 0x0,
  42. Wakeup = 0x1,
  43. Request = 0x2,
  44. Response = 0x3,
  45. Exit = 0x4,
  46. Message = 0x5,
  47. HomeButtonSingle = 0x6,
  48. HomeButtonDouble = 0x7,
  49. DspSleep = 0x8,
  50. DspWakeup = 0x9,
  51. WakeupByExit = 0xA,
  52. WakeupByPause = 0xB,
  53. WakeupByCancel = 0xC,
  54. WakeupByCancelAll = 0xD,
  55. WakeupByPowerButtonClick = 0xE,
  56. WakeupToJumpHome = 0xF,
  57. RequestForSysApplet = 0x10,
  58. WakeupToLaunchApplication = 0x11,
  59. };
  60. /// App Id's used by APT functions
  61. enum class AppletId : u32 {
  62. HomeMenu = 0x101,
  63. AlternateMenu = 0x103,
  64. Camera = 0x110,
  65. FriendsList = 0x112,
  66. GameNotes = 0x113,
  67. InternetBrowser = 0x114,
  68. InstructionManual = 0x115,
  69. Notifications = 0x116,
  70. Miiverse = 0x117,
  71. MiiversePost = 0x118,
  72. AmiiboSettings = 0x119,
  73. SoftwareKeyboard1 = 0x201,
  74. Ed1 = 0x202,
  75. PnoteApp = 0x204,
  76. SnoteApp = 0x205,
  77. Error = 0x206,
  78. Mint = 0x207,
  79. Extrapad = 0x208,
  80. Memolib = 0x209,
  81. Application = 0x300,
  82. AnyLibraryApplet = 0x400,
  83. SoftwareKeyboard2 = 0x401,
  84. Ed2 = 0x402,
  85. PnoteApp2 = 0x404,
  86. SnoteApp2 = 0x405,
  87. Error2 = 0x406,
  88. Mint2 = 0x407,
  89. Extrapad2 = 0x408,
  90. Memolib2 = 0x409,
  91. };
  92. enum class StartupArgumentType : u32 {
  93. OtherApp = 0,
  94. Restart = 1,
  95. OtherMedia = 2,
  96. };
  97. enum class ScreencapPostPermission : u32 {
  98. CleanThePermission = 0, // TODO(JamePeng): verify what "zero" means
  99. NoExplicitSetting = 1,
  100. EnableScreenshotPostingToMiiverse = 2,
  101. DisableScreenshotPostingToMiiverse = 3
  102. };
  103. /// Send a parameter to the currently-running application, which will read it via ReceiveParameter
  104. void SendParameter(const MessageParameter& parameter);
  105. /**
  106. * APT::Initialize service function
  107. * Service function that initializes the APT process for the running application
  108. * Outputs:
  109. * 1 : Result of the function, 0 on success, otherwise error code
  110. * 3 : Handle to the notification event
  111. * 4 : Handle to the pause event
  112. */
  113. void Initialize(Service::Interface* self);
  114. /**
  115. * APT::GetSharedFont service function
  116. * Outputs:
  117. * 1 : Result of function, 0 on success, otherwise error code
  118. * 2 : Virtual address of where shared font will be loaded in memory
  119. * 4 : Handle to shared font memory
  120. */
  121. void GetSharedFont(Service::Interface* self);
  122. /**
  123. * APT::NotifyToWait service function
  124. * Inputs:
  125. * 1 : AppID
  126. * Outputs:
  127. * 1 : Result of function, 0 on success, otherwise error code
  128. */
  129. void NotifyToWait(Service::Interface* self);
  130. /**
  131. * APT::GetLockHandle service function
  132. * Inputs:
  133. * 1 : Applet attributes
  134. * Outputs:
  135. * 1 : Result of function, 0 on success, otherwise error code
  136. * 2 : Applet attributes
  137. * 3 : Power button state
  138. * 4 : IPC handle descriptor
  139. * 5 : APT mutex handle
  140. */
  141. void GetLockHandle(Service::Interface* self);
  142. /**
  143. * APT::Enable service function
  144. * Inputs:
  145. * 1 : Applet attributes
  146. * Outputs:
  147. * 1 : Result of function, 0 on success, otherwise error code
  148. */
  149. void Enable(Service::Interface* self);
  150. /**
  151. * APT::GetAppletManInfo service function.
  152. * Inputs:
  153. * 1 : Unknown
  154. * Outputs:
  155. * 1 : Result of function, 0 on success, otherwise error code
  156. * 2 : Unknown u32 value
  157. * 3 : Unknown u8 value
  158. * 4 : Home Menu AppId
  159. * 5 : AppID of currently active app
  160. */
  161. void GetAppletManInfo(Service::Interface* self);
  162. /**
  163. * APT::GetAppletInfo service function.
  164. * Inputs:
  165. * 1 : AppId
  166. * Outputs:
  167. * 1 : Result of function, 0 on success, otherwise error code
  168. * 2-3 : Title ID
  169. * 4 : Media Type
  170. * 5 : Registered
  171. * 6 : Loaded
  172. * 7 : Attributes
  173. */
  174. void GetAppletInfo(Service::Interface* self);
  175. /**
  176. * APT::IsRegistered service function. This returns whether the specified AppID is registered with
  177. * NS yet. An AppID is "registered" once the process associated with the AppID uses APT:Enable. Home
  178. * Menu uses this command to determine when the launched process is running and to determine when to
  179. * stop using GSP, etc., while displaying the "Nintendo 3DS" loading screen.
  180. *
  181. * Inputs:
  182. * 1 : AppID
  183. * Outputs:
  184. * 0 : Return header
  185. * 1 : Result of function, 0 on success, otherwise error code
  186. * 2 : Output, 0 = not registered, 1 = registered.
  187. */
  188. void IsRegistered(Service::Interface* self);
  189. void InquireNotification(Service::Interface* self);
  190. /**
  191. * APT::SendParameter service function. This sets the parameter data state.
  192. * Inputs:
  193. * 1 : Source AppID
  194. * 2 : Destination AppID
  195. * 3 : Signal type
  196. * 4 : Parameter buffer size, max size is 0x1000 (this can be zero)
  197. * 5 : Value
  198. * 6 : Handle to the destination process, likely used for shared memory (this can be zero)
  199. * 7 : (Size<<14) | 2
  200. * 8 : Input parameter buffer ptr
  201. * Outputs:
  202. * 0 : Return Header
  203. * 1 : Result of function, 0 on success, otherwise error code
  204. */
  205. void SendParameter(Service::Interface* self);
  206. /**
  207. * APT::ReceiveParameter service function. This returns the current parameter data from NS state,
  208. * from the source process which set the parameters. Once finished, NS will clear a flag in the NS
  209. * state so that this command will return an error if this command is used again if parameters were
  210. * not set again. This is called when the second Initialize event is triggered. It returns a signal
  211. * type indicating why it was triggered.
  212. * Inputs:
  213. * 1 : AppID
  214. * 2 : Parameter buffer size, max size is 0x1000
  215. * Outputs:
  216. * 1 : Result of function, 0 on success, otherwise error code
  217. * 2 : AppID of the process which sent these parameters
  218. * 3 : Signal type
  219. * 4 : Actual parameter buffer size, this is <= to the the input size
  220. * 5 : Value
  221. * 6 : Handle from the source process which set the parameters, likely used for shared memory
  222. * 7 : Size
  223. * 8 : Output parameter buffer ptr
  224. */
  225. void ReceiveParameter(Service::Interface* self);
  226. /**
  227. * APT::GlanceParameter service function. This is exactly the same as APT_U::ReceiveParameter
  228. * (except for the word value prior to the output handle), except this will not clear the flag
  229. * (except when responseword[3]==8 || responseword[3]==9) in NS state.
  230. * Inputs:
  231. * 1 : AppID
  232. * 2 : Parameter buffer size, max size is 0x1000
  233. * Outputs:
  234. * 1 : Result of function, 0 on success, otherwise error code
  235. * 2 : Unknown, for now assume AppID of the process which sent these parameters
  236. * 3 : Unknown, for now assume Signal type
  237. * 4 : Actual parameter buffer size, this is <= to the the input size
  238. * 5 : Value
  239. * 6 : Handle from the source process which set the parameters, likely used for shared memory
  240. * 7 : Size
  241. * 8 : Output parameter buffer ptr
  242. */
  243. void GlanceParameter(Service::Interface* self);
  244. /**
  245. * APT::CancelParameter service function. When the parameter data is available, and when the above
  246. * specified fields match the ones in NS state(for the ones where the checks are enabled), this
  247. * clears the flag which indicates that parameter data is available
  248. * (same flag cleared by APT:ReceiveParameter).
  249. * Inputs:
  250. * 1 : Flag, when non-zero NS will compare the word after this one with a field in the NS
  251. * state.
  252. * 2 : Unknown, this is the same as the first unknown field returned by APT:ReceiveParameter.
  253. * 3 : Flag, when non-zero NS will compare the word after this one with a field in the NS
  254. * state.
  255. * 4 : AppID
  256. * Outputs:
  257. * 0 : Return header
  258. * 1 : Result of function, 0 on success, otherwise error code
  259. * 2 : Status flag, 0 = failure due to no parameter data being available, or the above enabled
  260. * fields don't match the fields in NS state. 1 = success.
  261. */
  262. void CancelParameter(Service::Interface* self);
  263. /**
  264. * APT::PrepareToStartApplication service function. When the input title-info programID is zero,
  265. * NS will load the actual program ID via AMNet:GetTitleIDList. After doing some checks with the
  266. * programID, NS will then set a NS state flag to value 1, then set the programID for AppID
  267. * 0x300(application) to the input program ID(or the one from GetTitleIDList). A media-type field
  268. * in the NS state is also set to the input media-type value
  269. * (other state fields are set at this point as well). With 8.0.0-18, NS will set an u8 NS state
  270. * field to value 1 when input flags bit8 is set
  271. * Inputs:
  272. * 1-4 : 0x10-byte title-info struct
  273. * 4 : Flags
  274. * Outputs:
  275. * 0 : Return header
  276. * 1 : Result of function, 0 on success, otherwise error code
  277. */
  278. void PrepareToStartApplication(Service::Interface* self);
  279. /**
  280. * APT::StartApplication service function. Buf0 is copied to NS FIRMparams+0x0, then Buf1 is copied
  281. * to the NS FIRMparams+0x480. Then the application is launched.
  282. * Inputs:
  283. * 1 : Buffer 0 size, max size is 0x300
  284. * 2 : Buffer 1 size, max size is 0x20 (this can be zero)
  285. * 3 : u8 flag
  286. * 4 : (Size0<<14) | 2
  287. * 5 : Buffer 0 pointer
  288. * 6 : (Size1<<14) | 0x802
  289. * 7 : Buffer 1 pointer
  290. * Outputs:
  291. * 0 : Return Header
  292. * 1 : Result of function, 0 on success, otherwise error code
  293. */
  294. void StartApplication(Service::Interface* self);
  295. /**
  296. * APT::AppletUtility service function
  297. * Inputs:
  298. * 1 : Unknown, but clearly used for something
  299. * 2 : Buffer 1 size (purpose is unknown)
  300. * 3 : Buffer 2 size (purpose is unknown)
  301. * 5 : Buffer 1 address (purpose is unknown)
  302. * 65 : Buffer 2 address (purpose is unknown)
  303. * Outputs:
  304. * 1 : Result of function, 0 on success, otherwise error code
  305. */
  306. void AppletUtility(Service::Interface* self);
  307. /**
  308. * APT::SetAppCpuTimeLimit service function
  309. * Inputs:
  310. * 1 : Value, must be one
  311. * 2 : Percentage of CPU time from 5 to 80
  312. * Outputs:
  313. * 1 : Result of function, 0 on success, otherwise error code
  314. */
  315. void SetAppCpuTimeLimit(Service::Interface* self);
  316. /**
  317. * APT::GetAppCpuTimeLimit service function
  318. * Inputs:
  319. * 1 : Value, must be one
  320. * Outputs:
  321. * 0 : Return header
  322. * 1 : Result of function, 0 on success, otherwise error code
  323. * 2 : System core CPU time percentage
  324. */
  325. void GetAppCpuTimeLimit(Service::Interface* self);
  326. /**
  327. * APT::PrepareToStartLibraryApplet service function
  328. * Inputs:
  329. * 0 : Command header [0x00180040]
  330. * 1 : Id of the applet to start
  331. * Outputs:
  332. * 0 : Return header
  333. * 1 : Result of function, 0 on success, otherwise error code
  334. */
  335. void PrepareToStartLibraryApplet(Service::Interface* self);
  336. /**
  337. * APT::PreloadLibraryApplet service function
  338. * Inputs:
  339. * 0 : Command header [0x00160040]
  340. * 1 : Id of the applet to start
  341. * Outputs:
  342. * 0 : Return header
  343. * 1 : Result of function, 0 on success, otherwise error code
  344. */
  345. void PreloadLibraryApplet(Service::Interface* self);
  346. /**
  347. * APT::StartLibraryApplet service function
  348. * Inputs:
  349. * 0 : Command header [0x001E0084]
  350. * 1 : Id of the applet to start
  351. * 2 : Buffer size
  352. * 3 : Always 0?
  353. * 4 : Handle passed to the applet
  354. * 5 : (Size << 14) | 2
  355. * 6 : Input buffer virtual address
  356. * Outputs:
  357. * 0 : Return header
  358. * 1 : Result of function, 0 on success, otherwise error code
  359. */
  360. void StartLibraryApplet(Service::Interface* self);
  361. /**
  362. * APT::CancelLibraryApplet service function
  363. * Inputs:
  364. * 0 : Command header [0x003B0040]
  365. * 1 : u8, Application exiting (0 = not exiting, 1 = exiting)
  366. * Outputs:
  367. * 0 : Header code
  368. * 1 : Result code
  369. */
  370. void CancelLibraryApplet(Service::Interface* self);
  371. /**
  372. * APT::GetStartupArgument service function
  373. * Inputs:
  374. * 1 : Parameter Size (capped to 0x300)
  375. * 2 : StartupArgumentType
  376. * 65 : Output buffer for startup argument
  377. * Outputs:
  378. * 0 : Return header
  379. * 1 : Result of function, 0 on success, otherwise error code
  380. * 2 : u8, Exists (0 = does not exist, 1 = exists)
  381. */
  382. void GetStartupArgument(Service::Interface* self);
  383. /**
  384. * APT::SetScreenCapPostPermission service function
  385. * Inputs:
  386. * 0 : Header Code[0x00550040]
  387. * 1 : u8 The screenshot posting permission
  388. * Outputs:
  389. * 1 : Result of function, 0 on success, otherwise error code
  390. */
  391. void SetScreenCapPostPermission(Service::Interface* self);
  392. /**
  393. * APT::GetScreenCapPostPermission service function
  394. * Inputs:
  395. * 0 : Header Code[0x00560000]
  396. * Outputs:
  397. * 1 : Result of function, 0 on success, otherwise error code
  398. * 2 : u8 The screenshot posting permission
  399. */
  400. void GetScreenCapPostPermission(Service::Interface* self);
  401. /**
  402. * APT::CheckNew3DSApp service function
  403. * Outputs:
  404. * 1: Result code, 0 on success, otherwise error code
  405. * 2: u8 output: 0 = Old3DS, 1 = New3DS.
  406. * Note:
  407. * This uses PTMSYSM:CheckNew3DS.
  408. * When a certain NS state field is non-zero, the output value is zero,
  409. * Otherwise the output is from PTMSYSM:CheckNew3DS.
  410. * Normally this NS state field is zero, however this state field is set to 1
  411. * when APT:PrepareToStartApplication is used with flags bit8 is set.
  412. */
  413. void CheckNew3DSApp(Service::Interface* self);
  414. /**
  415. * Wrapper for PTMSYSM:CheckNew3DS
  416. * APT::CheckNew3DS service function
  417. * Outputs:
  418. * 1: Result code, 0 on success, otherwise error code
  419. * 2: u8 output: 0 = Old3DS, 1 = New3DS.
  420. */
  421. void CheckNew3DS(Service::Interface* self);
  422. /// Initialize the APT service
  423. void Init();
  424. /// Shutdown the APT service
  425. void Shutdown();
  426. } // namespace APT
  427. } // namespace Service