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 { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 22 | namespace V1_5 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 23 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 25 | std::string legacyErrorToString(legacy_hal::wifi_error error) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 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"; |
Ahmed ElArabawy | 80feb3c | 2019-10-24 19:15:27 -0700 | [diff] [blame] | 49 | default: |
| 50 | return "UNKNOWN ERROR"; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 51 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 54 | WifiStatus createWifiStatus(WifiStatusCode code, |
| 55 | const std::string& description) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 56 | return {code, description}; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 59 | WifiStatus createWifiStatus(WifiStatusCode code) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 60 | return createWifiStatus(code, ""); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 63 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 64 | const std::string& desc) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 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); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 69 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 70 | case legacy_hal::WIFI_ERROR_NOT_SUPPORTED: |
| 71 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 72 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 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); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 76 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 77 | case legacy_hal::WIFI_ERROR_TIMED_OUT: |
| 78 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 79 | desc + ", timed out"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 80 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 81 | case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS: |
| 82 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 83 | desc + ", too many requests"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 84 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 85 | case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY: |
| 86 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 87 | desc + ", out of memory"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 88 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 89 | case legacy_hal::WIFI_ERROR_BUSY: |
| 90 | return createWifiStatus(WifiStatusCode::ERROR_BUSY); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 91 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 92 | case legacy_hal::WIFI_ERROR_NONE: |
| 93 | return createWifiStatus(WifiStatusCode::SUCCESS, desc); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 94 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 95 | case legacy_hal::WIFI_ERROR_UNKNOWN: |
| 96 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown"); |
Ahmed ElArabawy | 80feb3c | 2019-10-24 19:15:27 -0700 | [diff] [blame] | 97 | |
| 98 | default: |
| 99 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 100 | "unknown error"); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 101 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 104 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 105 | return createWifiStatusFromLegacyError(error, ""); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 108 | } // namespace implementation |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 109 | } // namespace V1_5 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 110 | } // namespace wifi |
| 111 | } // namespace hardware |
| 112 | } // namespace android |