activity_sdk_device_prepare.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. #include <algorithm>
  2. #include <limits>
  3. #include "../../middleware/bap/activity_message/damage_monitor_auth.h"
  4. #include "../../middleware/bap/activity_message/darkness_zone_auth.h"
  5. #include "../../middleware/bap/activity_message/ghost_link_auth.h"
  6. #include "../../middleware/bap/activity_message/interactable_object_auth.h"
  7. #include "../../middleware/bap/activity_message/map_generator_auth.h"
  8. #include "../../middleware/bap/activity_message/mission_effect_auth.h"
  9. #include "../../middleware/bap/activity_message/music_section_auth.h"
  10. #include "../../middleware/bap/activity_message/scene_events_auth.h"
  11. #include "../../middleware/bap/activity_message/sensor_auth_update.h"
  12. #include "../../middleware/bap/activity_message/squad_objective_auth.h"
  13. #include "../../middleware/bap/activity_message/volume_toggle_auth.h"
  14. #include "../../middleware/content/packages/tables/region_reader.h"
  15. #include "../../state/activity/runtime.h"
  16. #include "activity_sdk_device_internal.h"
  17. namespace sunrise::server::activity::activity_sdk_devices::detail {
  18. namespace auth = middleware::bap::activity_message::scriptable_auth;
  19. namespace format = state::activity_sdk::format;
  20. namespace layouts = state::build_data::scenarios;
  21. namespace sdk = state::activity_sdk;
  22. namespace tables = middleware::content::packages::tables;
  23. static_assert(format::kDeviceSlotType == auth::kType23SlotType);
  24. static_assert(format::kDeviceAuthSchema == auth::kType23Schema);
  25. static_assert(format::kObjectSlotType == auth::kType4SlotType);
  26. static_assert(format::kObjectAuthSchema == auth::kType4Schema);
  27. namespace {
  28. /** @return True when both complete groups have the same key and compressed wire layout. */
  29. [[nodiscard]] bool same_roster_layout(const layouts::RosterGroup& left,
  30. const layouts::RosterGroup& right) noexcept {
  31. if (!layouts::valid_roster_group(left) || !layouts::valid_roster_group(right)
  32. || left.registryKey != right.registryKey || left.slotCount != right.slotCount) {
  33. return false;
  34. }
  35. for (std::size_t index = 0; index < left.slotCount; ++index) {
  36. if (left.slotTypes[index] != right.slotTypes[index]
  37. || left.slotFlags[index] != right.slotFlags[index]
  38. || left.slotIndices[index] != right.slotIndices[index]) {
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. /** Finds the selected Auth slot in one materialized group's compressed order. */
  45. [[nodiscard]] bool selected_slot_offset(const layouts::RosterGroup& group,
  46. const format::Slot& slot,
  47. std::uint16_t& output) noexcept {
  48. output = 0;
  49. if (!layouts::valid_roster_group(group)
  50. || slot.slotIndex > (std::numeric_limits<std::uint16_t>::max)()) {
  51. return false;
  52. }
  53. std::size_t matches = 0;
  54. for (std::size_t index = 0; index < group.slotCount; ++index) {
  55. if (group.slotIndices[index] != slot.slotIndex || group.slotTypes[index] != slot.slotType
  56. || (group.slotFlags[index] & layouts::kSlotAuthFlag) == 0) {
  57. continue;
  58. }
  59. output = static_cast<std::uint16_t>(index);
  60. ++matches;
  61. }
  62. return matches == 1;
  63. }
  64. /** Resolves a materialized occurrence group to at most one canonical roster row. */
  65. [[nodiscard]] Status canonical_target(const sdk::BoundView& view,
  66. const format::Scenario& scenario,
  67. const format::Slot& slot,
  68. const layouts::RosterGroup& generatedGroup,
  69. std::int32_t effectiveRegion,
  70. host::ScriptableTarget& output,
  71. bool& found) noexcept {
  72. output = {};
  73. found = false;
  74. if (view.binding.destination.packageNameLength == 0
  75. || view.binding.destination.packageNameLength
  76. > view.binding.destination.packageName.size()) {
  77. return Status::invalidView;
  78. }
  79. const std::string_view destination(
  80. reinterpret_cast<const char*>(view.binding.destination.packageName.data()),
  81. view.binding.destination.packageNameLength);
  82. layouts::Definition layout{};
  83. if (!state::build_data::find_scenario_layout(destination, layout) || layout.tag != scenario.tag
  84. || layout.rosterGroupCount > layout.rosterGroups.size()
  85. || layout.bubbleGroupCount > layout.bubbleGroups.size()) {
  86. return Status::targetUnavailable;
  87. }
  88. const std::uint32_t activeBubble =
  89. static_cast<std::uint32_t>(effectiveRegion) / tables::kSliceSetIndexFactor;
  90. std::size_t activeMatches = 0;
  91. std::uint16_t selectedTable = 0;
  92. layouts::RosterGroup selectedGroup{};
  93. const auto consider = [&](std::uint16_t tableIndex, bool active) noexcept {
  94. layouts::RosterGroup candidate{};
  95. if (!state::build_data::find_roster_group(tableIndex, candidate)) {
  96. return false;
  97. }
  98. if (!same_roster_layout(generatedGroup, candidate)) {
  99. return true;
  100. }
  101. if (active) {
  102. if (activeMatches == 0) {
  103. activeMatches = 1;
  104. selectedTable = tableIndex;
  105. selectedGroup = candidate;
  106. } else if (tableIndex != selectedTable) {
  107. // The same canonical table may be published in both the always-active and bubble
  108. // lanes. That is one target; only a distinct active table is ambiguous.
  109. activeMatches = 2;
  110. }
  111. }
  112. return true;
  113. };
  114. for (std::size_t index = 0; index < layout.rosterGroupCount; ++index) {
  115. if (!consider(layout.rosterGroups[index], true)) {
  116. return Status::targetUnavailable;
  117. }
  118. }
  119. for (std::size_t index = 0; index < layout.bubbleGroupCount; ++index) {
  120. const bool active =
  121. activeBubble < layouts::kBubbleCapacity
  122. && (layout.bubbleGroupMasks[index] & (std::uint64_t{1} << activeBubble)) != 0;
  123. if (!consider(layout.bubbleGroups[index], active)) {
  124. return Status::targetUnavailable;
  125. }
  126. }
  127. if (activeMatches > 1) {
  128. return Status::ambiguousTarget;
  129. }
  130. if (activeMatches == 0) {
  131. return Status::ready;
  132. }
  133. std::uint16_t slotOffset = 0;
  134. if (!selected_slot_offset(selectedGroup, slot, slotOffset)) {
  135. return Status::invalidSlot;
  136. }
  137. output.objectTag = selectedGroup.objectTag;
  138. output.registryKey = selectedGroup.registryKey;
  139. output.authSchema = slot.authSchema;
  140. output.rosterGroupIndex = selectedTable;
  141. output.rosterSlotOffset = slotOffset;
  142. output.slotIndex = static_cast<std::uint16_t>(slot.slotIndex);
  143. output.slotType = static_cast<std::uint8_t>(slot.slotType);
  144. found = true;
  145. return Status::ready;
  146. }
  147. /** Finishes the exact canonical or state-local route resolved from the bound SDK. */
  148. [[nodiscard]] Status finish_prepared(const sdk::BoundView& view,
  149. const server::bap::ActivityLinkView& link,
  150. PreparedDevice& output) noexcept {
  151. output.activityClientGeneration = link.activityClientGeneration;
  152. output.scenarioRow = view.scenarioRow;
  153. output.effectiveRegion = link.effectiveRegion;
  154. return Status::ready;
  155. }
  156. } // namespace
  157. /** Maps the SDK binding validator to this API's stable refusal surface. */
  158. [[nodiscard]] Status binding_status(const sdk::BoundView& view,
  159. server::bap::ActivityLinkView& link) noexcept {
  160. if (view.catalog == nullptr || sdk::bound_activity(view) == nullptr
  161. || sdk::bound_scenario(view) == nullptr) {
  162. return Status::invalidView;
  163. }
  164. if (!state::activity::binding_matches(view.binding)) {
  165. return Status::staleBinding;
  166. }
  167. (void)server::bap::activity_link_view(view.binding, link);
  168. switch (
  169. sdk::revalidate(view, view.binding, link.matchingLinks, link.activityClientGeneration)) {
  170. case sdk::Status::ready:
  171. return link.effectiveRegion >= 0 ? Status::ready : Status::noActivityLink;
  172. case sdk::Status::missingClient:
  173. case sdk::Status::ambiguousClient:
  174. return Status::noActivityLink;
  175. case sdk::Status::staleSession:
  176. return Status::staleBinding;
  177. case sdk::Status::staleActivityClient:
  178. return Status::staleActivityClient;
  179. case sdk::Status::notReady:
  180. case sdk::Status::missing:
  181. case sdk::Status::wrongSdkBuild:
  182. case sdk::Status::catalogInvalid:
  183. case sdk::Status::wrongActivity:
  184. case sdk::Status::activityJoinNotExact:
  185. case sdk::Status::missingScenarioLink:
  186. return Status::invalidView;
  187. }
  188. return Status::invalidView;
  189. }
  190. /** Resolves one SDK slot through a published canonical group or its exact live occurrence. */
  191. [[nodiscard]] Status
  192. prepare_slot(const sdk::BoundView& view, std::uint32_t slotRow, PreparedDevice& output) noexcept {
  193. output = {};
  194. server::bap::ActivityLinkView link{};
  195. const Status live = binding_status(view, link);
  196. if (live != Status::ready) {
  197. return live;
  198. }
  199. const sdk::Catalog& catalog = *view.catalog;
  200. const format::Scenario* const scenario = sdk::bound_scenario(view);
  201. const auto slots = catalog.slots();
  202. const auto objects = catalog.objects();
  203. const auto occurrences = catalog.occurrences();
  204. const auto states = catalog.states();
  205. const auto bubbles = catalog.bubbles();
  206. if (scenario == nullptr || slotRow >= slots.size()) {
  207. return Status::invalidSlot;
  208. }
  209. const format::Slot& slot = slots[slotRow];
  210. if (slot.objectIndex >= objects.size()
  211. || slot.slotIndex > middleware::bap::activity_message::sensor_auth_update::kMaximumSlotIndex
  212. || slot.slotType > middleware::bap::activity_message::sensor_auth_update::kMaximumSlotType
  213. || slot.authSchema == 0 || slot.authSchema == format::kAbsentIndex) {
  214. return Status::invalidSlot;
  215. }
  216. if ((slot.flags & format::kSlotSchemaJoinExact) == 0) {
  217. return Status::schemaJoinNotExact;
  218. }
  219. const format::Object& object = objects[slot.objectIndex];
  220. if (object.objectTag == 0 || object.objectKey == 0
  221. || !sdk::materialize_roster_group(catalog, object, output.generatedRosterGroup)) {
  222. return Status::invalidSlot;
  223. }
  224. std::uint16_t slotOffset = 0;
  225. if (!selected_slot_offset(output.generatedRosterGroup, slot, slotOffset)) {
  226. return Status::invalidSlot;
  227. }
  228. bool canonical = false;
  229. const Status canonicalStatus = canonical_target(view,
  230. *scenario,
  231. slot,
  232. output.generatedRosterGroup,
  233. link.effectiveRegion,
  234. output.target,
  235. canonical);
  236. if (canonicalStatus != Status::ready) {
  237. output = {};
  238. return canonicalStatus;
  239. }
  240. if (canonical) {
  241. return finish_prepared(view, link, output);
  242. }
  243. const format::Occurrence* selected = nullptr;
  244. std::uint32_t selectedState = format::kAbsentIndex;
  245. for (const format::Occurrence& occurrence : sdk::scenario_occurrences(catalog, *scenario)) {
  246. if (occurrence.scenarioIndex != view.scenarioRow || &occurrence < occurrences.data()
  247. || &occurrence >= occurrences.data() + occurrences.size()) {
  248. return Status::invalidView;
  249. }
  250. if (occurrence.objectIndex != slot.objectIndex) {
  251. continue;
  252. }
  253. if (occurrence.stateIndex >= states.size() || occurrence.bubbleIndex >= bubbles.size()) {
  254. return Status::invalidView;
  255. }
  256. const format::State& candidateState = states[occurrence.stateIndex];
  257. const format::Bubble& candidateBubble = bubbles[occurrence.bubbleIndex];
  258. if (candidateState.scenarioIndex != view.scenarioRow
  259. || candidateBubble.scenarioIndex != view.scenarioRow
  260. || candidateState.bubbleIndex != occurrence.bubbleIndex
  261. || candidateState.stateOrdinal >= tables::kSliceSetIndexFactor
  262. || candidateBubble.bubbleOrdinal >= layouts::kBubbleCapacity) {
  263. return Status::invalidView;
  264. }
  265. const std::uint64_t candidateRegion =
  266. static_cast<std::uint64_t>(candidateState.sliceSetIndex) + candidateState.stateOrdinal;
  267. if (candidateRegion != static_cast<std::uint64_t>(link.effectiveRegion)) {
  268. continue;
  269. }
  270. if (selected == nullptr) {
  271. selected = &occurrence;
  272. selectedState = occurrence.stateIndex;
  273. } else if (occurrence.stateIndex != selectedState) {
  274. return Status::ambiguousTarget;
  275. }
  276. }
  277. if (selected == nullptr) {
  278. return Status::targetUnavailable;
  279. }
  280. if (selected->stateIndex >= states.size() || selected->bubbleIndex >= bubbles.size()
  281. || selected->objectIndex >= objects.size()) {
  282. return Status::invalidView;
  283. }
  284. const format::State& state = states[selected->stateIndex];
  285. const format::Bubble& bubble = bubbles[selected->bubbleIndex];
  286. if (state.scenarioIndex != view.scenarioRow || bubble.scenarioIndex != view.scenarioRow
  287. || state.bubbleIndex != selected->bubbleIndex || object.objectTag == 0
  288. || object.objectKey == 0 || state.stateOrdinal >= tables::kSliceSetIndexFactor
  289. || bubble.bubbleOrdinal >= layouts::kBubbleCapacity) {
  290. return Status::invalidView;
  291. }
  292. output.target.objectTag = output.generatedRosterGroup.objectTag;
  293. output.target.registryKey = output.generatedRosterGroup.registryKey;
  294. output.target.authSchema = slot.authSchema;
  295. output.target.rosterGroupIndex = host::kGeneratedRosterGroupIndex;
  296. output.target.rosterSlotOffset = slotOffset;
  297. output.target.slotIndex = static_cast<std::uint16_t>(slot.slotIndex);
  298. output.target.sdkObjectIndex = selected->objectIndex;
  299. output.target.stateLocalRegion = link.effectiveRegion;
  300. output.target.slotType = static_cast<std::uint8_t>(slot.slotType);
  301. output.target.stateLocalRoster = true;
  302. output.stateRow = selected->stateIndex;
  303. return finish_prepared(view, link, output);
  304. }
  305. /** Resolves the legacy type-23 device facade through the shared typed SDK Auth slot route. */
  306. [[nodiscard]] Status prepare(const sdk::BoundView& view,
  307. std::uint32_t slotRow,
  308. auth::Type23Channel channel,
  309. float value,
  310. PreparedDevice& output) noexcept {
  311. (void)value;
  312. const auto channelIndex = static_cast<std::size_t>(channel);
  313. if (channelIndex >= auth::kType23ChannelCount) {
  314. return Status::invalidChannel;
  315. }
  316. if (view.catalog == nullptr || slotRow >= view.catalog->slots().size()) {
  317. return Status::invalidSlot;
  318. }
  319. const format::Slot& slot = view.catalog->slots()[slotRow];
  320. if (slot.slotType != format::kDeviceSlotType
  321. || slot.componentClass != format::kDeviceComponentClass
  322. || slot.senseSchema != format::kDeviceSenseSchema
  323. || slot.authSchema != format::kDeviceAuthSchema) {
  324. return Status::invalidSlot;
  325. }
  326. return prepare_slot(view, slotRow, output);
  327. }
  328. /**
  329. * Resolves one exact type-31 trigger slot. Type 31 carries no caller value, so unlike the device
  330. * path there is no channel or range to check first.
  331. * @param view Pinned SDK view whose binding is revalidated.
  332. * @param slotRow Catalog row the pulse targets.
  333. * @param output Cleared, then receives the resolved target.
  334. * @return ready only for an exact type-31 slot on a live owned binding.
  335. */
  336. [[nodiscard]] Status prepare_trigger(const sdk::BoundView& view,
  337. std::uint32_t slotRow,
  338. PreparedDevice& output) noexcept {
  339. if (view.catalog == nullptr || slotRow >= view.catalog->slots().size()) {
  340. return Status::invalidSlot;
  341. }
  342. const format::Slot& slot = view.catalog->slots()[slotRow];
  343. if (slot.slotType != auth::kType31SlotType || slot.authSchema != auth::kType31Schema) {
  344. return Status::invalidSlot;
  345. }
  346. return prepare_slot(view, slotRow, output);
  347. }
  348. /** Resolves one package-owned object entry without accepting a caller transform. */
  349. [[nodiscard]] Status prepare_object(const sdk::BoundView& view,
  350. std::uint32_t slotRow,
  351. std::int32_t entryIndex,
  352. PreparedDevice& output) noexcept {
  353. if (view.catalog == nullptr || slotRow >= view.catalog->slots().size() || entryIndex < 0) {
  354. return Status::invalidSlot;
  355. }
  356. const format::Slot& slot = view.catalog->slots()[slotRow];
  357. if (slot.slotType != format::kObjectSlotType
  358. || slot.componentClass != format::kObjectComponentClass
  359. || slot.senseSchema != format::kObjectSenseSchema
  360. || slot.authSchema != format::kObjectAuthSchema) {
  361. return Status::invalidSlot;
  362. }
  363. return prepare_slot(view, slotRow, output);
  364. }
  365. /** Resolves one exact actor channel bridge. */
  366. [[nodiscard]] Status prepare_combatant(const sdk::BoundView& view,
  367. std::uint32_t slotRow,
  368. PreparedDevice& output) noexcept {
  369. if (view.catalog == nullptr || slotRow >= view.catalog->slots().size()) {
  370. return Status::invalidSlot;
  371. }
  372. const format::Slot& slot = view.catalog->slots()[slotRow];
  373. if (slot.slotType != auth::kType2SlotType || slot.componentClass != auth::kType2ComponentClass
  374. || slot.senseSchema != auth::kType2SenseSchema || slot.authSchema != auth::kType2Schema) {
  375. return Status::invalidSlot;
  376. }
  377. return prepare_slot(view, slotRow, output);
  378. }
  379. /** Verifies exact SDK identity and schema-decodes one retained Auth body. */
  380. [[nodiscard]] Status validate_auth(const sdk::BoundView& view,
  381. std::uint32_t slotRow,
  382. std::uint32_t objectTag,
  383. std::uint32_t registryKey,
  384. std::uint32_t authSchema,
  385. std::uint16_t slotIndex,
  386. std::uint8_t slotType,
  387. std::span<const std::byte> body,
  388. std::uint16_t bitCount,
  389. std::span<const std::byte> sdkBuildSha256) noexcept {
  390. if (view.catalog == nullptr || sdkBuildSha256.size() != 32U
  391. || view.catalog->sdk_build_sha256().size() != sdkBuildSha256.size()
  392. || !std::equal(sdkBuildSha256.begin(),
  393. sdkBuildSha256.end(),
  394. view.catalog->sdk_build_sha256().begin())) {
  395. return Status::wrongSdkBuild;
  396. }
  397. const auto slots = view.catalog->slots();
  398. const auto objects = view.catalog->objects();
  399. if (slotRow >= slots.size()) {
  400. return Status::invalidSlot;
  401. }
  402. const format::Slot& slot = slots[slotRow];
  403. if (slot.objectIndex >= objects.size() || objectTag == 0 || registryKey == 0 || authSchema == 0
  404. || slotType > middleware::bap::activity_message::sensor_auth_update::kMaximumSlotType
  405. || slotIndex > middleware::bap::activity_message::sensor_auth_update::kMaximumSlotIndex
  406. || objects[slot.objectIndex].objectTag != objectTag
  407. || objects[slot.objectIndex].objectKey != registryKey || slot.authSchema != authSchema
  408. || slot.slotIndex != slotIndex || slot.slotType != slotType) {
  409. return Status::invalidSlot;
  410. }
  411. if ((slot.flags & format::kSlotSchemaJoinExact) == 0) {
  412. return Status::schemaJoinNotExact;
  413. }
  414. if (body.empty()
  415. || body.size()
  416. > middleware::bap::activity_message::sensor_auth_update::kAuthOverrideByteCapacity
  417. || bitCount > body.size() * 8U || bitCount + 7U < body.size() * 8U) {
  418. return Status::invalidBody;
  419. }
  420. const std::size_t trailingBits = bitCount % 8U;
  421. if (trailingBits != 0) {
  422. const std::uint8_t paddingMask =
  423. static_cast<std::uint8_t>((std::uint16_t{1} << (8U - trailingBits)) - 1U);
  424. if ((std::to_integer<std::uint8_t>(body.back()) & paddingMask) != 0) {
  425. return Status::invalidBody;
  426. }
  427. }
  428. // An occupancy Auth body is exactly 87 bits, which the wire pads to 11 bytes.
  429. constexpr std::size_t kOccupancyAuthBits = 87;
  430. constexpr std::size_t kOccupancyAuthBytes = 11;
  431. // Bodies this tree encodes are admitted by slot identity. Their shape belongs to the encoder.
  432. namespace message = middleware::bap::activity_message;
  433. const auto typed = [&](std::uint32_t type, std::uint32_t componentClass, std::uint32_t schema) {
  434. return slotType == type && slot.componentClass == componentClass && authSchema == schema;
  435. };
  436. const bool typedSdkBody =
  437. typed(auth::kType34SlotType, auth::kType34ComponentClass, auth::kType34Schema)
  438. || typed(message::mission_effect::kSlotType,
  439. message::mission_effect::kComponentClass,
  440. message::mission_effect::kSchema)
  441. || typed(message::music_section::kSlotType,
  442. message::music_section::kComponentClass,
  443. message::music_section::kSchema)
  444. || typed(message::scene_events::kSlotType,
  445. message::scene_events::kComponentClass,
  446. message::scene_events::kSchema)
  447. || typed(message::damage_monitor::kSlotType,
  448. message::damage_monitor::kComponentClass,
  449. message::damage_monitor::kAuthSchema)
  450. || typed(message::darkness_zone::kSlotType,
  451. message::darkness_zone::kComponentClass,
  452. message::darkness_zone::kSchema)
  453. || typed(format::kObjectSlotType,
  454. format::kObjectComponentClass,
  455. message::interactable_object::kSchema)
  456. || typed(message::ghost_link::kSlotType,
  457. message::ghost_link::kComponentClass,
  458. message::ghost_link::kAuthSchema)
  459. || typed(
  460. format::kSquadSlotType, format::kSquadComponentClass, message::squad_objective::kSchema)
  461. || typed(message::map_generator_auth::kSlotType,
  462. message::map_generator_auth::kComponentClass,
  463. message::map_generator_auth::kSchema)
  464. || typed(auth::kType2SlotType, auth::kType2ComponentClass, auth::kType2Schema);
  465. const bool occupancy = slotType == format::kOccupancySlotType
  466. && authSchema == format::kOccupancyAuthSchema
  467. && bitCount == kOccupancyAuthBits && body.size() == kOccupancyAuthBytes;
  468. const bool directive =
  469. slotType == middleware::bap::activity_message::scriptable_auth::kType68SlotType
  470. && authSchema == middleware::bap::activity_message::scriptable_auth::kType68Schema
  471. && middleware::bap::activity_message::scriptable_auth::validate_type68_body(body, bitCount);
  472. const bool engagement =
  473. slotType == middleware::bap::activity_message::scriptable_auth::kType70SlotType
  474. && authSchema == middleware::bap::activity_message::scriptable_auth::kType70Schema
  475. && middleware::bap::activity_message::scriptable_auth::validate_type70_body(body, bitCount);
  476. const bool publicEvent =
  477. slotType == middleware::bap::activity_message::scriptable_auth::kType71SlotType
  478. && authSchema == middleware::bap::activity_message::scriptable_auth::kType71Schema
  479. && middleware::bap::activity_message::scriptable_auth::validate_type71_body(body, bitCount);
  480. const bool performance =
  481. slotType == middleware::bap::activity_message::scriptable_auth::kType42SlotType
  482. && authSchema == middleware::bap::activity_message::scriptable_auth::kType42Schema
  483. && middleware::bap::activity_message::scriptable_auth::validate_type42_body(body, bitCount);
  484. const bool combatant =
  485. slotType == middleware::bap::activity_message::scriptable_auth::kType2SlotType
  486. && authSchema == middleware::bap::activity_message::scriptable_auth::kType2Schema
  487. && middleware::bap::activity_message::scriptable_auth::validate_type2_body(body, bitCount);
  488. auth::Type32VolumeBody volumeBody{};
  489. bool volumeToggle = slotType == auth::kType32SlotType && authSchema == auth::kType32Schema
  490. && slot.componentClass == auth::kType32ComponentClass
  491. && auth::decode_type32_volume(body, bitCount, volumeBody)
  492. && volumeBody.registryKey == registryKey;
  493. if (volumeToggle) {
  494. // Validate the inner reference again at dispatch under the same SDK/owner binding.
  495. const auto matches = std::count_if(slots.begin(), slots.end(), [&](const auto& target) {
  496. return target.objectIndex == slot.objectIndex
  497. && target.slotType == auth::kVolumeSlotType
  498. && target.slotIndex == static_cast<std::uint16_t>(volumeBody.slotIndex);
  499. });
  500. volumeToggle = matches == 1;
  501. }
  502. if (!typedSdkBody && !occupancy && !directive && !engagement && !publicEvent && !performance
  503. && !combatant && !volumeToggle) {
  504. return Status::invalidBody;
  505. }
  506. return Status::ready;
  507. }
  508. } // namespace sunrise::server::activity::activity_sdk_devices::detail