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 | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 25 | std::string legacyErrorToString(legacy_hal::wifi_error error) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 26 | switch (error) { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 27 | case legacy_hal::WIFI_SUCCESS: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 28 | return "SUCCESS"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 29 | case legacy_hal::WIFI_ERROR_UNINITIALIZED: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 30 | return "UNINITIALIZED"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 31 | case legacy_hal::WIFI_ERROR_NOT_AVAILABLE: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 32 | return "NOT_AVAILABLE"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 33 | case legacy_hal::WIFI_ERROR_NOT_SUPPORTED: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 34 | return "NOT_SUPPORTED"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 35 | case legacy_hal::WIFI_ERROR_INVALID_ARGS: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 36 | return "INVALID_ARGS"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 37 | case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 38 | return "INVALID_REQUEST_ID"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 39 | case legacy_hal::WIFI_ERROR_TIMED_OUT: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 40 | return "TIMED_OUT"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 41 | case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 42 | return "TOO_MANY_REQUESTS"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 43 | case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 44 | return "OUT_OF_MEMORY"; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 45 | case legacy_hal::WIFI_ERROR_UNKNOWN: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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) { |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 53 | return {code, description}; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 56 | WifiStatus createWifiStatus(WifiStatusCode code) { |
| 57 | return createWifiStatus(code, ""); |
| 58 | } |
| 59 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 60 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error, |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 61 | const std::string& desc) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 62 | switch (error) { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 63 | case legacy_hal::WIFI_ERROR_UNINITIALIZED: |
| 64 | case legacy_hal::WIFI_ERROR_NOT_AVAILABLE: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 65 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 66 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 67 | case legacy_hal::WIFI_ERROR_NOT_SUPPORTED: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 68 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 69 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 70 | case legacy_hal::WIFI_ERROR_INVALID_ARGS: |
| 71 | case legacy_hal::WIFI_ERROR_INVALID_REQUEST_ID: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 72 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS, desc); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 73 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 74 | case legacy_hal::WIFI_ERROR_TIMED_OUT: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 75 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 76 | desc + ", timed out"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 77 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 78 | case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 79 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 80 | desc + ", too many requests"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 81 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 82 | case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 83 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, |
| 84 | desc + ", out of memory"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 85 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 86 | case legacy_hal::WIFI_ERROR_NONE: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 87 | return createWifiStatus(WifiStatusCode::SUCCESS, desc); |
| 88 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 89 | case legacy_hal::WIFI_ERROR_UNKNOWN: |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 90 | default: |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 91 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 95 | WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) { |
Roshan Pius | 1922482 | 2016-10-11 08:21:46 -0700 | [diff] [blame] | 96 | return createWifiStatusFromLegacyError(error, ""); |
| 97 | } |
| 98 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 99 | } // namespace implementation |
| 100 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 101 | } // namespace wifi |
| 102 | } // namespace hardware |
| 103 | } // namespace android |