1 /*
2  * Copyright (C) 2016 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 android {
20 namespace hardware {
21 namespace wifi {
22 namespace V1_4 {
23 namespace implementation {
24 
legacyErrorToString(legacy_hal::wifi_error error)25 std::string legacyErrorToString(legacy_hal::wifi_error error) {
26     switch (error) {
27         case legacy_hal::WIFI_SUCCESS:
28             return "SUCCESS";
29         case legacy_hal::WIFI_ERROR_UNINITIALIZED:
30             return "UNINITIALIZED";
31         case legacy_hal::WIFI_ERROR_NOT_AVAILABLE:
32             return "NOT_AVAILABLE";
33         case legacy_hal::WIFI_ERROR_NOT_SUPPORTED:
34             return "NOT_SUPPORTED";
35         case legacy_hal::WIFI_ERROR_INVALID_ARGS:
36             return "INVALID_ARGS";
37         case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID:
38             return "INVALID_REQUEST_ID";
39         case legacy_hal::WIFI_ERROR_TIMED_OUT:
40             return "TIMED_OUT";
41         case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS:
42             return "TOO_MANY_REQUESTS";
43         case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY:
44             return "OUT_OF_MEMORY";
45         case legacy_hal::WIFI_ERROR_BUSY:
46             return "BUSY";
47         case legacy_hal::WIFI_ERROR_UNKNOWN:
48             return "UNKNOWN";
49         default:
50             return "UNKNOWN ERROR";
51     }
52 }
53 
createWifiStatus(WifiStatusCode code,const std::string & description)54 WifiStatus createWifiStatus(WifiStatusCode code,
55                             const std::string& description) {
56     return {code, description};
57 }
58 
createWifiStatus(WifiStatusCode code)59 WifiStatus createWifiStatus(WifiStatusCode code) {
60     return createWifiStatus(code, "");
61 }
62 
createWifiStatusFromLegacyError(legacy_hal::wifi_error error,const std::string & desc)63 WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error,
64                                            const std::string& desc) {
65     switch (error) {
66         case legacy_hal::WIFI_ERROR_UNINITIALIZED:
67         case legacy_hal::WIFI_ERROR_NOT_AVAILABLE:
68             return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc);
69 
70         case legacy_hal::WIFI_ERROR_NOT_SUPPORTED:
71             return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc);
72 
73         case legacy_hal::WIFI_ERROR_INVALID_ARGS:
74         case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID:
75             return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc);
76 
77         case legacy_hal::WIFI_ERROR_TIMED_OUT:
78             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
79                                     desc + ", timed out");
80 
81         case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS:
82             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
83                                     desc + ", too many requests");
84 
85         case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY:
86             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
87                                     desc + ", out of memory");
88 
89         case legacy_hal::WIFI_ERROR_BUSY:
90             return createWifiStatus(WifiStatusCode::ERROR_BUSY);
91 
92         case legacy_hal::WIFI_ERROR_NONE:
93             return createWifiStatus(WifiStatusCode::SUCCESS, desc);
94 
95         case legacy_hal::WIFI_ERROR_UNKNOWN:
96             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown");
97 
98         default:
99             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
100                                     "unknown error");
101     }
102 }
103 
createWifiStatusFromLegacyError(legacy_hal::wifi_error error)104 WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) {
105     return createWifiStatusFromLegacyError(error, "");
106 }
107 
108 }  // namespace implementation
109 }  // namespace V1_4
110 }  // namespace wifi
111 }  // namespace hardware
112 }  // namespace android
113