apt.h 14 KB

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