set_sys.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/assert.h"
  4. #include "common/logging/log.h"
  5. #include "common/settings.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, Result 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. // FIXME: implement support for the real system_settings.ini
  83. template <typename T>
  84. static std::vector<u8> ToBytes(const T& value) {
  85. static_assert(std::is_trivially_copyable_v<T>);
  86. const auto* begin = reinterpret_cast<const u8*>(&value);
  87. const auto* end = begin + sizeof(T);
  88. return std::vector<u8>(begin, end);
  89. }
  90. using Settings =
  91. std::map<std::string, std::map<std::string, std::vector<u8>, std::less<>>, std::less<>>;
  92. static Settings GetSettings() {
  93. Settings ret;
  94. ret["hbloader"]["applet_heap_size"] = ToBytes(u64{0x0});
  95. ret["hbloader"]["applet_heap_reservation_size"] = ToBytes(u64{0x8600000});
  96. return ret;
  97. }
  98. void SET_SYS::GetSettingsItemValueSize(Kernel::HLERequestContext& ctx) {
  99. LOG_DEBUG(Service_SET, "called");
  100. // The category of the setting. This corresponds to the top-level keys of
  101. // system_settings.ini.
  102. const auto setting_category_buf{ctx.ReadBuffer(0)};
  103. const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()};
  104. // The name of the setting. This corresponds to the second-level keys of
  105. // system_settings.ini.
  106. const auto setting_name_buf{ctx.ReadBuffer(1)};
  107. const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()};
  108. auto settings{GetSettings()};
  109. u64 response_size{0};
  110. if (settings.contains(setting_category) && settings[setting_category].contains(setting_name)) {
  111. response_size = settings[setting_category][setting_name].size();
  112. }
  113. IPC::ResponseBuilder rb{ctx, 4};
  114. rb.Push(response_size == 0 ? ResultUnknown : ResultSuccess);
  115. rb.Push(response_size);
  116. }
  117. void SET_SYS::GetSettingsItemValue(Kernel::HLERequestContext& ctx) {
  118. LOG_DEBUG(Service_SET, "called");
  119. // The category of the setting. This corresponds to the top-level keys of
  120. // system_settings.ini.
  121. const auto setting_category_buf{ctx.ReadBuffer(0)};
  122. const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()};
  123. // The name of the setting. This corresponds to the second-level keys of
  124. // system_settings.ini.
  125. const auto setting_name_buf{ctx.ReadBuffer(1)};
  126. const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()};
  127. auto settings{GetSettings()};
  128. Result response{ResultUnknown};
  129. if (settings.contains(setting_category) && settings[setting_category].contains(setting_name)) {
  130. auto setting_value = settings[setting_category][setting_name];
  131. ctx.WriteBuffer(setting_value.data(), setting_value.size());
  132. response = ResultSuccess;
  133. }
  134. IPC::ResponseBuilder rb{ctx, 2};
  135. rb.Push(response);
  136. }
  137. void SET_SYS::GetDeviceNickName(Kernel::HLERequestContext& ctx) {
  138. LOG_DEBUG(Service_SET, "called");
  139. IPC::ResponseBuilder rb{ctx, 2};
  140. rb.Push(ResultSuccess);
  141. ctx.WriteBuffer(::Settings::values.device_name.GetValue());
  142. }
  143. SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
  144. // clang-format off
  145. static const FunctionInfo functions[] = {
  146. {0, nullptr, "SetLanguageCode"},
  147. {1, nullptr, "SetNetworkSettings"},
  148. {2, nullptr, "GetNetworkSettings"},
  149. {3, &SET_SYS::GetFirmwareVersion, "GetFirmwareVersion"},
  150. {4, &SET_SYS::GetFirmwareVersion2, "GetFirmwareVersion2"},
  151. {5, nullptr, "GetFirmwareVersionDigest"},
  152. {7, nullptr, "GetLockScreenFlag"},
  153. {8, nullptr, "SetLockScreenFlag"},
  154. {9, nullptr, "GetBacklightSettings"},
  155. {10, nullptr, "SetBacklightSettings"},
  156. {11, nullptr, "SetBluetoothDevicesSettings"},
  157. {12, nullptr, "GetBluetoothDevicesSettings"},
  158. {13, nullptr, "GetExternalSteadyClockSourceId"},
  159. {14, nullptr, "SetExternalSteadyClockSourceId"},
  160. {15, nullptr, "GetUserSystemClockContext"},
  161. {16, nullptr, "SetUserSystemClockContext"},
  162. {17, nullptr, "GetAccountSettings"},
  163. {18, nullptr, "SetAccountSettings"},
  164. {19, nullptr, "GetAudioVolume"},
  165. {20, nullptr, "SetAudioVolume"},
  166. {21, nullptr, "GetEulaVersions"},
  167. {22, nullptr, "SetEulaVersions"},
  168. {23, &SET_SYS::GetColorSetId, "GetColorSetId"},
  169. {24, &SET_SYS::SetColorSetId, "SetColorSetId"},
  170. {25, nullptr, "GetConsoleInformationUploadFlag"},
  171. {26, nullptr, "SetConsoleInformationUploadFlag"},
  172. {27, nullptr, "GetAutomaticApplicationDownloadFlag"},
  173. {28, nullptr, "SetAutomaticApplicationDownloadFlag"},
  174. {29, nullptr, "GetNotificationSettings"},
  175. {30, nullptr, "SetNotificationSettings"},
  176. {31, nullptr, "GetAccountNotificationSettings"},
  177. {32, nullptr, "SetAccountNotificationSettings"},
  178. {35, nullptr, "GetVibrationMasterVolume"},
  179. {36, nullptr, "SetVibrationMasterVolume"},
  180. {37, &SET_SYS::GetSettingsItemValueSize, "GetSettingsItemValueSize"},
  181. {38, &SET_SYS::GetSettingsItemValue, "GetSettingsItemValue"},
  182. {39, nullptr, "GetTvSettings"},
  183. {40, nullptr, "SetTvSettings"},
  184. {41, nullptr, "GetEdid"},
  185. {42, nullptr, "SetEdid"},
  186. {43, nullptr, "GetAudioOutputMode"},
  187. {44, nullptr, "SetAudioOutputMode"},
  188. {45, nullptr, "IsForceMuteOnHeadphoneRemoved"},
  189. {46, nullptr, "SetForceMuteOnHeadphoneRemoved"},
  190. {47, nullptr, "GetQuestFlag"},
  191. {48, nullptr, "SetQuestFlag"},
  192. {49, nullptr, "GetDataDeletionSettings"},
  193. {50, nullptr, "SetDataDeletionSettings"},
  194. {51, nullptr, "GetInitialSystemAppletProgramId"},
  195. {52, nullptr, "GetOverlayDispProgramId"},
  196. {53, nullptr, "GetDeviceTimeZoneLocationName"},
  197. {54, nullptr, "SetDeviceTimeZoneLocationName"},
  198. {55, nullptr, "GetWirelessCertificationFileSize"},
  199. {56, nullptr, "GetWirelessCertificationFile"},
  200. {57, nullptr, "SetRegionCode"},
  201. {58, nullptr, "GetNetworkSystemClockContext"},
  202. {59, nullptr, "SetNetworkSystemClockContext"},
  203. {60, nullptr, "IsUserSystemClockAutomaticCorrectionEnabled"},
  204. {61, nullptr, "SetUserSystemClockAutomaticCorrectionEnabled"},
  205. {62, nullptr, "GetDebugModeFlag"},
  206. {63, nullptr, "GetPrimaryAlbumStorage"},
  207. {64, nullptr, "SetPrimaryAlbumStorage"},
  208. {65, nullptr, "GetUsb30EnableFlag"},
  209. {66, nullptr, "SetUsb30EnableFlag"},
  210. {67, nullptr, "GetBatteryLot"},
  211. {68, nullptr, "GetSerialNumber"},
  212. {69, nullptr, "GetNfcEnableFlag"},
  213. {70, nullptr, "SetNfcEnableFlag"},
  214. {71, nullptr, "GetSleepSettings"},
  215. {72, nullptr, "SetSleepSettings"},
  216. {73, nullptr, "GetWirelessLanEnableFlag"},
  217. {74, nullptr, "SetWirelessLanEnableFlag"},
  218. {75, nullptr, "GetInitialLaunchSettings"},
  219. {76, nullptr, "SetInitialLaunchSettings"},
  220. {77, &SET_SYS::GetDeviceNickName, "GetDeviceNickName"},
  221. {78, nullptr, "SetDeviceNickName"},
  222. {79, nullptr, "GetProductModel"},
  223. {80, nullptr, "GetLdnChannel"},
  224. {81, nullptr, "SetLdnChannel"},
  225. {82, nullptr, "AcquireTelemetryDirtyFlagEventHandle"},
  226. {83, nullptr, "GetTelemetryDirtyFlags"},
  227. {84, nullptr, "GetPtmBatteryLot"},
  228. {85, nullptr, "SetPtmBatteryLot"},
  229. {86, nullptr, "GetPtmFuelGaugeParameter"},
  230. {87, nullptr, "SetPtmFuelGaugeParameter"},
  231. {88, nullptr, "GetBluetoothEnableFlag"},
  232. {89, nullptr, "SetBluetoothEnableFlag"},
  233. {90, nullptr, "GetMiiAuthorId"},
  234. {91, nullptr, "SetShutdownRtcValue"},
  235. {92, nullptr, "GetShutdownRtcValue"},
  236. {93, nullptr, "AcquireFatalDirtyFlagEventHandle"},
  237. {94, nullptr, "GetFatalDirtyFlags"},
  238. {95, nullptr, "GetAutoUpdateEnableFlag"},
  239. {96, nullptr, "SetAutoUpdateEnableFlag"},
  240. {97, nullptr, "GetNxControllerSettings"},
  241. {98, nullptr, "SetNxControllerSettings"},
  242. {99, nullptr, "GetBatteryPercentageFlag"},
  243. {100, nullptr, "SetBatteryPercentageFlag"},
  244. {101, nullptr, "GetExternalRtcResetFlag"},
  245. {102, nullptr, "SetExternalRtcResetFlag"},
  246. {103, nullptr, "GetUsbFullKeyEnableFlag"},
  247. {104, nullptr, "SetUsbFullKeyEnableFlag"},
  248. {105, nullptr, "SetExternalSteadyClockInternalOffset"},
  249. {106, nullptr, "GetExternalSteadyClockInternalOffset"},
  250. {107, nullptr, "GetBacklightSettingsEx"},
  251. {108, nullptr, "SetBacklightSettingsEx"},
  252. {109, nullptr, "GetHeadphoneVolumeWarningCount"},
  253. {110, nullptr, "SetHeadphoneVolumeWarningCount"},
  254. {111, nullptr, "GetBluetoothAfhEnableFlag"},
  255. {112, nullptr, "SetBluetoothAfhEnableFlag"},
  256. {113, nullptr, "GetBluetoothBoostEnableFlag"},
  257. {114, nullptr, "SetBluetoothBoostEnableFlag"},
  258. {115, nullptr, "GetInRepairProcessEnableFlag"},
  259. {116, nullptr, "SetInRepairProcessEnableFlag"},
  260. {117, nullptr, "GetHeadphoneVolumeUpdateFlag"},
  261. {118, nullptr, "SetHeadphoneVolumeUpdateFlag"},
  262. {119, nullptr, "NeedsToUpdateHeadphoneVolume"},
  263. {120, nullptr, "GetPushNotificationActivityModeOnSleep"},
  264. {121, nullptr, "SetPushNotificationActivityModeOnSleep"},
  265. {122, nullptr, "GetServiceDiscoveryControlSettings"},
  266. {123, nullptr, "SetServiceDiscoveryControlSettings"},
  267. {124, nullptr, "GetErrorReportSharePermission"},
  268. {125, nullptr, "SetErrorReportSharePermission"},
  269. {126, nullptr, "GetAppletLaunchFlags"},
  270. {127, nullptr, "SetAppletLaunchFlags"},
  271. {128, nullptr, "GetConsoleSixAxisSensorAccelerationBias"},
  272. {129, nullptr, "SetConsoleSixAxisSensorAccelerationBias"},
  273. {130, nullptr, "GetConsoleSixAxisSensorAngularVelocityBias"},
  274. {131, nullptr, "SetConsoleSixAxisSensorAngularVelocityBias"},
  275. {132, nullptr, "GetConsoleSixAxisSensorAccelerationGain"},
  276. {133, nullptr, "SetConsoleSixAxisSensorAccelerationGain"},
  277. {134, nullptr, "GetConsoleSixAxisSensorAngularVelocityGain"},
  278. {135, nullptr, "SetConsoleSixAxisSensorAngularVelocityGain"},
  279. {136, nullptr, "GetKeyboardLayout"},
  280. {137, nullptr, "SetKeyboardLayout"},
  281. {138, nullptr, "GetWebInspectorFlag"},
  282. {139, nullptr, "GetAllowedSslHosts"},
  283. {140, nullptr, "GetHostFsMountPoint"},
  284. {141, nullptr, "GetRequiresRunRepairTimeReviser"},
  285. {142, nullptr, "SetRequiresRunRepairTimeReviser"},
  286. {143, nullptr, "SetBlePairingSettings"},
  287. {144, nullptr, "GetBlePairingSettings"},
  288. {145, nullptr, "GetConsoleSixAxisSensorAngularVelocityTimeBias"},
  289. {146, nullptr, "SetConsoleSixAxisSensorAngularVelocityTimeBias"},
  290. {147, nullptr, "GetConsoleSixAxisSensorAngularAcceleration"},
  291. {148, nullptr, "SetConsoleSixAxisSensorAngularAcceleration"},
  292. {149, nullptr, "GetRebootlessSystemUpdateVersion"},
  293. {150, nullptr, "GetDeviceTimeZoneLocationUpdatedTime"},
  294. {151, nullptr, "SetDeviceTimeZoneLocationUpdatedTime"},
  295. {152, nullptr, "GetUserSystemClockAutomaticCorrectionUpdatedTime"},
  296. {153, nullptr, "SetUserSystemClockAutomaticCorrectionUpdatedTime"},
  297. {154, nullptr, "GetAccountOnlineStorageSettings"},
  298. {155, nullptr, "SetAccountOnlineStorageSettings"},
  299. {156, nullptr, "GetPctlReadyFlag"},
  300. {157, nullptr, "SetPctlReadyFlag"},
  301. {158, nullptr, "GetAnalogStickUserCalibrationL"},
  302. {159, nullptr, "SetAnalogStickUserCalibrationL"},
  303. {160, nullptr, "GetAnalogStickUserCalibrationR"},
  304. {161, nullptr, "SetAnalogStickUserCalibrationR"},
  305. {162, nullptr, "GetPtmBatteryVersion"},
  306. {163, nullptr, "SetPtmBatteryVersion"},
  307. {164, nullptr, "GetUsb30HostEnableFlag"},
  308. {165, nullptr, "SetUsb30HostEnableFlag"},
  309. {166, nullptr, "GetUsb30DeviceEnableFlag"},
  310. {167, nullptr, "SetUsb30DeviceEnableFlag"},
  311. {168, nullptr, "GetThemeId"},
  312. {169, nullptr, "SetThemeId"},
  313. {170, nullptr, "GetChineseTraditionalInputMethod"},
  314. {171, nullptr, "SetChineseTraditionalInputMethod"},
  315. {172, nullptr, "GetPtmCycleCountReliability"},
  316. {173, nullptr, "SetPtmCycleCountReliability"},
  317. {174, nullptr, "GetHomeMenuScheme"},
  318. {175, nullptr, "GetThemeSettings"},
  319. {176, nullptr, "SetThemeSettings"},
  320. {177, nullptr, "GetThemeKey"},
  321. {178, nullptr, "SetThemeKey"},
  322. {179, nullptr, "GetZoomFlag"},
  323. {180, nullptr, "SetZoomFlag"},
  324. {181, nullptr, "GetT"},
  325. {182, nullptr, "SetT"},
  326. {183, nullptr, "GetPlatformRegion"},
  327. {184, nullptr, "SetPlatformRegion"},
  328. {185, nullptr, "GetHomeMenuSchemeModel"},
  329. {186, nullptr, "GetMemoryUsageRateFlag"},
  330. {187, nullptr, "GetTouchScreenMode"},
  331. {188, nullptr, "SetTouchScreenMode"},
  332. {189, nullptr, "GetButtonConfigSettingsFull"},
  333. {190, nullptr, "SetButtonConfigSettingsFull"},
  334. {191, nullptr, "GetButtonConfigSettingsEmbedded"},
  335. {192, nullptr, "SetButtonConfigSettingsEmbedded"},
  336. {193, nullptr, "GetButtonConfigSettingsLeft"},
  337. {194, nullptr, "SetButtonConfigSettingsLeft"},
  338. {195, nullptr, "GetButtonConfigSettingsRight"},
  339. {196, nullptr, "SetButtonConfigSettingsRight"},
  340. {197, nullptr, "GetButtonConfigRegisteredSettingsEmbedded"},
  341. {198, nullptr, "SetButtonConfigRegisteredSettingsEmbedded"},
  342. {199, nullptr, "GetButtonConfigRegisteredSettings"},
  343. {200, nullptr, "SetButtonConfigRegisteredSettings"},
  344. {201, nullptr, "GetFieldTestingFlag"},
  345. {202, nullptr, "SetFieldTestingFlag"},
  346. {203, nullptr, "GetPanelCrcMode"},
  347. {204, nullptr, "SetPanelCrcMode"},
  348. {205, nullptr, "GetNxControllerSettingsEx"},
  349. {206, nullptr, "SetNxControllerSettingsEx"},
  350. };
  351. // clang-format on
  352. RegisterHandlers(functions);
  353. }
  354. SET_SYS::~SET_SYS() = default;
  355. } // namespace Service::Set