Home | History | Annotate | Download | only in default
      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 "wifi_status_util.h"
     18 
     19 namespace android {
     20 namespace hardware {
     21 namespace wifi {
     22 namespace V1_2 {
     23 namespace implementation {
     24 
     25 std::string legacyErrorToString(legacy_hal::wifi_error error) {
     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     }
     50 }
     51 
     52 WifiStatus createWifiStatus(WifiStatusCode code,
     53                             const std::string& description) {
     54     return {code, description};
     55 }
     56 
     57 WifiStatus createWifiStatus(WifiStatusCode code) {
     58     return createWifiStatus(code, "");
     59 }
     60 
     61 WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error,
     62                                            const std::string& desc) {
     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);
     67 
     68         case legacy_hal::WIFI_ERROR_NOT_SUPPORTED:
     69             return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED, desc);
     70 
     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);
     74 
     75         case legacy_hal::WIFI_ERROR_TIMED_OUT:
     76             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
     77                                     desc + ", timed out");
     78 
     79         case legacy_hal::WIFI_ERROR_TOO_MANY_REQUESTS:
     80             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
     81                                     desc + ", too many requests");
     82 
     83         case legacy_hal::WIFI_ERROR_OUT_OF_MEMORY:
     84             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN,
     85                                     desc + ", out of memory");
     86 
     87         case legacy_hal::WIFI_ERROR_BUSY:
     88             return createWifiStatus(WifiStatusCode::ERROR_BUSY);
     89 
     90         case legacy_hal::WIFI_ERROR_NONE:
     91             return createWifiStatus(WifiStatusCode::SUCCESS, desc);
     92 
     93         case legacy_hal::WIFI_ERROR_UNKNOWN:
     94             return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, "unknown");
     95     }
     96 }
     97 
     98 WifiStatus createWifiStatusFromLegacyError(legacy_hal::wifi_error error) {
     99     return createWifiStatusFromLegacyError(error, "");
    100 }
    101 
    102 }  // namespace implementation
    103 }  // namespace V1_2
    104 }  // namespace wifi
    105 }  // namespace hardware
    106 }  // namespace android
    107