blob: 1dcc11076184761f8dd7bbd9223b6ced2892a87b [file] [log] [blame]
Paul Stewartb50f0b92011-05-16 16:31:42 -07001// Copyright (c) 2011 The Chromium OS 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 SHILL_WIFI_
6#define SHILL_WIFI_
7
mukesh agrawalab87ea42011-05-18 11:44:49 -07008#include <map>
Chris Masone46eaaf52011-05-24 13:08:30 -07009#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070010#include <vector>
Chris Masone46eaaf52011-05-24 13:08:30 -070011
mukesh agrawalaf571952011-07-14 14:31:12 -070012#include <dbus-c++/dbus.h>
Paul Stewart6ab23a92011-11-09 17:17:47 -080013#include <gtest/gtest_prod.h> // for FRIEND_TEST
mukesh agrawalaf571952011-07-14 14:31:12 -070014
Paul Stewartb50f0b92011-05-16 16:31:42 -070015#include "shill/device.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070016#include "shill/event_dispatcher.h"
Chris Masone2b105542011-06-22 10:58:09 -070017#include "shill/refptr_types.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070018
19namespace shill {
20
mukesh agrawal7a4e4002011-09-06 11:26:05 -070021class Error;
22class KeyValueStore;
Darin Petkovab565bb2011-10-06 02:55:51 -070023class ProxyFactory;
mukesh agrawalaf571952011-07-14 14:31:12 -070024class SupplicantInterfaceProxyInterface;
25class SupplicantProcessProxyInterface;
mukesh agrawal445e72c2011-06-22 11:13:50 -070026class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -070027
mukesh agrawalab87ea42011-05-18 11:44:49 -070028// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070029class WiFi : public Device {
30 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070031 WiFi(ControlInterface *control_interface,
32 EventDispatcher *dispatcher,
33 Manager *manager,
Chris Masone626719f2011-08-18 16:58:48 -070034 const std::string &link,
35 const std::string &address,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070036 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070037 virtual ~WiFi();
Darin Petkovc0865312011-09-16 15:31:20 -070038
mukesh agrawalab87ea42011-05-18 11:44:49 -070039 virtual void Start();
40 virtual void Stop();
Paul Stewarta41e38d2011-11-11 07:47:29 -080041 virtual bool Load(StoreInterface *storage);
Darin Petkovc0865312011-09-16 15:31:20 -070042 virtual void Scan(Error *error);
Paul Stewartfdd16072011-09-16 12:41:35 -070043 virtual bool TechnologyIs(const Technology::Identifier type) const;
mukesh agrawalf2f68a52011-09-01 12:15:48 -070044 virtual void LinkEvent(unsigned int flags, unsigned int change);
mukesh agrawalab87ea42011-05-18 11:44:49 -070045
46 // called by SupplicantInterfaceProxy, in response to events from
47 // wpa_supplicant.
48 void BSSAdded(const ::DBus::Path &BSS,
Chris Masonea82b7112011-05-25 15:16:29 -070049 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawal7ec71312011-11-10 02:08:26 +000050 void PropertiesChanged(
51 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070052 void ScanDone();
53
mukesh agrawal445e72c2011-06-22 11:13:50 -070054 // called by WiFiService
mukesh agrawal6e277772011-09-29 15:04:23 -070055 virtual void ConnectTo(
56 WiFiService *service,
57 const std::map<std::string, ::DBus::Variant> &service_params);
mukesh agrawalb54601c2011-06-07 17:39:22 -070058
mukesh agrawal7a4e4002011-09-06 11:26:05 -070059 // called by Manager
60 virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error);
61
Paul Stewartb50f0b92011-05-16 16:31:42 -070062 private:
mukesh agrawal7ec71312011-11-10 02:08:26 +000063 friend class WiFiMainTest; // access to supplicant_*_proxy_, link_up_
mukesh agrawal7ec71312011-11-10 02:08:26 +000064 FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown
Paul Stewart6ab23a92011-11-09 17:17:47 -080065
mukesh agrawalb54601c2011-06-07 17:39:22 -070066 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
mukesh agrawal31950242011-07-14 11:53:38 -070067 typedef std::map<const std::string, WiFiServiceRefPtr> ServiceMap;
mukesh agrawalb54601c2011-06-07 17:39:22 -070068
mukesh agrawal7a4e4002011-09-06 11:26:05 -070069 static const char kManagerErrorPassphraseRequired[];
70 static const char kManagerErrorSSIDTooLong[];
71 static const char kManagerErrorSSIDTooShort[];
72 static const char kManagerErrorSSIDRequired[];
73 static const char kManagerErrorTypeRequired[];
74 static const char kManagerErrorUnsupportedSecurityMode[];
75 static const char kManagerErrorUnsupportedServiceType[];
76 static const char kManagerErrorUnsupportedServiceMode[];
mukesh agrawal7ec71312011-11-10 02:08:26 +000077 static const char kInterfaceStateUnknown[];
mukesh agrawalab87ea42011-05-18 11:44:49 -070078
Paul Stewart6ab23a92011-11-09 17:17:47 -080079 WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid,
80 const std::string &mode,
81 const std::string &security) const;
Paul Stewartced6a0b2011-11-08 15:32:04 -080082 ByteArrays GetHiddenSSIDList();
Paul Stewarta41e38d2011-11-11 07:47:29 -080083 // Create services for hidden networks stored in |storage|. Returns true
84 // if any were found, otherwise returns false.
85 bool LoadHiddenServices(StoreInterface *storage);
mukesh agrawaldc42bb32011-07-28 10:40:26 -070086 void ScanDoneTask();
mukesh agrawal32399322011-09-01 10:53:43 -070087 void ScanTask();
mukesh agrawal7ec71312011-11-10 02:08:26 +000088 void StateChanged(const std::string &new_state);
mukesh agrawalb54601c2011-06-07 17:39:22 -070089
Darin Petkovab565bb2011-10-06 02:55:51 -070090 // Store cached copies of singletons for speed/ease of testing.
91 ProxyFactory *proxy_factory_;
92
mukesh agrawalb54601c2011-06-07 17:39:22 -070093 ScopedRunnableMethodFactory<WiFi> task_factory_;
mukesh agrawalaf571952011-07-14 14:31:12 -070094 scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
95 scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
mukesh agrawalb54601c2011-06-07 17:39:22 -070096 EndpointMap endpoint_by_bssid_;
97 ServiceMap service_by_private_id_;
mukesh agrawalab87ea42011-05-18 11:44:49 -070098
Chris Masone853b81b2011-06-24 14:11:41 -070099 // Properties
100 std::string bgscan_method_;
101 uint16 bgscan_short_interval_;
102 int32 bgscan_signal_threshold_;
103 bool scan_pending_;
104 uint16 scan_interval_;
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700105 bool link_up_;
Paul Stewartced6a0b2011-11-08 15:32:04 -0800106 std::vector<WiFiServiceRefPtr> services_;
mukesh agrawal7ec71312011-11-10 02:08:26 +0000107 WiFiServiceRefPtr pending_service_;
108 std::string supplicant_state_;
Chris Masone853b81b2011-06-24 14:11:41 -0700109
Paul Stewartb50f0b92011-05-16 16:31:42 -0700110 DISALLOW_COPY_AND_ASSIGN(WiFi);
111};
112
113} // namespace shill
114
115#endif // SHILL_WIFI_