blob: 21b4eebe7b29a4e1c4ba4e36870170368f57df1a [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001/*
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
Roshan Pius19224822016-10-11 08:21:46 -070017#include "wifi_status_util.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070018
Roshan Pius3c4e8a32016-10-03 14:53:58 -070019namespace android {
20namespace hardware {
21namespace wifi {
Roshan Pius79a99752016-10-04 13:03:58 -070022namespace V1_0 {
23namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070024
Roshan Pius19224822016-10-11 08:21:46 -070025std::string legacyErrorToString(wifi_error error) {
Roshan Pius79a99752016-10-04 13:03:58 -070026 switch (error) {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070027 case WIFI_SUCCESS:
28 return "SUCCESS";
29 case WIFI_ERROR_UNINITIALIZED:
30 return "UNINITIALIZED";
31 case WIFI_ERROR_NOT_AVAILABLE:
32 return "NOT_AVAILABLE";
33 case WIFI_ERROR_NOT_SUPPORTED:
34 return "NOT_SUPPORTED";
35 case WIFI_ERROR_INVALID_ARGS:
36 return "INVALID_ARGS";
37 case WIFI_ERROR_INVALID_REQUEST_ID:
38 return "INVALID_REQUEST_ID";
39 case WIFI_ERROR_TIMED_OUT:
40 return "TIMED_OUT";
41 case WIFI_ERROR_TOO_MANY_REQUESTS:
42 return "TOO_MANY_REQUESTS";
43 case WIFI_ERROR_OUT_OF_MEMORY:
44 return "OUT_OF_MEMORY";
45 case WIFI_ERROR_UNKNOWN:
46 default:
47 return "UNKNOWN";
48 }
49}
50
Roshan Pius19224822016-10-11 08:21:46 -070051WifiStatus createWifiStatus(WifiStatusCode code,
52 const std::string& description) {
53 WifiStatus result;
54 result.code = code;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070055 result.description = description.data();
56 return result;
57}
58
Roshan Pius19224822016-10-11 08:21:46 -070059WifiStatus createWifiStatus(WifiStatusCode code) {
60 return createWifiStatus(code, "");
61}
62
63WifiStatus createWifiStatusFromLegacyError(wifi_error error,
64 const std::string& desc) {
Roshan Pius79a99752016-10-04 13:03:58 -070065 switch (error) {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070066 case WIFI_ERROR_UNINITIALIZED:
67 case WIFI_ERROR_NOT_AVAILABLE:
Roshan Pius19224822016-10-11 08:21:46 -070068 return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070069
70 case WIFI_ERROR_NOT_SUPPORTED:
Roshan Pius19224822016-10-11 08:21:46 -070071 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070072
73 case WIFI_ERROR_INVALID_ARGS:
74 case WIFI_ERROR_INVALID_REQUEST_ID:
Roshan Pius19224822016-10-11 08:21:46 -070075 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc);
Roshan Pius3c4e8a32016-10-03 14:53:58 -070076
77 case WIFI_ERROR_TIMED_OUT:
Roshan Pius19224822016-10-11 08:21:46 -070078 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
79 desc + ", timed out");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070080
81 case WIFI_ERROR_TOO_MANY_REQUESTS:
Roshan Pius19224822016-10-11 08:21:46 -070082 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
83 desc + ", too many requests");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070084
85 case WIFI_ERROR_OUT_OF_MEMORY:
Roshan Pius19224822016-10-11 08:21:46 -070086 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
87 desc + ", out of memory");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070088
89 case WIFI_ERROR_NONE:
Roshan Pius19224822016-10-11 08:21:46 -070090 return createWifiStatus(WifiStatusCode::SUCCESS, desc);
91
Roshan Pius3c4e8a32016-10-03 14:53:58 -070092 case WIFI_ERROR_UNKNOWN:
93 default:
Roshan Pius19224822016-10-11 08:21:46 -070094 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070095 }
96}
97
Roshan Pius19224822016-10-11 08:21:46 -070098WifiStatus createWifiStatusFromLegacyError(wifi_error error) {
99 return createWifiStatusFromLegacyError(error, "");
100}
101
Roshan Pius79a99752016-10-04 13:03:58 -0700102} // namespace implementation
103} // namespace V1_0
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700104} // namespace wifi
105} // namespace hardware
106} // namespace android