apt.h 14 KB

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