1 /*
2  * Copyright 2018, 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 #pragma once
18 
19 #include "command.h"
20 #include "result.h"
21 
22 #include <string>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <vector>
26 
27 class Bridge;
28 
29 class WifiCommand : public Command {
30 public:
31     explicit WifiCommand(Bridge& bridge);
32     virtual ~WifiCommand() = default;
33 
34     Result onCommand(const char* command, const char* args) override;
35 private:
36     void readConfig();
37     Result writeConfig();
38     Result triggerHostApd();
39 
40     Result onAdd(const std::vector<std::string>& args);
41     Result onBlock(const std::vector<std::string>& args);
42     Result onUnblock(const std::vector<std::string>& args);
43 
44     struct AccessPoint {
AccessPointAccessPoint45         AccessPoint() : blocked(false) {}
46         std::string ifName;
47         std::string ssid;
48         std::string password;
49         bool blocked;
50     };
51 
52     Bridge& mBridge;
53     std::unordered_map<std::string, AccessPoint> mAccessPoints;
54     std::unordered_set<std::string> mUsedInterfaces;
55     int mLowestInterfaceNumber;
56 };
57 
58