Home | History | Annotate | Download | only in wifi_hal
      1 /*
      2  * Copyright (C) 2017 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 "info.h"
     18 
     19 static const char kInterfaceName[] = "wlan0";
     20 
     21 Info::Info() {
     22     mInterfaces.emplace_back(mNetlink, kInterfaceName);
     23     auto handle = reinterpret_cast<wifi_interface_handle>(&mInterfaces.back());
     24     mInterfaceHandles.emplace_back(handle);
     25 }
     26 
     27 bool Info::init() {
     28     if (!mNetlink.init()) {
     29         return false;
     30     }
     31     for (auto& iface : mInterfaces) {
     32         if (!iface.init()) {
     33             return false;
     34         }
     35     }
     36     return true;
     37 }
     38 
     39 void Info::eventLoop() {
     40     mNetlink.eventLoop();
     41 }
     42 
     43 void Info::stop(StopHandler stopHandler) {
     44     mNetlink.stop(stopHandler);
     45 }
     46 
     47 wifi_error Info::getInterfaces(int* num, wifi_interface_handle** interfaces) {
     48     if (num == nullptr || interfaces == nullptr) {
     49         return WIFI_ERROR_INVALID_ARGS;
     50     }
     51     *num = mInterfaceHandles.size();
     52     *interfaces = mInterfaceHandles.data();
     53 
     54     return WIFI_SUCCESS;
     55 }
     56 
     57