xref: /aosp_15_r20/external/uwb/src/rust/uwb_core/src/uci/error.rs (revision e0df40009cb5d71e642272d38ba1bb7ffccfce41)
1 // Copyright 2022, 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 use crate::error::{Error, Result};
16 use crate::params::uci_packets::StatusCode;
17 
status_code_to_result(status: StatusCode) -> Result<()>18 pub(crate) fn status_code_to_result(status: StatusCode) -> Result<()> {
19     match status {
20         StatusCode::UciStatusOk => Ok(()),
21         StatusCode::UciStatusMaxSessionsExceeded => Err(Error::MaxSessionsExceeded),
22         StatusCode::UciStatusInvalidParam
23         | StatusCode::UciStatusInvalidRange
24         | StatusCode::UciStatusInvalidMsgSize => Err(Error::BadParameters),
25         StatusCode::UciStatusSessionDuplicate => Err(Error::DuplicatedSessionId),
26         StatusCode::UciStatusFailed
27         | StatusCode::UciStatusSessionNotExist
28         | StatusCode::UciStatusSessionNotConfigured
29         | StatusCode::UciStatusErrorCccSeBusy
30         | StatusCode::UciStatusErrorCccLifecycle => Err(Error::ProtocolSpecific),
31         StatusCode::UciStatusCommandRetry => Err(Error::CommandRetry),
32         StatusCode::UciStatusRegulationUwbOff => Err(Error::RegulationUwbOff),
33         _ => Err(Error::Unknown),
34     }
35 }
36