set_sys.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "core/file_sys/errors.h"
  7. #include "core/file_sys/system_archive/system_version.h"
  8. #include "core/hle/ipc_helpers.h"
  9. #include "core/hle/service/filesystem/filesystem.h"
  10. #include "core/hle/service/set/set_sys.h"
  11. namespace Service::Set {
  12. namespace {
  13. constexpr u64 SYSTEM_VERSION_FILE_MINOR_REVISION_OFFSET = 0x05;
  14. enum class GetFirmwareVersionType {
  15. Version1,
  16. Version2,
  17. };
  18. void GetFirmwareVersionImpl(Kernel::HLERequestContext& ctx, GetFirmwareVersionType type) {
  19. LOG_WARNING(Service_SET, "called - Using hardcoded firmware version '{}'",
  20. FileSys::SystemArchive::GetLongDisplayVersion());
  21. ASSERT_MSG(ctx.GetWriteBufferSize() == 0x100,
  22. "FirmwareVersion output buffer must be 0x100 bytes in size!");
  23. // Instead of using the normal procedure of checking for the real system archive and if it
  24. // doesn't exist, synthesizing one, I feel that that would lead to strange bugs because a
  25. // used is using a really old or really new SystemVersion title. The synthesized one ensures
  26. // consistence (currently reports as 5.1.0-0.0)
  27. const auto archive = FileSys::SystemArchive::SystemVersion();
  28. const auto early_exit_failure = [&ctx](std::string_view desc, ResultCode code) {
  29. LOG_ERROR(Service_SET, "General failure while attempting to resolve firmware version ({}).",
  30. desc);
  31. IPC::ResponseBuilder rb{ctx, 2};
  32. rb.Push(code);
  33. };
  34. if (archive == nullptr) {
  35. early_exit_failure("The system version archive couldn't be synthesized.",
  36. FileSys::ERROR_FAILED_MOUNT_ARCHIVE);
  37. return;
  38. }
  39. const auto ver_file = archive->GetFile("file");
  40. if (ver_file == nullptr) {
  41. early_exit_failure("The system version archive didn't contain the file 'file'.",
  42. FileSys::ERROR_INVALID_ARGUMENT);
  43. return;
  44. }
  45. auto data = ver_file->ReadAllBytes();
  46. if (data.size() != 0x100) {
  47. early_exit_failure("The system version file 'file' was not the correct size.",
  48. FileSys::ERROR_OUT_OF_BOUNDS);
  49. return;
  50. }
  51. // If the command is GetFirmwareVersion (as opposed to GetFirmwareVersion2), hardware will
  52. // zero out the REVISION_MINOR field.
  53. if (type == GetFirmwareVersionType::Version1) {
  54. data[SYSTEM_VERSION_FILE_MINOR_REVISION_OFFSET] = 0;
  55. }
  56. ctx.WriteBuffer(data);
  57. IPC::ResponseBuilder rb{ctx, 2};
  58. rb.Push(ResultSuccess);
  59. }
  60. } // Anonymous namespace
  61. void SET_SYS::GetFirmwareVersion(Kernel::HLERequestContext& ctx) {
  62. LOG_DEBUG(Service_SET, "called");
  63. GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version1);
  64. }
  65. void SET_SYS::GetFirmwareVersion2(Kernel::HLERequestContext& ctx) {
  66. LOG_DEBUG(Service_SET, "called");
  67. GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version2);
  68. }
  69. void SET_SYS::GetColorSetId(Kernel::HLERequestContext& ctx) {
  70. LOG_DEBUG(Service_SET, "called");
  71. IPC::ResponseBuilder rb{ctx, 3};
  72. rb.Push(ResultSuccess);
  73. rb.PushEnum(color_set);
  74. }
  75. void SET_SYS::SetColorSetId(Kernel::HLERequestContext& ctx) {
  76. LOG_DEBUG(Service_SET, "called");
  77. IPC::RequestParser rp{ctx};
  78. color_set = rp.PopEnum<ColorSet>();
  79. IPC::ResponseBuilder rb{ctx, 2};
  80. rb.Push(ResultSuccess);
  81. }
  82. SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
  83. // clang-format off
  84. static const FunctionInfo functions[] = {
  85. {0, nullptr, "SetLanguageCode"},
  86. {1, nullptr, "SetNetworkSettings"},
  87. {2, nullptr, "GetNetworkSettings"},
  88. {3, &SET_SYS::GetFirmwareVersion, "GetFirmwareVersion"},
  89. {4, &SET_SYS::GetFirmwareVersion2, "GetFirmwareVersion2"},
  90. {5, nullptr, "GetFirmwareVersionDigest"},
  91. {7, nullptr, "GetLockScreenFlag"},
  92. {8, nullptr, "SetLockScreenFlag"},
  93. {9, nullptr, "GetBacklightSettings"},
  94. {10, nullptr, "SetBacklightSettings"},
  95. {11, nullptr, "SetBluetoothDevicesSettings"},
  96. {12, nullptr, "GetBluetoothDevicesSettings"},
  97. {13, nullptr, "GetExternalSteadyClockSourceId"},
  98. {14, nullptr, "SetExternalSteadyClockSourceId"},
  99. {15, nullptr, "GetUserSystemClockContext"},
  100. {16, nullptr, "SetUserSystemClockContext"},
  101. {17, nullptr, "GetAccountSettings"},
  102. {18, nullptr, "SetAccountSettings"},
  103. {19, nullptr, "GetAudioVolume"},
  104. {20, nullptr, "SetAudioVolume"},
  105. {21, nullptr, "GetEulaVersions"},
  106. {22, nullptr, "SetEulaVersions"},
  107. {23, &SET_SYS::GetColorSetId, "GetColorSetId"},
  108. {24, &SET_SYS::SetColorSetId, "SetColorSetId"},
  109. {25, nullptr, "GetConsoleInformationUploadFlag"},
  110. {26, nullptr, "SetConsoleInformationUploadFlag"},
  111. {27, nullptr, "GetAutomaticApplicationDownloadFlag"},
  112. {28, nullptr, "SetAutomaticApplicationDownloadFlag"},
  113. {29, nullptr, "GetNotificationSettings"},
  114. {30, nullptr, "SetNotificationSettings"},
  115. {31, nullptr, "GetAccountNotificationSettings"},
  116. {32, nullptr, "SetAccountNotificationSettings"},
  117. {35, nullptr, "GetVibrationMasterVolume"},
  118. {36, nullptr, "SetVibrationMasterVolume"},
  119. {37, nullptr, "GetSettingsItemValueSize"},
  120. {38, nullptr, "GetSettingsItemValue"},
  121. {39, nullptr, "GetTvSettings"},
  122. {40, nullptr, "SetTvSettings"},
  123. {41, nullptr, "GetEdid"},
  124. {42, nullptr, "SetEdid"},
  125. {43, nullptr, "GetAudioOutputMode"},
  126. {44, nullptr, "SetAudioOutputMode"},
  127. {45, nullptr, "IsForceMuteOnHeadphoneRemoved"},
  128. {46, nullptr, "SetForceMuteOnHeadphoneRemoved"},
  129. {47, nullptr, "GetQuestFlag"},
  130. {48, nullptr, "SetQuestFlag"},
  131. {49, nullptr, "GetDataDeletionSettings"},
  132. {50, nullptr, "SetDataDeletionSettings"},
  133. {51, nullptr, "GetInitialSystemAppletProgramId"},
  134. {52, nullptr, "GetOverlayDispProgramId"},
  135. {53, nullptr, "GetDeviceTimeZoneLocationName"},
  136. {54, nullptr, "SetDeviceTimeZoneLocationName"},
  137. {55, nullptr, "GetWirelessCertificationFileSize"},
  138. {56, nullptr, "GetWirelessCertificationFile"},
  139. {57, nullptr, "SetRegionCode"},
  140. {58, nullptr, "GetNetworkSystemClockContext"},
  141. {59, nullptr, "SetNetworkSystemClockContext"},
  142. {60, nullptr, "IsUserSystemClockAutomaticCorrectionEnabled"},
  143. {61, nullptr, "SetUserSystemClockAutomaticCorrectionEnabled"},
  144. {62, nullptr, "GetDebugModeFlag"},
  145. {63, nullptr, "GetPrimaryAlbumStorage"},
  146. {64, nullptr, "SetPrimaryAlbumStorage"},
  147. {65, nullptr, "GetUsb30EnableFlag"},
  148. {66, nullptr, "SetUsb30EnableFlag"},
  149. {67, nullptr, "GetBatteryLot"},
  150. {68, nullptr, "GetSerialNumber"},
  151. {69, nullptr, "GetNfcEnableFlag"},
  152. {70, nullptr, "SetNfcEnableFlag"},
  153. {71, nullptr, "GetSleepSettings"},
  154. {72, nullptr, "SetSleepSettings"},
  155. {73, nullptr, "GetWirelessLanEnableFlag"},
  156. {74, nullptr, "SetWirelessLanEnableFlag"},
  157. {75, nullptr, "GetInitialLaunchSettings"},
  158. {76, nullptr, "SetInitialLaunchSettings"},
  159. {77, nullptr, "GetDeviceNickName"},
  160. {78, nullptr, "SetDeviceNickName"},
  161. {79, nullptr, "GetProductModel"},
  162. {80, nullptr, "GetLdnChannel"},
  163. {81, nullptr, "SetLdnChannel"},
  164. {82, nullptr, "AcquireTelemetryDirtyFlagEventHandle"},
  165. {83, nullptr, "GetTelemetryDirtyFlags"},
  166. {84, nullptr, "GetPtmBatteryLot"},
  167. {85, nullptr, "SetPtmBatteryLot"},
  168. {86, nullptr, "GetPtmFuelGaugeParameter"},
  169. {87, nullptr, "SetPtmFuelGaugeParameter"},
  170. {88, nullptr, "GetBluetoothEnableFlag"},
  171. {89, nullptr, "SetBluetoothEnableFlag"},
  172. {90, nullptr, "GetMiiAuthorId"},
  173. {91, nullptr, "SetShutdownRtcValue"},
  174. {92, nullptr, "GetShutdownRtcValue"},
  175. {93, nullptr, "AcquireFatalDirtyFlagEventHandle"},
  176. {94, nullptr, "GetFatalDirtyFlags"},
  177. {95, nullptr, "GetAutoUpdateEnableFlag"},
  178. {96, nullptr, "SetAutoUpdateEnableFlag"},
  179. {97, nullptr, "GetNxControllerSettings"},
  180. {98, nullptr, "SetNxControllerSettings"},
  181. {99, nullptr, "GetBatteryPercentageFlag"},
  182. {100, nullptr, "SetBatteryPercentageFlag"},
  183. {101, nullptr, "GetExternalRtcResetFlag"},
  184. {102, nullptr, "SetExternalRtcResetFlag"},
  185. {103, nullptr, "GetUsbFullKeyEnableFlag"},
  186. {104, nullptr, "SetUsbFullKeyEnableFlag"},
  187. {105, nullptr, "SetExternalSteadyClockInternalOffset"},
  188. {106, nullptr, "GetExternalSteadyClockInternalOffset"},
  189. {107, nullptr, "GetBacklightSettingsEx"},
  190. {108, nullptr, "SetBacklightSettingsEx"},
  191. {109, nullptr, "GetHeadphoneVolumeWarningCount"},
  192. {110, nullptr, "SetHeadphoneVolumeWarningCount"},
  193. {111, nullptr, "GetBluetoothAfhEnableFlag"},
  194. {112, nullptr, "SetBluetoothAfhEnableFlag"},
  195. {113, nullptr, "GetBluetoothBoostEnableFlag"},
  196. {114, nullptr, "SetBluetoothBoostEnableFlag"},
  197. {115, nullptr, "GetInRepairProcessEnableFlag"},
  198. {116, nullptr, "SetInRepairProcessEnableFlag"},
  199. {117, nullptr, "GetHeadphoneVolumeUpdateFlag"},
  200. {118, nullptr, "SetHeadphoneVolumeUpdateFlag"},
  201. {119, nullptr, "NeedsToUpdateHeadphoneVolume"},
  202. {120, nullptr, "GetPushNotificationActivityModeOnSleep"},
  203. {121, nullptr, "SetPushNotificationActivityModeOnSleep"},
  204. {122, nullptr, "GetServiceDiscoveryControlSettings"},
  205. {123, nullptr, "SetServiceDiscoveryControlSettings"},
  206. {124, nullptr, "GetErrorReportSharePermission"},
  207. {125, nullptr, "SetErrorReportSharePermission"},
  208. {126, nullptr, "GetAppletLaunchFlags"},
  209. {127, nullptr, "SetAppletLaunchFlags"},
  210. {128, nullptr, "GetConsoleSixAxisSensorAccelerationBias"},
  211. {129, nullptr, "SetConsoleSixAxisSensorAccelerationBias"},
  212. {130, nullptr, "GetConsoleSixAxisSensorAngularVelocityBias"},
  213. {131, nullptr, "SetConsoleSixAxisSensorAngularVelocityBias"},
  214. {132, nullptr, "GetConsoleSixAxisSensorAccelerationGain"},
  215. {133, nullptr, "SetConsoleSixAxisSensorAccelerationGain"},
  216. {134, nullptr, "GetConsoleSixAxisSensorAngularVelocityGain"},
  217. {135, nullptr, "SetConsoleSixAxisSensorAngularVelocityGain"},
  218. {136, nullptr, "GetKeyboardLayout"},
  219. {137, nullptr, "SetKeyboardLayout"},
  220. {138, nullptr, "GetWebInspectorFlag"},
  221. {139, nullptr, "GetAllowedSslHosts"},
  222. {140, nullptr, "GetHostFsMountPoint"},
  223. {141, nullptr, "GetRequiresRunRepairTimeReviser"},
  224. {142, nullptr, "SetRequiresRunRepairTimeReviser"},
  225. {143, nullptr, "SetBlePairingSettings"},
  226. {144, nullptr, "GetBlePairingSettings"},
  227. {145, nullptr, "GetConsoleSixAxisSensorAngularVelocityTimeBias"},
  228. {146, nullptr, "SetConsoleSixAxisSensorAngularVelocityTimeBias"},
  229. {147, nullptr, "GetConsoleSixAxisSensorAngularAcceleration"},
  230. {148, nullptr, "SetConsoleSixAxisSensorAngularAcceleration"},
  231. {149, nullptr, "GetRebootlessSystemUpdateVersion"},
  232. {150, nullptr, "GetDeviceTimeZoneLocationUpdatedTime"},
  233. {151, nullptr, "SetDeviceTimeZoneLocationUpdatedTime"},
  234. {152, nullptr, "GetUserSystemClockAutomaticCorrectionUpdatedTime"},
  235. {153, nullptr, "SetUserSystemClockAutomaticCorrectionUpdatedTime"},
  236. {154, nullptr, "GetAccountOnlineStorageSettings"},
  237. {155, nullptr, "SetAccountOnlineStorageSettings"},
  238. {156, nullptr, "GetPctlReadyFlag"},
  239. {157, nullptr, "SetPctlReadyFlag"},
  240. {158, nullptr, "GetAnalogStickUserCalibrationL"},
  241. {159, nullptr, "SetAnalogStickUserCalibrationL"},
  242. {160, nullptr, "GetAnalogStickUserCalibrationR"},
  243. {161, nullptr, "SetAnalogStickUserCalibrationR"},
  244. {162, nullptr, "GetPtmBatteryVersion"},
  245. {163, nullptr, "SetPtmBatteryVersion"},
  246. {164, nullptr, "GetUsb30HostEnableFlag"},
  247. {165, nullptr, "SetUsb30HostEnableFlag"},
  248. {166, nullptr, "GetUsb30DeviceEnableFlag"},
  249. {167, nullptr, "SetUsb30DeviceEnableFlag"},
  250. {168, nullptr, "GetThemeId"},
  251. {169, nullptr, "SetThemeId"},
  252. {170, nullptr, "GetChineseTraditionalInputMethod"},
  253. {171, nullptr, "SetChineseTraditionalInputMethod"},
  254. {172, nullptr, "GetPtmCycleCountReliability"},
  255. {173, nullptr, "SetPtmCycleCountReliability"},
  256. {174, nullptr, "GetHomeMenuScheme"},
  257. {175, nullptr, "GetThemeSettings"},
  258. {176, nullptr, "SetThemeSettings"},
  259. {177, nullptr, "GetThemeKey"},
  260. {178, nullptr, "SetThemeKey"},
  261. {179, nullptr, "GetZoomFlag"},
  262. {180, nullptr, "SetZoomFlag"},
  263. {181, nullptr, "GetT"},
  264. {182, nullptr, "SetT"},
  265. {183, nullptr, "GetPlatformRegion"},
  266. {184, nullptr, "SetPlatformRegion"},
  267. {185, nullptr, "GetHomeMenuSchemeModel"},
  268. {186, nullptr, "GetMemoryUsageRateFlag"},
  269. {187, nullptr, "GetTouchScreenMode"},
  270. {188, nullptr, "SetTouchScreenMode"},
  271. {189, nullptr, "GetButtonConfigSettingsFull"},
  272. {190, nullptr, "SetButtonConfigSettingsFull"},
  273. {191, nullptr, "GetButtonConfigSettingsEmbedded"},
  274. {192, nullptr, "SetButtonConfigSettingsEmbedded"},
  275. {193, nullptr, "GetButtonConfigSettingsLeft"},
  276. {194, nullptr, "SetButtonConfigSettingsLeft"},
  277. {195, nullptr, "GetButtonConfigSettingsRight"},
  278. {196, nullptr, "SetButtonConfigSettingsRight"},
  279. {197, nullptr, "GetButtonConfigRegisteredSettingsEmbedded"},
  280. {198, nullptr, "SetButtonConfigRegisteredSettingsEmbedded"},
  281. {199, nullptr, "GetButtonConfigRegisteredSettings"},
  282. {200, nullptr, "SetButtonConfigRegisteredSettings"},
  283. {201, nullptr, "GetFieldTestingFlag"},
  284. {202, nullptr, "SetFieldTestingFlag"},
  285. {203, nullptr, "GetPanelCrcMode"},
  286. {204, nullptr, "SetPanelCrcMode"},
  287. };
  288. // clang-format on
  289. RegisterHandlers(functions);
  290. }
  291. SET_SYS::~SET_SYS() = default;
  292. } // namespace Service::Set