Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 17 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 18 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace wifi { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 22 | namespace V1_0 { |
| 23 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 25 | std::string legacyErrorToString(wifi_error error) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 26 | switch (error) { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 27 | 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 Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 51 | WifiStatus createWifiStatus(WifiStatusCode code, |
| 52 | const std::string& description) { |
| 53 | WifiStatus result; |
| 54 | result.code = code; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 55 | result.description = description.data(); |
| 56 | return result; |
| 57 | } |
| 58 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 59 | WifiStatus createWifiStatus(WifiStatusCode code) { |
| 60 | return createWifiStatus(code, ""); |
| 61 | } |
| 62 | |
| 63 | WifiStatus createWifiStatusFromLegacyError(wifi_error error, |
| 64 | const std::string& desc) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 65 | switch (error) { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 66 | case WIFI_ERROR_UNINITIALIZED: |
| 67 | case WIFI_ERROR_NOT_AVAILABLE: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 68 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 69 | |
| 70 | case WIFI_ERROR_NOT_SUPPORTED: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 71 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 72 | |
| 73 | case WIFI_ERROR_INVALID_ARGS: |
| 74 | case WIFI_ERROR_INVALID_REQUEST_ID: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 75 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 76 | |
| 77 | case WIFI_ERROR_TIMED_OUT: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 78 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 79 | desc + ", timed out"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 80 | |
| 81 | case WIFI_ERROR_TOO_MANY_REQUESTS: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 82 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 83 | desc + ", too many requests"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 84 | |
| 85 | case WIFI_ERROR_OUT_OF_MEMORY: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 86 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 87 | desc + ", out of memory"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 88 | |
| 89 | case WIFI_ERROR_NONE: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 90 | return createWifiStatus(WifiStatusCode::SUCCESS, desc); |
| 91 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 92 | case WIFI_ERROR_UNKNOWN: |
| 93 | default: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 94 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 98 | WifiStatus createWifiStatusFromLegacyError(wifi_error error) { |
| 99 | return createWifiStatusFromLegacyError(error, ""); |
| 100 | } |
| 101 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 102 | } // namespace implementation |
| 103 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 104 | } // namespace wifi |
| 105 | } // namespace hardware |
| 106 | } // namespace android |