blob: f703ebe2c26b2c06cd8296b186a877f51cc65e57 [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
Roshan Pius3c4e8a32016-10-03 14:53:58 -070019namespace android {
20namespace hardware {
21namespace wifi {
Roshan Pius79a99752016-10-04 13:03:58 -070022namespace V1_0 {
23namespace implementation {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070024
25std::string LegacyErrorToString(wifi_error error) {
Roshan Pius79a99752016-10-04 13:03:58 -070026 switch (error) {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070027 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 Pius79a99752016-10-04 13:03:58 -070051FailureReason CreateFailureReason(CommandFailureReason reason,
52 const std::string& description) {
53 FailureReason result;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070054 result.reason = reason;
55 result.description = description.data();
56 return result;
57}
58
Roshan Pius79a99752016-10-04 13:03:58 -070059FailureReason CreateFailureReasonLegacyError(wifi_error error,
60 const std::string& desc) {
61 switch (error) {
Roshan Pius3c4e8a32016-10-03 14:53:58 -070062 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 Pius79a99752016-10-04 13:03:58 -070074 return CreateFailureReason(CommandFailureReason::UNKNOWN,
75 desc + ", timed out");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070076
77 case WIFI_ERROR_TOO_MANY_REQUESTS:
Roshan Pius79a99752016-10-04 13:03:58 -070078 return CreateFailureReason(CommandFailureReason::UNKNOWN,
79 desc + ", too many requests");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070080
81 case WIFI_ERROR_OUT_OF_MEMORY:
Roshan Pius79a99752016-10-04 13:03:58 -070082 return CreateFailureReason(CommandFailureReason::UNKNOWN,
83 desc + ", out of memory");
Roshan Pius3c4e8a32016-10-03 14:53:58 -070084
85 case WIFI_ERROR_NONE:
86 case WIFI_ERROR_UNKNOWN:
87 default:
88 return CreateFailureReason(CommandFailureReason::UNKNOWN, "unknown");
89 }
90}
91
Roshan Pius79a99752016-10-04 13:03:58 -070092} // namespace implementation
93} // namespace V1_0
Roshan Pius3c4e8a32016-10-03 14:53:58 -070094} // namespace wifi
95} // namespace hardware
96} // namespace android