module.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cctype>
  5. #include <mbedtls/md5.h>
  6. #include "backend/boxcat.h"
  7. #include "common/hex_util.h"
  8. #include "common/logging/log.h"
  9. #include "common/string_util.h"
  10. #include "core/file_sys/vfs.h"
  11. #include "core/hle/ipc_helpers.h"
  12. #include "core/hle/kernel/process.h"
  13. #include "core/hle/kernel/readable_event.h"
  14. #include "core/hle/kernel/writable_event.h"
  15. #include "core/hle/service/bcat/backend/backend.h"
  16. #include "core/hle/service/bcat/bcat.h"
  17. #include "core/hle/service/bcat/module.h"
  18. #include "core/hle/service/filesystem/filesystem.h"
  19. #include "core/settings.h"
  20. namespace Service::BCAT {
  21. constexpr ResultCode ERROR_INVALID_ARGUMENT{ErrorModule::BCAT, 1};
  22. constexpr ResultCode ERROR_FAILED_OPEN_ENTITY{ErrorModule::BCAT, 2};
  23. constexpr ResultCode ERROR_ENTITY_ALREADY_OPEN{ErrorModule::BCAT, 6};
  24. constexpr ResultCode ERROR_NO_OPEN_ENTITY{ErrorModule::BCAT, 7};
  25. // The command to clear the delivery cache just calls fs IFileSystem DeleteFile on all of the files
  26. // and if any of them have a non-zero result it just forwards that result. This is the FS error code
  27. // for permission denied, which is the closest approximation of this scenario.
  28. constexpr ResultCode ERROR_FAILED_CLEAR_CACHE{ErrorModule::FS, 6400};
  29. using BCATDigest = std::array<u8, 0x10>;
  30. namespace {
  31. u64 GetCurrentBuildID() {
  32. const auto& id = Core::System::GetInstance().GetCurrentProcessBuildID();
  33. u64 out{};
  34. std::memcpy(&out, id.data(), sizeof(u64));
  35. return out;
  36. }
  37. // The digest is only used to determine if a file is unique compared to others of the same name.
  38. // Since the algorithm isn't ever checked in game, MD5 is safe.
  39. BCATDigest DigestFile(const FileSys::VirtualFile& file) {
  40. BCATDigest out{};
  41. const auto bytes = file->ReadAllBytes();
  42. mbedtls_md5(bytes.data(), bytes.size(), out.data());
  43. return out;
  44. }
  45. // For a name to be valid it must be non-empty, must have a null terminating character as the final
  46. // char, can only contain numbers, letters, underscores and a hyphen if directory and a period if
  47. // file.
  48. bool VerifyNameValidInternal(Kernel::HLERequestContext& ctx, std::array<char, 0x20> name,
  49. char match_char) {
  50. const auto null_chars = std::count(name.begin(), name.end(), 0);
  51. const auto bad_chars = std::count_if(name.begin(), name.end(), [match_char](char c) {
  52. return !std::isalnum(static_cast<u8>(c)) && c != '_' && c != match_char && c != '\0';
  53. });
  54. if (null_chars == 0x20 || null_chars == 0 || bad_chars != 0 || name[0x1F] != '\0') {
  55. LOG_ERROR(Service_BCAT, "Name passed was invalid!");
  56. IPC::ResponseBuilder rb{ctx, 2};
  57. rb.Push(ERROR_INVALID_ARGUMENT);
  58. return false;
  59. }
  60. return true;
  61. }
  62. bool VerifyNameValidDir(Kernel::HLERequestContext& ctx, DirectoryName name) {
  63. return VerifyNameValidInternal(ctx, name, '-');
  64. }
  65. bool VerifyNameValidFile(Kernel::HLERequestContext& ctx, FileName name) {
  66. return VerifyNameValidInternal(ctx, name, '.');
  67. }
  68. } // Anonymous namespace
  69. struct DeliveryCacheDirectoryEntry {
  70. FileName name;
  71. u64 size;
  72. BCATDigest digest;
  73. };
  74. class IDeliveryCacheProgressService final : public ServiceFramework<IDeliveryCacheProgressService> {
  75. public:
  76. IDeliveryCacheProgressService(Kernel::SharedPtr<Kernel::ReadableEvent> event,
  77. const DeliveryCacheProgressImpl& impl)
  78. : ServiceFramework{"IDeliveryCacheProgressService"}, event(std::move(event)), impl(impl) {
  79. // clang-format off
  80. static const FunctionInfo functions[] = {
  81. {0, &IDeliveryCacheProgressService::GetEvent, "GetEvent"},
  82. {1, &IDeliveryCacheProgressService::GetImpl, "GetImpl"},
  83. };
  84. // clang-format on
  85. RegisterHandlers(functions);
  86. }
  87. private:
  88. void GetEvent(Kernel::HLERequestContext& ctx) {
  89. LOG_DEBUG(Service_BCAT, "called");
  90. IPC::ResponseBuilder rb{ctx, 2, 1};
  91. rb.Push(RESULT_SUCCESS);
  92. rb.PushCopyObjects(event);
  93. }
  94. void GetImpl(Kernel::HLERequestContext& ctx) {
  95. LOG_DEBUG(Service_BCAT, "called");
  96. ctx.WriteBuffer(&impl, sizeof(DeliveryCacheProgressImpl));
  97. IPC::ResponseBuilder rb{ctx, 2};
  98. rb.Push(RESULT_SUCCESS);
  99. }
  100. Kernel::SharedPtr<Kernel::ReadableEvent> event;
  101. const DeliveryCacheProgressImpl& impl;
  102. };
  103. class IBcatService final : public ServiceFramework<IBcatService> {
  104. public:
  105. IBcatService(Backend& backend) : ServiceFramework("IBcatService"), backend(backend) {
  106. // clang-format off
  107. static const FunctionInfo functions[] = {
  108. {10100, &IBcatService::RequestSyncDeliveryCache, "RequestSyncDeliveryCache"},
  109. {10101, &IBcatService::RequestSyncDeliveryCacheWithDirectoryName, "RequestSyncDeliveryCacheWithDirectoryName"},
  110. {10200, nullptr, "CancelSyncDeliveryCacheRequest"},
  111. {20100, nullptr, "RequestSyncDeliveryCacheWithApplicationId"},
  112. {20101, nullptr, "RequestSyncDeliveryCacheWithApplicationIdAndDirectoryName"},
  113. {30100, &IBcatService::SetPassphrase, "SetPassphrase"},
  114. {30200, nullptr, "RegisterBackgroundDeliveryTask"},
  115. {30201, nullptr, "UnregisterBackgroundDeliveryTask"},
  116. {30202, nullptr, "BlockDeliveryTask"},
  117. {30203, nullptr, "UnblockDeliveryTask"},
  118. {90100, nullptr, "EnumerateBackgroundDeliveryTask"},
  119. {90200, nullptr, "GetDeliveryList"},
  120. {90201, &IBcatService::ClearDeliveryCacheStorage, "ClearDeliveryCacheStorage"},
  121. {90300, nullptr, "GetPushNotificationLog"},
  122. };
  123. // clang-format on
  124. RegisterHandlers(functions);
  125. }
  126. private:
  127. enum class SyncType {
  128. Normal,
  129. Directory,
  130. Count,
  131. };
  132. std::shared_ptr<IDeliveryCacheProgressService> CreateProgressService(SyncType type) {
  133. auto& backend{progress.at(static_cast<std::size_t>(type))};
  134. return std::make_shared<IDeliveryCacheProgressService>(backend.GetEvent(),
  135. backend.GetImpl());
  136. }
  137. void RequestSyncDeliveryCache(Kernel::HLERequestContext& ctx) {
  138. LOG_DEBUG(Service_BCAT, "called");
  139. backend.Synchronize({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()},
  140. progress.at(static_cast<std::size_t>(SyncType::Normal)));
  141. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  142. rb.Push(RESULT_SUCCESS);
  143. rb.PushIpcInterface(CreateProgressService(SyncType::Normal));
  144. }
  145. void RequestSyncDeliveryCacheWithDirectoryName(Kernel::HLERequestContext& ctx) {
  146. IPC::RequestParser rp{ctx};
  147. const auto name_raw = rp.PopRaw<DirectoryName>();
  148. const auto name =
  149. Common::StringFromFixedZeroTerminatedBuffer(name_raw.data(), name_raw.size());
  150. LOG_DEBUG(Service_BCAT, "called, name={}", name);
  151. backend.SynchronizeDirectory({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()},
  152. name,
  153. progress.at(static_cast<std::size_t>(SyncType::Directory)));
  154. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  155. rb.Push(RESULT_SUCCESS);
  156. rb.PushIpcInterface(CreateProgressService(SyncType::Directory));
  157. }
  158. void SetPassphrase(Kernel::HLERequestContext& ctx) {
  159. IPC::RequestParser rp{ctx};
  160. const auto title_id = rp.PopRaw<u64>();
  161. const auto passphrase_raw = ctx.ReadBuffer();
  162. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id,
  163. Common::HexToString(passphrase_raw));
  164. if (title_id == 0) {
  165. LOG_ERROR(Service_BCAT, "Invalid title ID!");
  166. IPC::ResponseBuilder rb{ctx, 2};
  167. rb.Push(ERROR_INVALID_ARGUMENT);
  168. }
  169. if (passphrase_raw.size() > 0x40) {
  170. LOG_ERROR(Service_BCAT, "Passphrase too large!");
  171. IPC::ResponseBuilder rb{ctx, 2};
  172. rb.Push(ERROR_INVALID_ARGUMENT);
  173. return;
  174. }
  175. Passphrase passphrase{};
  176. std::memcpy(passphrase.data(), passphrase_raw.data(),
  177. std::min(passphrase.size(), passphrase_raw.size()));
  178. backend.SetPassphrase(title_id, passphrase);
  179. IPC::ResponseBuilder rb{ctx, 2};
  180. rb.Push(RESULT_SUCCESS);
  181. }
  182. void ClearDeliveryCacheStorage(Kernel::HLERequestContext& ctx) {
  183. IPC::RequestParser rp{ctx};
  184. const auto title_id = rp.PopRaw<u64>();
  185. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}", title_id);
  186. if (title_id == 0) {
  187. LOG_ERROR(Service_BCAT, "Invalid title ID!");
  188. IPC::ResponseBuilder rb{ctx, 2};
  189. rb.Push(ERROR_INVALID_ARGUMENT);
  190. return;
  191. }
  192. if (!backend.Clear(title_id)) {
  193. LOG_ERROR(Service_BCAT, "Could not clear the directory successfully!");
  194. IPC::ResponseBuilder rb{ctx, 2};
  195. rb.Push(ERROR_FAILED_CLEAR_CACHE);
  196. return;
  197. }
  198. IPC::ResponseBuilder rb{ctx, 2};
  199. rb.Push(RESULT_SUCCESS);
  200. }
  201. Backend& backend;
  202. std::array<ProgressServiceBackend, static_cast<std::size_t>(SyncType::Count)> progress{
  203. ProgressServiceBackend{"Normal"},
  204. ProgressServiceBackend{"Directory"},
  205. };
  206. };
  207. void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) {
  208. LOG_DEBUG(Service_BCAT, "called");
  209. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  210. rb.Push(RESULT_SUCCESS);
  211. rb.PushIpcInterface<IBcatService>(*backend);
  212. }
  213. class IDeliveryCacheFileService final : public ServiceFramework<IDeliveryCacheFileService> {
  214. public:
  215. IDeliveryCacheFileService(FileSys::VirtualDir root_)
  216. : ServiceFramework{"IDeliveryCacheFileService"}, root(std::move(root_)) {
  217. // clang-format off
  218. static const FunctionInfo functions[] = {
  219. {0, &IDeliveryCacheFileService::Open, "Open"},
  220. {1, &IDeliveryCacheFileService::Read, "Read"},
  221. {2, &IDeliveryCacheFileService::GetSize, "GetSize"},
  222. {3, &IDeliveryCacheFileService::GetDigest, "GetDigest"},
  223. };
  224. // clang-format on
  225. RegisterHandlers(functions);
  226. }
  227. private:
  228. void Open(Kernel::HLERequestContext& ctx) {
  229. IPC::RequestParser rp{ctx};
  230. const auto dir_name_raw = rp.PopRaw<DirectoryName>();
  231. const auto file_name_raw = rp.PopRaw<FileName>();
  232. const auto dir_name =
  233. Common::StringFromFixedZeroTerminatedBuffer(dir_name_raw.data(), dir_name_raw.size());
  234. const auto file_name =
  235. Common::StringFromFixedZeroTerminatedBuffer(file_name_raw.data(), file_name_raw.size());
  236. LOG_DEBUG(Service_BCAT, "called, dir_name={}, file_name={}", dir_name, file_name);
  237. if (!VerifyNameValidDir(ctx, dir_name_raw) || !VerifyNameValidFile(ctx, file_name_raw))
  238. return;
  239. if (current_file != nullptr) {
  240. LOG_ERROR(Service_BCAT, "A file has already been opened on this interface!");
  241. IPC::ResponseBuilder rb{ctx, 2};
  242. rb.Push(ERROR_ENTITY_ALREADY_OPEN);
  243. return;
  244. }
  245. const auto dir = root->GetSubdirectory(dir_name);
  246. if (dir == nullptr) {
  247. LOG_ERROR(Service_BCAT, "The directory of name={} couldn't be opened!", dir_name);
  248. IPC::ResponseBuilder rb{ctx, 2};
  249. rb.Push(ERROR_FAILED_OPEN_ENTITY);
  250. return;
  251. }
  252. current_file = dir->GetFile(file_name);
  253. if (current_file == nullptr) {
  254. LOG_ERROR(Service_BCAT, "The file of name={} couldn't be opened!", file_name);
  255. IPC::ResponseBuilder rb{ctx, 2};
  256. rb.Push(ERROR_FAILED_OPEN_ENTITY);
  257. return;
  258. }
  259. IPC::ResponseBuilder rb{ctx, 2};
  260. rb.Push(RESULT_SUCCESS);
  261. }
  262. void Read(Kernel::HLERequestContext& ctx) {
  263. IPC::RequestParser rp{ctx};
  264. const auto offset{rp.PopRaw<u64>()};
  265. auto size = ctx.GetWriteBufferSize();
  266. LOG_DEBUG(Service_BCAT, "called, offset={:016X}, size={:016X}", offset, size);
  267. if (current_file == nullptr) {
  268. LOG_ERROR(Service_BCAT, "There is no file currently open!");
  269. IPC::ResponseBuilder rb{ctx, 2};
  270. rb.Push(ERROR_NO_OPEN_ENTITY);
  271. }
  272. size = std::min<u64>(current_file->GetSize() - offset, size);
  273. const auto buffer = current_file->ReadBytes(size, offset);
  274. ctx.WriteBuffer(buffer);
  275. IPC::ResponseBuilder rb{ctx, 4};
  276. rb.Push(RESULT_SUCCESS);
  277. rb.Push<u64>(buffer.size());
  278. }
  279. void GetSize(Kernel::HLERequestContext& ctx) {
  280. LOG_DEBUG(Service_BCAT, "called");
  281. if (current_file == nullptr) {
  282. LOG_ERROR(Service_BCAT, "There is no file currently open!");
  283. IPC::ResponseBuilder rb{ctx, 2};
  284. rb.Push(ERROR_NO_OPEN_ENTITY);
  285. }
  286. IPC::ResponseBuilder rb{ctx, 4};
  287. rb.Push(RESULT_SUCCESS);
  288. rb.Push<u64>(current_file->GetSize());
  289. }
  290. void GetDigest(Kernel::HLERequestContext& ctx) {
  291. LOG_DEBUG(Service_BCAT, "called");
  292. if (current_file == nullptr) {
  293. LOG_ERROR(Service_BCAT, "There is no file currently open!");
  294. IPC::ResponseBuilder rb{ctx, 2};
  295. rb.Push(ERROR_NO_OPEN_ENTITY);
  296. }
  297. IPC::ResponseBuilder rb{ctx, 6};
  298. rb.Push(RESULT_SUCCESS);
  299. rb.PushRaw(DigestFile(current_file));
  300. }
  301. FileSys::VirtualDir root;
  302. FileSys::VirtualFile current_file;
  303. };
  304. class IDeliveryCacheDirectoryService final
  305. : public ServiceFramework<IDeliveryCacheDirectoryService> {
  306. public:
  307. IDeliveryCacheDirectoryService(FileSys::VirtualDir root_)
  308. : ServiceFramework{"IDeliveryCacheDirectoryService"}, root(std::move(root_)) {
  309. // clang-format off
  310. static const FunctionInfo functions[] = {
  311. {0, &IDeliveryCacheDirectoryService::Open, "Open"},
  312. {1, &IDeliveryCacheDirectoryService::Read, "Read"},
  313. {2, &IDeliveryCacheDirectoryService::GetCount, "GetCount"},
  314. };
  315. // clang-format on
  316. RegisterHandlers(functions);
  317. }
  318. private:
  319. void Open(Kernel::HLERequestContext& ctx) {
  320. IPC::RequestParser rp{ctx};
  321. const auto name_raw = rp.PopRaw<DirectoryName>();
  322. const auto name =
  323. Common::StringFromFixedZeroTerminatedBuffer(name_raw.data(), name_raw.size());
  324. LOG_DEBUG(Service_BCAT, "called, name={}", name);
  325. if (!VerifyNameValidDir(ctx, name_raw))
  326. return;
  327. if (current_dir != nullptr) {
  328. LOG_ERROR(Service_BCAT, "A file has already been opened on this interface!");
  329. IPC::ResponseBuilder rb{ctx, 2};
  330. rb.Push(ERROR_ENTITY_ALREADY_OPEN);
  331. return;
  332. }
  333. current_dir = root->GetSubdirectory(name);
  334. if (current_dir == nullptr) {
  335. LOG_ERROR(Service_BCAT, "Failed to open the directory name={}!", name);
  336. IPC::ResponseBuilder rb{ctx, 2};
  337. rb.Push(ERROR_FAILED_OPEN_ENTITY);
  338. return;
  339. }
  340. IPC::ResponseBuilder rb{ctx, 2};
  341. rb.Push(RESULT_SUCCESS);
  342. }
  343. void Read(Kernel::HLERequestContext& ctx) {
  344. auto write_size = ctx.GetWriteBufferSize() / sizeof(DeliveryCacheDirectoryEntry);
  345. LOG_DEBUG(Service_BCAT, "called, write_size={:016X}", write_size);
  346. if (current_dir == nullptr) {
  347. LOG_ERROR(Service_BCAT, "There is no open directory!");
  348. IPC::ResponseBuilder rb{ctx, 2};
  349. rb.Push(ERROR_NO_OPEN_ENTITY);
  350. return;
  351. }
  352. const auto files = current_dir->GetFiles();
  353. write_size = std::min<u64>(write_size, files.size());
  354. std::vector<DeliveryCacheDirectoryEntry> entries(write_size);
  355. std::transform(
  356. files.begin(), files.begin() + write_size, entries.begin(), [](const auto& file) {
  357. FileName name{};
  358. std::memcpy(name.data(), file->GetName().data(),
  359. std::min(file->GetName().size(), name.size()));
  360. return DeliveryCacheDirectoryEntry{name, file->GetSize(), DigestFile(file)};
  361. });
  362. ctx.WriteBuffer(entries);
  363. IPC::ResponseBuilder rb{ctx, 3};
  364. rb.Push(RESULT_SUCCESS);
  365. rb.Push<u32>(write_size * sizeof(DeliveryCacheDirectoryEntry));
  366. }
  367. void GetCount(Kernel::HLERequestContext& ctx) {
  368. LOG_DEBUG(Service_BCAT, "called");
  369. if (current_dir == nullptr) {
  370. LOG_ERROR(Service_BCAT, "There is no open directory!");
  371. IPC::ResponseBuilder rb{ctx, 2};
  372. rb.Push(ERROR_NO_OPEN_ENTITY);
  373. return;
  374. }
  375. const auto files = current_dir->GetFiles();
  376. IPC::ResponseBuilder rb{ctx, 3};
  377. rb.Push(RESULT_SUCCESS);
  378. rb.Push<u32>(files.size());
  379. }
  380. FileSys::VirtualDir root;
  381. FileSys::VirtualDir current_dir;
  382. };
  383. class IDeliveryCacheStorageService final : public ServiceFramework<IDeliveryCacheStorageService> {
  384. public:
  385. IDeliveryCacheStorageService(FileSys::VirtualDir root_)
  386. : ServiceFramework{"IDeliveryCacheStorageService"}, root(std::move(root_)) {
  387. // clang-format off
  388. static const FunctionInfo functions[] = {
  389. {0, &IDeliveryCacheStorageService::CreateFileService, "CreateFileService"},
  390. {1, &IDeliveryCacheStorageService::CreateDirectoryService, "CreateDirectoryService"},
  391. {10, &IDeliveryCacheStorageService::EnumerateDeliveryCacheDirectory, "EnumerateDeliveryCacheDirectory"},
  392. };
  393. // clang-format on
  394. RegisterHandlers(functions);
  395. for (const auto& subdir : root->GetSubdirectories()) {
  396. DirectoryName name{};
  397. std::memcpy(name.data(), subdir->GetName().data(),
  398. std::min(sizeof(DirectoryName) - 1, subdir->GetName().size()));
  399. entries.push_back(name);
  400. }
  401. }
  402. private:
  403. void CreateFileService(Kernel::HLERequestContext& ctx) {
  404. LOG_DEBUG(Service_BCAT, "called");
  405. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  406. rb.Push(RESULT_SUCCESS);
  407. rb.PushIpcInterface<IDeliveryCacheFileService>(root);
  408. }
  409. void CreateDirectoryService(Kernel::HLERequestContext& ctx) {
  410. LOG_DEBUG(Service_BCAT, "called");
  411. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  412. rb.Push(RESULT_SUCCESS);
  413. rb.PushIpcInterface<IDeliveryCacheDirectoryService>(root);
  414. }
  415. void EnumerateDeliveryCacheDirectory(Kernel::HLERequestContext& ctx) {
  416. auto size = ctx.GetWriteBufferSize() / sizeof(DirectoryName);
  417. LOG_DEBUG(Service_BCAT, "called, size={:016X}", size);
  418. size = std::min<u64>(size, entries.size() - next_read_index);
  419. ctx.WriteBuffer(entries.data() + next_read_index, size * sizeof(DirectoryName));
  420. next_read_index += size;
  421. IPC::ResponseBuilder rb{ctx, 3};
  422. rb.Push(RESULT_SUCCESS);
  423. rb.Push<u32>(size);
  424. }
  425. FileSys::VirtualDir root;
  426. std::vector<DirectoryName> entries;
  427. u64 next_read_index = 0;
  428. };
  429. void Module::Interface::CreateDeliveryCacheStorageService(Kernel::HLERequestContext& ctx) {
  430. LOG_DEBUG(Service_BCAT, "called");
  431. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  432. rb.Push(RESULT_SUCCESS);
  433. rb.PushIpcInterface<IDeliveryCacheStorageService>(
  434. Service::FileSystem::GetBCATDirectory(Core::CurrentProcess()->GetTitleID()));
  435. }
  436. void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId(
  437. Kernel::HLERequestContext& ctx) {
  438. IPC::RequestParser rp{ctx};
  439. const auto title_id = rp.PopRaw<u64>();
  440. LOG_DEBUG(Service_BCAT, "called, title_id={:016X}", title_id);
  441. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  442. rb.Push(RESULT_SUCCESS);
  443. rb.PushIpcInterface<IDeliveryCacheStorageService>(
  444. Service::FileSystem::GetBCATDirectory(title_id));
  445. }
  446. std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter) {
  447. const auto backend = Settings::values.bcat_backend;
  448. #ifdef YUZU_ENABLE_BOXCAT
  449. if (backend == "boxcat")
  450. return std::make_unique<Boxcat>(std::move(getter));
  451. #endif
  452. return std::make_unique<NullBackend>(std::move(getter));
  453. }
  454. Module::Interface::Interface(std::shared_ptr<Module> module, const char* name)
  455. : ServiceFramework(name), module(std::move(module)),
  456. backend(CreateBackendFromSettings(&Service::FileSystem::GetBCATDirectory)) {}
  457. Module::Interface::~Interface() = default;
  458. void InstallInterfaces(SM::ServiceManager& service_manager) {
  459. auto module = std::make_shared<Module>();
  460. std::make_shared<BCAT>(module, "bcat:a")->InstallAsService(service_manager);
  461. std::make_shared<BCAT>(module, "bcat:m")->InstallAsService(service_manager);
  462. std::make_shared<BCAT>(module, "bcat:u")->InstallAsService(service_manager);
  463. std::make_shared<BCAT>(module, "bcat:s")->InstallAsService(service_manager);
  464. }
  465. } // namespace Service::BCAT