1// Copyright 2015 The Weave Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_
6#define LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_
7
8#include <string>
9#include <vector>
10
11#include <base/memory/weak_ptr.h>
12#include <base/time/time.h>
13#include <weave/provider/wifi.h>
14
15namespace weave {
16
17namespace provider {
18class TaskRunner;
19}
20
21namespace examples {
22
23class EventNetworkImpl;
24
25// Basic weave::Wifi implementation.
26// Production version of SSL socket needs secure server certificate check.
27class WifiImpl : public provider::Wifi {
28 public:
29  WifiImpl(provider::TaskRunner* task_runner, EventNetworkImpl* network);
30  ~WifiImpl();
31
32  // Wifi implementation.
33  void Connect(const std::string& ssid,
34               const std::string& passphrase,
35               const DoneCallback& callback) override;
36  void StartAccessPoint(const std::string& ssid) override;
37  void StopAccessPoint() override;
38  bool IsWifi24Supported() const override {return true;};
39  bool IsWifi50Supported() const override {return false;};
40
41  static bool HasWifiCapability();
42
43 private:
44  void TryToConnect(const std::string& ssid,
45                    const std::string& passphrase,
46                    int pid,
47                    base::Time until,
48                    const DoneCallback& callback);
49  bool hostapd_started_{false};
50  provider::TaskRunner* task_runner_{nullptr};
51  EventNetworkImpl* network_{nullptr};
52  base::WeakPtrFactory<WifiImpl> weak_ptr_factory_{this};
53  std::string iface_;
54};
55
56}  // namespace examples
57}  // namespace weave
58
59#endif  // LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_
60