1 // Copyright 2023, The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! Vsock setup shared between the host and the service VM. 16 17 const PROTECTED_VM_PORT: u32 = 5679; 18 const NON_PROTECTED_VM_PORT: u32 = 5680; 19 20 /// VM Type. 21 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 22 pub enum VmType { 23 /// Protected VM. 24 ProtectedVm, 25 26 /// NonProtectev VM. 27 NonProtectedVm, 28 } 29 30 impl VmType { 31 /// Returns the port number used for the vsock communication between 32 /// the host and the service VM. port(&self) -> u3233 pub fn port(&self) -> u32 { 34 match self { 35 Self::ProtectedVm => PROTECTED_VM_PORT, 36 Self::NonProtectedVm => NON_PROTECTED_VM_PORT, 37 } 38 } 39 40 /// Returns whether it is a protected VM. is_protected(&self) -> bool41 pub fn is_protected(&self) -> bool { 42 match self { 43 Self::ProtectedVm => true, 44 Self::NonProtectedVm => false, 45 } 46 } 47 } 48