blob: 7fd226978af5e9ab82a49a3ef7778f9ff76ceaa2 [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001/*
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
19using ::android::hardware::wifi::V1_0::CommandFailureReason;
20
21namespace android {
22namespace hardware {
23namespace wifi {
24
25std::string LegacyErrorToString(wifi_error error) {
26 switch(error) {
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
51V1_0::FailureReason CreateFailureReason(
52 CommandFailureReason reason, const std::string& description) {
53 V1_0::FailureReason result;
54 result.reason = reason;
55 result.description = description.data();
56 return result;
57}
58
59V1_0::FailureReason CreateFailureReasonLegacyError(
60 wifi_error error, const std::string& desc) {
61 switch(error) {
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:
74 return CreateFailureReason(
75 CommandFailureReason::UNKNOWN, desc + ", timed out");
76
77 case WIFI_ERROR_TOO_MANY_REQUESTS:
78 return CreateFailureReason(
79 CommandFailureReason::UNKNOWN, desc + ", too many requests");
80
81 case WIFI_ERROR_OUT_OF_MEMORY:
82 return CreateFailureReason(
83 CommandFailureReason::UNKNOWN, desc + ", out of memory");
84
85 case WIFI_ERROR_NONE:
86 case WIFI_ERROR_UNKNOWN:
87 default:
88 return CreateFailureReason(CommandFailureReason::UNKNOWN, "unknown");
89 }
90}
91
92} // namespace wifi
93} // namespace hardware
94} // namespace android