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 | |
| 17 | #include "failure_reason_util.h" |
| 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 | |
| 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 | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 51 | FailureReason CreateFailureReason(CommandFailureReason reason, |
| 52 | const std::string& description) { |
| 53 | FailureReason result; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 54 | result.reason = reason; |
| 55 | result.description = description.data(); |
| 56 | return result; |
| 57 | } |
| 58 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 59 | FailureReason CreateFailureReasonLegacyError(wifi_error error, |
| 60 | const std::string& desc) { |
| 61 | switch (error) { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 62 | case WIFI_ERROR_UNINITIALIZED: |
| 63 | case WIFI_ERROR_NOT_AVAILABLE: |
| 64 | return CreateFailureReason(CommandFailureReason::NOT_AVAILABLE, desc); |
| 65 | |
| 66 | case WIFI_ERROR_NOT_SUPPORTED: |
| 67 | return CreateFailureReason(CommandFailureReason::NOT_SUPPORTED, desc); |
| 68 | |
| 69 | case WIFI_ERROR_INVALID_ARGS: |
| 70 | case WIFI_ERROR_INVALID_REQUEST_ID: |
| 71 | return CreateFailureReason(CommandFailureReason::INVALID_ARGS, desc); |
| 72 | |
| 73 | case WIFI_ERROR_TIMED_OUT: |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 74 | return CreateFailureReason(CommandFailureReason::UNKNOWN, |
| 75 | desc + ", timed out"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 76 | |
| 77 | case WIFI_ERROR_TOO_MANY_REQUESTS: |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 78 | return CreateFailureReason(CommandFailureReason::UNKNOWN, |
| 79 | desc + ", too many requests"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 80 | |
| 81 | case WIFI_ERROR_OUT_OF_MEMORY: |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 82 | return CreateFailureReason(CommandFailureReason::UNKNOWN, |
| 83 | desc + ", out of memory"); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 84 | |
| 85 | case WIFI_ERROR_NONE: |
| 86 | case WIFI_ERROR_UNKNOWN: |
| 87 | default: |
| 88 | return CreateFailureReason(CommandFailureReason::UNKNOWN, "unknown"); |
| 89 | } |
| 90 | } |
| 91 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 92 | } // namespace implementation |
| 93 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 94 | } // namespace wifi |
| 95 | } // namespace hardware |
| 96 | } // namespace android |