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 { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 22 | namespace V1_2 { |
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"; |
| 49 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 52 | WifiStatus createWifiStatus(WifiStatusCode code, |
| 53 | const std::string& description) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 54 | return {code, description}; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 57 | WifiStatus createWifiStatus(WifiStatusCode code) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 58 | return createWifiStatus(code, ""); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 61 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 62 | const std::string& desc) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 63 | switch (error) { |
| 64 | case legacy_hal::WIFI_ERROR_UNINITIALIZED: |
| 65 | case legacy_hal::WIFI_ERROR_NOT_AVAILABLE: |
| 66 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 67 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 68 | case legacy_hal::WIFI_ERROR_NOT_SUPPORTED: |
| 69 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 70 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 71 | case legacy_hal::WIFI_ERROR_INVALID_ARGS: |
| 72 | case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID: |
| 73 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 74 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 75 | case legacy_hal::WIFI_ERROR_TIMED_OUT: |
| 76 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 77 | desc + ", timed out"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 78 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 79 | case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS: |
| 80 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 81 | desc + ", too many requests"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 82 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 83 | case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY: |
| 84 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 85 | desc + ", out of memory"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 86 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 87 | case legacy_hal::WIFI_ERROR_BUSY: |
| 88 | return createWifiStatus(WifiStatusCode::ERROR_BUSY); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 89 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 90 | case legacy_hal::WIFI_ERROR_NONE: |
| 91 | return createWifiStatus(WifiStatusCode::SUCCESS, desc); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 92 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 93 | case legacy_hal::WIFI_ERROR_UNKNOWN: |
| 94 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown"); |
| 95 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 98 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame^] | 99 | return createWifiStatusFromLegacyError(error, ""); |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 102 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 103 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 104 | } // namespace wifi |
| 105 | } // namespace hardware |
| 106 | } // namespace android |