• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "wifi_status_util.h"
18 
19 namespace aidl {
20 namespace android {
21 namespace hardware {
22 namespace wifi {
23 
legacyErrorToString(legacy_hal::wifi_error error)24 std::string legacyErrorToString(legacy_hal::wifi_error error) {
25     switch (error) {
26         case legacy_hal::WIFI_SUCCESS:
27             return "SUCCESS";
28         case legacy_hal::WIFI_ERROR_UNINITIALIZED:
29             return "UNINITIALIZED";
30         case legacy_hal::WIFI_ERROR_NOT_AVAILABLE:
31             return "NOT_AVAILABLE";
32         case legacy_hal::WIFI_ERROR_NOT_SUPPORTED:
33             return "NOT_SUPPORTED";
34         case legacy_hal::WIFI_ERROR_INVALID_ARGS:
35             return "INVALID_ARGS";
36         case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID:
37             return "INVALID_REQUEST_ID";
38         case legacy_hal::WIFI_ERROR_TIMED_OUT:
39             return "TIMED_OUT";
40         case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS:
41             return "TOO_MANY_REQUESTS";
42         case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY:
43             return "OUT_OF_MEMORY";
44         case legacy_hal::WIFI_ERROR_BUSY:
45             return "BUSY";
46         case legacy_hal::WIFI_ERROR_UNKNOWN:
47             return "UNKNOWN";
48         default:
49             return "UNKNOWN ERROR";
50     }
51 }
52 
createWifiStatus(WifiStatusCode code,const std::string & description)53 ndk::ScopedAStatus createWifiStatus(WifiStatusCode code, const std::string& description) {
54     return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(static_cast<int32_t>(code),
55                                                                    description.c_str());
56 }
57 
createWifiStatus(WifiStatusCode code)58 ndk::ScopedAStatus createWifiStatus(WifiStatusCode code) {
59     return ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(code));
60 }
61 
createWifiStatusFromLegacyError(legacy_hal::wifi_error error,const std::string & desc)62 ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error,
63                                                    const std::string& desc) {
64     switch (error) {
65         case legacy_hal::WIFI_ERROR_NONE:
66             return ndk::ScopedAStatus::ok();
67 
68         case legacy_hal::WIFI_ERROR_UNINITIALIZED:
69         case legacy_hal::WIFI_ERROR_NOT_AVAILABLE:
70             return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc);
71 
72         case legacy_hal::WIFI_ERROR_NOT_SUPPORTED:
73             return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc);
74 
75         case legacy_hal::WIFI_ERROR_INVALID_ARGS:
76         case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID:
77             return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc);
78 
79         case legacy_hal::WIFI_ERROR_TIMED_OUT:
80             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, desc + ", timed out");
81 
82         case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS:
83             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, desc + ", too many requests");
84 
85         case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY:
86             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, desc + ", out of memory");
87 
88         case legacy_hal::WIFI_ERROR_BUSY:
89             return createWifiStatus(WifiStatusCode::ERROR_BUSY);
90 
91         case legacy_hal::WIFI_ERROR_UNKNOWN:
92             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown");
93 
94         default:
95             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown error");
96     }
97 }
98 
createWifiStatusFromLegacyError(legacy_hal::wifi_error error)99 ndk::ScopedAStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) {
100     return createWifiStatusFromLegacyError(error, "");
101 }
102 
103 }  // namespace wifi
104 }  // namespace hardware
105 }  // namespace android
106 }  // namespace aidl
107