1use crate::{
8 AsHandleRef, GPAddr, Handle, HandleBased, HandleRef, MonotonicInstant, Signals, Status,
9 VcpuContents, guest, ok, sys,
10};
11use bitflags::bitflags;
12use std::mem;
13
14#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19#[repr(transparent)]
20pub struct Port(Handle);
21impl_handle_based!(Port);
22
23bitflags! {
24 pub struct PortOptions: u32 {
26 const BIND_TO_INTERRUPT = sys::ZX_PORT_BIND_TO_INTERRUPT;
27 }
28}
29
30#[derive(Debug, Copy, Clone, Eq, PartialEq)]
32pub enum PacketContents {
33 User(UserPacket),
35 SignalOne(SignalPacket),
37 GuestBell(GuestBellPacket),
39 GuestMem(GuestMemPacket),
41 GuestIo(GuestIoPacket),
43 GuestVcpu(GuestVcpuPacket),
45 Pager(PagerPacket),
47 Interrupt(InterruptPacket),
49 PowerTransition(PowerTransitionPacket),
52
53 #[doc(hidden)]
54 __Nonexhaustive,
55}
56
57#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
60pub struct UserPacket(sys::zx_packet_user_t);
61
62#[derive(Copy, Clone, Debug, Eq, PartialEq)]
65pub struct SignalPacket(sys::zx_packet_signal_t);
66
67#[derive(Copy, Clone, Debug, Eq, PartialEq)]
70pub struct GuestBellPacket(sys::zx_packet_guest_bell_t);
71
72#[derive(Copy, Clone, Debug, Eq, PartialEq)]
75pub struct GuestMemPacket(sys::zx_packet_guest_mem_t);
76
77#[derive(Copy, Clone, Debug, Eq, PartialEq)]
80pub struct GuestIoPacket(sys::zx_packet_guest_io_t);
81
82#[derive(Copy, Clone, Debug, Eq, PartialEq)]
85pub struct GuestVcpuPacket(sys::zx_packet_guest_vcpu_t);
86
87#[derive(Copy, Clone, Debug, Eq, PartialEq)]
90pub struct PagerPacket(sys::zx_packet_page_request_t);
91
92#[derive(Copy, Clone, Debug, Eq, PartialEq)]
95pub struct InterruptPacket(sys::zx_packet_interrupt_t);
96
97#[derive(Copy, Clone, Debug, Eq, PartialEq)]
100pub struct PowerTransitionPacket(sys::zx_packet_processor_power_level_transition_request_t);
101
102#[derive(PartialEq, Eq, Debug)]
105pub struct Packet(pub(crate) sys::zx_port_packet_t);
106
107impl Packet {
108 pub fn from_user_packet(key: u64, status: i32, user: UserPacket) -> Packet {
110 Packet(sys::zx_port_packet_t {
111 key: key,
112 packet_type: sys::zx_packet_type_t::ZX_PKT_TYPE_USER,
113 status: status,
114 union: user.0,
115 })
116 }
117
118 pub fn from_guest_mem_packet(key: u64, status: i32, mem: GuestMemPacket) -> Packet {
120 let mut raw = sys::zx_port_packet_t {
121 key,
122 packet_type: sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_MEM,
123 status,
124 union: Default::default(),
125 };
126 let bytes: &[u8; std::mem::size_of::<sys::zx_packet_guest_mem_t>()] =
134 unsafe { mem::transmute(&mem.0) };
135 raw.union[0..std::mem::size_of::<sys::zx_packet_guest_mem_t>()].copy_from_slice(bytes);
136 Packet(raw)
137 }
138
139 pub fn from_guest_io_packet(key: u64, status: i32, io: GuestIoPacket) -> Packet {
141 let mut raw = sys::zx_port_packet_t {
142 key,
143 packet_type: sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_IO,
144 status,
145 union: Default::default(),
146 };
147 let bytes: &[u8; std::mem::size_of::<sys::zx_packet_guest_io_t>()] =
150 unsafe { mem::transmute(&io.0) };
151 raw.union[0..std::mem::size_of::<sys::zx_packet_guest_io_t>()].copy_from_slice(bytes);
152 Packet(raw)
153 }
154
155 pub fn from_guest_vcpu_packet(key: u64, status: i32, vcpu: GuestVcpuPacket) -> Packet {
157 Packet(sys::zx_port_packet_t {
158 key,
159 packet_type: sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_VCPU,
160 status,
161 union: unsafe { mem::transmute_copy(&vcpu.0) },
162 })
163 }
164
165 pub fn from_power_transition_packet(
167 key: u64,
168 status: i32,
169 power_transition_packet: PowerTransitionPacket,
170 ) -> Packet {
171 Packet(sys::zx_port_packet_t {
172 key: key,
173 packet_type:
174 sys::zx_packet_type_t::ZX_PKT_TYPE_PROCESSOR_POWER_LEVEL_TRANSITION_REQUEST,
175 status: status,
176 union: unsafe { mem::transmute_copy(&power_transition_packet.0) },
177 })
178 }
179
180 pub fn key(&self) -> u64 {
182 self.0.key
183 }
184
185 pub fn status(&self) -> i32 {
188 self.0.status
189 }
190
191 pub fn contents(&self) -> PacketContents {
193 match self.0.packet_type {
194 sys::zx_packet_type_t::ZX_PKT_TYPE_USER => {
195 PacketContents::User(UserPacket(self.0.union))
196 }
197
198 sys::zx_packet_type_t::ZX_PKT_TYPE_SIGNAL_ONE => {
199 PacketContents::SignalOne(SignalPacket(unsafe {
200 mem::transmute_copy(&self.0.union)
201 }))
202 }
203
204 sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_BELL => {
205 PacketContents::GuestBell(GuestBellPacket(unsafe {
206 mem::transmute_copy(&self.0.union)
207 }))
208 }
209
210 sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_MEM => {
211 PacketContents::GuestMem(GuestMemPacket(unsafe {
212 mem::transmute_copy(&self.0.union)
213 }))
214 }
215
216 sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_IO => {
217 PacketContents::GuestIo(GuestIoPacket(unsafe {
218 mem::transmute_copy(&self.0.union)
219 }))
220 }
221
222 sys::zx_packet_type_t::ZX_PKT_TYPE_GUEST_VCPU => {
223 PacketContents::GuestVcpu(GuestVcpuPacket(unsafe {
224 mem::transmute_copy(&self.0.union)
225 }))
226 }
227
228 sys::zx_packet_type_t::ZX_PKT_TYPE_PAGE_REQUEST => {
229 PacketContents::Pager(PagerPacket(unsafe { mem::transmute_copy(&self.0.union) }))
230 }
231
232 sys::zx_packet_type_t::ZX_PKT_TYPE_INTERRUPT => {
233 PacketContents::Interrupt(InterruptPacket(unsafe {
234 mem::transmute_copy(&self.0.union)
235 }))
236 }
237
238 sys::zx_packet_type_t::ZX_PKT_TYPE_PROCESSOR_POWER_LEVEL_TRANSITION_REQUEST => {
239 PacketContents::PowerTransition(PowerTransitionPacket(unsafe {
240 mem::transmute_copy(&self.0.union)
241 }))
242 }
243
244 _ => panic!("unexpected packet type"),
245 }
246 }
247}
248
249impl UserPacket {
250 pub fn from_u8_array(val: [u8; 32]) -> UserPacket {
251 UserPacket(val)
252 }
253
254 pub fn as_u8_array(&self) -> &[u8; 32] {
255 &self.0
256 }
257
258 pub fn as_mut_u8_array(&mut self) -> &mut [u8; 32] {
259 &mut self.0
260 }
261}
262
263impl SignalPacket {
264 pub fn trigger(&self) -> Signals {
266 Signals::from_bits_truncate(self.0.trigger)
267 }
268
269 pub fn observed(&self) -> Signals {
271 Signals::from_bits_truncate(self.0.observed)
272 }
273
274 pub fn count(&self) -> u64 {
276 self.0.count
277 }
278
279 pub fn timestamp(&self) -> sys::zx_time_t {
281 self.0.timestamp
282 }
283
284 pub fn raw_packet(&self) -> &sys::zx_packet_signal_t {
286 &self.0
287 }
288}
289
290impl GuestBellPacket {
291 pub fn addr(&self) -> GPAddr {
293 GPAddr(self.0.addr)
294 }
295}
296
297impl GuestMemPacket {
298 pub fn from_raw(mem: sys::zx_packet_guest_mem_t) -> GuestMemPacket {
299 GuestMemPacket(mem)
300 }
301
302 pub fn addr(&self) -> GPAddr {
304 GPAddr(self.0.addr)
305 }
306}
307
308#[cfg(target_arch = "aarch64")]
309impl GuestMemPacket {
310 pub fn access_size(&self) -> Option<guest::MemAccessSize> {
314 match self.0.access_size {
315 1 => Some(guest::MemAccessSize::Bits8),
316 2 => Some(guest::MemAccessSize::Bits16),
317 4 => Some(guest::MemAccessSize::Bits32),
318 8 => Some(guest::MemAccessSize::Bits64),
319 _ => None,
320 }
321 }
322
323 pub fn sign_extend(&self) -> bool {
325 self.0.sign_extend
326 }
327
328 pub fn reg(&self) -> u8 {
330 self.0.xt
331 }
332
333 pub fn data(&self) -> Option<guest::MemData> {
335 if let guest::AccessType::Write = self.access_type() {
336 self.access_size().map(|size| match size {
337 guest::MemAccessSize::Bits8 => guest::MemData::Data8(self.0.data as u8),
338 guest::MemAccessSize::Bits16 => guest::MemData::Data16(self.0.data as u16),
339 guest::MemAccessSize::Bits32 => guest::MemData::Data32(self.0.data as u32),
340 guest::MemAccessSize::Bits64 => guest::MemData::Data64(self.0.data),
341 })
342 } else {
343 None
344 }
345 }
346
347 pub fn access_type(&self) -> guest::AccessType {
349 match self.0.read {
350 true => guest::AccessType::Read,
351 false => guest::AccessType::Write,
352 }
353 }
354}
355
356#[cfg(target_arch = "x86_64")]
357impl GuestMemPacket {
358 pub fn default_operand_size(&self) -> Option<guest::CSDefaultOperandSize> {
362 match self.0.default_operand_size {
364 2 => Some(guest::CSDefaultOperandSize::Bits16),
365 4 => Some(guest::CSDefaultOperandSize::Bits32),
366 _ => None,
367 }
368 }
369}
370
371impl GuestIoPacket {
372 pub fn from_raw(io: sys::zx_packet_guest_io_t) -> GuestIoPacket {
373 GuestIoPacket(io)
374 }
375
376 pub fn port(&self) -> u16 {
378 self.0.port
379 }
380
381 pub fn access_size(&self) -> Option<guest::PortAccessSize> {
385 match self.0.access_size {
386 1 => Some(guest::PortAccessSize::Bits8),
387 2 => Some(guest::PortAccessSize::Bits16),
388 4 => Some(guest::PortAccessSize::Bits32),
389 _ => None,
390 }
391 }
392
393 pub fn access_type(&self) -> guest::AccessType {
395 match self.0.input {
396 true => guest::AccessType::Read,
397 false => guest::AccessType::Write,
398 }
399 }
400
401 pub fn data(&self) -> Option<guest::PortData> {
403 #[repr(C)]
404 union DataUnion {
405 bit8: [u8; 4],
406 bit16: [u16; 2],
407 bit32: [u32; 1],
408 }
409 if let guest::AccessType::Write = self.access_type() {
410 unsafe {
411 let data = &DataUnion { bit8: self.0.data };
412 self.access_size().map(|size| match size {
413 guest::PortAccessSize::Bits8 => guest::PortData::Data8(data.bit8[0]),
414 guest::PortAccessSize::Bits16 => guest::PortData::Data16(data.bit16[0]),
415 guest::PortAccessSize::Bits32 => guest::PortData::Data32(data.bit32[0]),
416 })
417 }
418 } else {
419 None
420 }
421 }
422}
423
424impl GuestVcpuPacket {
425 pub fn from_raw(vcpu: sys::zx_packet_guest_vcpu_t) -> GuestVcpuPacket {
426 GuestVcpuPacket(vcpu)
427 }
428
429 pub fn contents(&self) -> VcpuContents {
430 match self.0.r#type {
431 sys::zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT => unsafe {
432 VcpuContents::Interrupt {
433 mask: self.0.union.interrupt.mask,
434 vector: self.0.union.interrupt.vector,
435 }
436 },
437 sys::zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP => unsafe {
438 VcpuContents::Startup {
439 id: self.0.union.startup.id,
440 entry: self.0.union.startup.entry,
441 }
442 },
443 _ => panic!("unexpected VCPU packet type"),
444 }
445 }
446}
447
448impl PagerPacket {
449 pub fn command(&self) -> sys::zx_page_request_command_t {
451 self.0.command
452 }
453
454 pub fn range(&self) -> std::ops::Range<u64> {
456 self.0.offset..self.0.offset + self.0.length
457 }
458}
459
460impl InterruptPacket {
461 pub fn timestamp(&self) -> sys::zx_time_t {
462 self.0.timestamp
463 }
464}
465
466impl PowerTransitionPacket {
467 pub fn from_raw(
468 packet: sys::zx_packet_processor_power_level_transition_request_t,
469 ) -> PowerTransitionPacket {
470 PowerTransitionPacket(packet)
471 }
472
473 pub fn domain_id(&self) -> u32 {
474 self.0.domain_id
475 }
476
477 pub fn options(&self) -> u32 {
478 self.0.options
479 }
480
481 pub fn control_interface(&self) -> u64 {
482 self.0.control_interface
483 }
484
485 pub fn control_argument(&self) -> u64 {
486 self.0.control_argument
487 }
488}
489
490impl Port {
491 pub fn create() -> Self {
502 Self::create_with_opts(PortOptions::from_bits_truncate(0))
503 }
504
505 pub fn create_with_opts(opts: PortOptions) -> Self {
506 unsafe {
507 let mut handle = 0;
508 let status = sys::zx_port_create(opts.bits(), &mut handle);
509 ok(status).expect(
510 "port creation always succeeds except with OOM or when job policy denies it",
511 );
512 Handle::from_raw(handle).into()
513 }
514 }
515
516 pub fn queue(&self, packet: &Packet) -> Result<(), Status> {
522 let status =
523 unsafe { sys::zx_port_queue(self.raw_handle(), std::ptr::from_ref(&packet.0)) };
524 ok(status)
525 }
526
527 pub fn wait(&self, deadline: MonotonicInstant) -> Result<Packet, Status> {
533 let mut packet = Default::default();
534 ok(unsafe { sys::zx_port_wait(self.raw_handle(), deadline.into_nanos(), &mut packet) })?;
535 Ok(Packet(packet))
536 }
537
538 pub fn cancel(&self, key: u64) -> Result<(), Status> {
544 let options = 0;
545 let status = unsafe { sys::zx_port_cancel_key(self.raw_handle(), options, key) };
546 ok(status)
547 }
548}
549
550bitflags! {
551 #[repr(transparent)]
553 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
554 pub struct WaitAsyncOpts: u32 {
555 const TIMESTAMP = sys::ZX_WAIT_ASYNC_TIMESTAMP;
557
558 const BOOT_TIMESTAMP = sys::ZX_WAIT_ASYNC_BOOT_TIMESTAMP;
560
561 const EDGE_TRIGGERED = sys::ZX_WAIT_ASYNC_EDGE;
564 }
565}
566
567#[cfg(test)]
568mod tests {
569 use super::*;
570 use crate::{Duration, Event};
571 use assert_matches::assert_matches;
572
573 #[test]
574 fn port_basic() {
575 let ten_ms = Duration::from_millis(10);
576
577 let port = Port::create();
578
579 assert_eq!(port.wait(MonotonicInstant::after(ten_ms)), Err(Status::TIMED_OUT));
581
582 let packet = Packet::from_user_packet(42, 123, UserPacket::from_u8_array([13; 32]));
584 assert!(port.queue(&packet).is_ok());
585
586 let read_packet = port.wait(MonotonicInstant::after(ten_ms)).unwrap();
588 assert_eq!(read_packet, packet);
589 }
590
591 #[test]
592 fn create_with_opts() {
593 let _port = Port::create_with_opts(PortOptions::BIND_TO_INTERRUPT);
594 }
595
596 #[test]
597 fn wait_async_once() {
598 let ten_ms = Duration::from_millis(10);
599 let key = 42;
600
601 let port = Port::create();
602 let event = Event::create();
603 let no_opts = WaitAsyncOpts::empty();
604
605 assert!(
606 event.wait_async_handle(&port, key, Signals::USER_0 | Signals::USER_1, no_opts).is_ok()
607 );
608
609 assert_eq!(port.wait(MonotonicInstant::after(ten_ms)), Err(Status::TIMED_OUT));
611
612 assert!(event.signal_handle(Signals::NONE, Signals::USER_0).is_ok());
614 let read_packet = port.wait(MonotonicInstant::after(ten_ms)).unwrap();
615 assert_eq!(read_packet.key(), key);
616 assert_eq!(read_packet.status(), 0);
617 match read_packet.contents() {
618 PacketContents::SignalOne(sig) => {
619 assert_eq!(sig.trigger(), Signals::USER_0 | Signals::USER_1);
620 assert_eq!(sig.observed(), Signals::USER_0);
621 assert_eq!(sig.count(), 1);
622 }
623 _ => panic!("wrong packet type"),
624 }
625
626 assert_eq!(port.wait(MonotonicInstant::after(ten_ms)), Err(Status::TIMED_OUT));
628
629 assert!(event.wait_async_handle(&port, key, Signals::USER_0, no_opts).is_ok());
631 let read_packet = port.wait(MonotonicInstant::after(ten_ms)).unwrap();
632 assert_eq!(read_packet.key(), key);
633 assert_eq!(read_packet.status(), 0);
634 match read_packet.contents() {
635 PacketContents::SignalOne(sig) => {
636 assert_eq!(sig.trigger(), Signals::USER_0);
637 assert_eq!(sig.observed(), Signals::USER_0);
638 assert_eq!(sig.count(), 1);
639 }
640 _ => panic!("wrong packet type"),
641 }
642
643 assert!(event.wait_async_handle(&port, key, Signals::USER_0, no_opts).is_ok());
646 assert!(port.cancel(key).is_ok());
647 assert_eq!(port.wait(MonotonicInstant::after(ten_ms)), Err(Status::TIMED_OUT));
648
649 assert!(event.signal_handle(Signals::USER_0, Signals::NONE).is_ok()); assert!(event.wait_async_handle(&port, key, Signals::USER_0, no_opts).is_ok());
652 assert!(port.cancel(key).is_ok());
653 assert!(event.signal_handle(Signals::NONE, Signals::USER_0).is_ok());
654 assert_eq!(port.wait(MonotonicInstant::after(ten_ms)), Err(Status::TIMED_OUT));
655 }
656
657 #[test]
658 fn guest_mem_packet() {
659 #[cfg(target_arch = "x86_64")]
660 let guest_mem_packet = sys::zx_packet_guest_mem_t {
661 addr: 0xaaaabbbbccccdddd,
662 cr3: 0x0123456789abcdef,
663 rip: 0xffffffff00000000,
664 instruction_size: 8,
665 default_operand_size: 2,
666 };
667 #[cfg(target_arch = "aarch64")]
668 let guest_mem_packet = sys::zx_packet_guest_mem_t {
669 addr: 0x8877665544332211,
670 access_size: 8,
671 sign_extend: true,
672 xt: 0xf3,
673 read: false,
674 data: 0x1122334455667788,
675 };
676 #[cfg(target_arch = "riscv64")]
677 let guest_mem_packet = {
678 let mut ret = sys::zx_packet_guest_mem_t::default();
679 ret.addr = 0x8877665544332211;
680 ret
681 };
682 const KEY: u64 = 0x5555555555555555;
683 const STATUS: i32 = sys::ZX_ERR_INTERNAL;
684
685 let packet =
686 Packet::from_guest_mem_packet(KEY, STATUS, GuestMemPacket::from_raw(guest_mem_packet));
687
688 assert_matches!(packet.contents(), PacketContents::GuestMem(GuestMemPacket(packet)) if packet == guest_mem_packet);
689 assert_eq!(packet.key(), KEY);
690 assert_eq!(packet.status(), STATUS);
691 }
692
693 #[test]
694 fn guest_io_packet() {
695 const GUEST_IO_PACKET: sys::zx_packet_guest_io_t = sys::zx_packet_guest_io_t {
696 port: 0xabcd,
697 access_size: 4,
698 input: true,
699 data: [0xaa, 0xbb, 0xcc, 0xdd],
700 };
701 const KEY: u64 = 0x0123456789abcdef;
702 const STATUS: i32 = sys::ZX_ERR_NO_RESOURCES;
703
704 let packet =
705 Packet::from_guest_io_packet(KEY, STATUS, GuestIoPacket::from_raw(GUEST_IO_PACKET));
706
707 assert_matches!(packet.contents(), PacketContents::GuestIo(GuestIoPacket(packet)) if packet == GUEST_IO_PACKET);
708 assert_eq!(packet.key(), KEY);
709 assert_eq!(packet.status(), STATUS);
710 }
711
712 #[test]
713 fn guest_vcpu_interrupt_packet() {
714 let mut guest_vcpu_packet = sys::zx_packet_guest_vcpu_t::default();
716 guest_vcpu_packet.r#type = sys::zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT;
717 guest_vcpu_packet.union = sys::zx_packet_guest_vcpu_union_t {
718 interrupt: {
719 let mut interrupt = sys::zx_packet_guest_vcpu_interrupt_t::default();
720 interrupt.mask = 0xaaaaaaaaaaaaaaaa;
721 interrupt.vector = 0x12;
722 interrupt
723 },
724 };
725 const KEY: u64 = 0x0123456789abcdef;
726 const STATUS: i32 = sys::ZX_ERR_NO_RESOURCES;
727
728 let packet = Packet::from_guest_vcpu_packet(
729 KEY,
730 STATUS,
731 GuestVcpuPacket::from_raw(guest_vcpu_packet),
732 );
733
734 assert_matches!(packet.contents(), PacketContents::GuestVcpu(GuestVcpuPacket(packet)) if packet == guest_vcpu_packet);
735 assert_eq!(packet.key(), KEY);
736 assert_eq!(packet.status(), STATUS);
737 }
738
739 #[test]
740 fn guest_vcpu_startup_packet() {
741 let mut guest_vcpu_packet = sys::zx_packet_guest_vcpu_t::default();
742 guest_vcpu_packet.r#type = sys::zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP;
743 guest_vcpu_packet.union = sys::zx_packet_guest_vcpu_union_t {
744 startup: sys::zx_packet_guest_vcpu_startup_t { id: 16, entry: 0xffffffff11111111 },
745 };
746 const KEY: u64 = 0x0123456789abcdef;
747 const STATUS: i32 = sys::ZX_ERR_NO_RESOURCES;
748
749 let packet = Packet::from_guest_vcpu_packet(
750 KEY,
751 STATUS,
752 GuestVcpuPacket::from_raw(guest_vcpu_packet),
753 );
754
755 assert_matches!(packet.contents(), PacketContents::GuestVcpu(GuestVcpuPacket(packet)) if packet == guest_vcpu_packet);
756 assert_eq!(packet.key(), KEY);
757 assert_eq!(packet.status(), STATUS);
758 }
759
760 #[test]
761 fn power_transition_packet() {
762 let power_transition_packet =
763 sys::zx_packet_processor_power_level_transition_request_t::default();
764 const KEY: u64 = 0x0123456789abcdef;
765 const STATUS: i32 = sys::ZX_ERR_NO_RESOURCES;
766
767 let packet = Packet::from_power_transition_packet(
768 KEY,
769 STATUS,
770 PowerTransitionPacket::from_raw(power_transition_packet),
771 );
772
773 assert_matches!(
774 packet.contents(),
775 PacketContents::PowerTransition(PowerTransitionPacket(packet)) if packet == power_transition_packet
776 );
777 assert_eq!(packet.key(), KEY);
778 assert_eq!(packet.status(), STATUS);
779 }
780}