blob: 69655604d94433ed9469e11a42d73382d4ad40da [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();
Darin Petkovc0865312011-09-16 15:31:20 -070041 virtual void Scan(Error *error);
Paul Stewartfdd16072011-09-16 12:41:35 -070042 virtual bool TechnologyIs(const Technology::Identifier type) const;
mukesh agrawalf2f68a52011-09-01 12:15:48 -070043 virtual void LinkEvent(unsigned int flags, unsigned int change);
mukesh agrawalab87ea42011-05-18 11:44:49 -070044
45 // called by SupplicantInterfaceProxy, in response to events from
46 // wpa_supplicant.
47 void BSSAdded(const ::DBus::Path &BSS,
Chris Masonea82b7112011-05-25 15:16:29 -070048 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070049 void ScanDone();
50
mukesh agrawal445e72c2011-06-22 11:13:50 -070051 // called by WiFiService
mukesh agrawal6e277772011-09-29 15:04:23 -070052 virtual void ConnectTo(
53 WiFiService *service,
54 const std::map<std::string, ::DBus::Variant> &service_params);
mukesh agrawalb54601c2011-06-07 17:39:22 -070055
mukesh agrawal7a4e4002011-09-06 11:26:05 -070056 // called by Manager
57 virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error);
58
Paul Stewartb50f0b92011-05-16 16:31:42 -070059 private:
Paul Stewart6ab23a92011-11-09 17:17:47 -080060 FRIEND_TEST(WiFiMainTest, FindServiceWEP);
61 FRIEND_TEST(WiFiMainTest, FindServiceWPA);
62
mukesh agrawalb54601c2011-06-07 17:39:22 -070063 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
mukesh agrawal31950242011-07-14 11:53:38 -070064 typedef std::map<const std::string, WiFiServiceRefPtr> ServiceMap;
mukesh agrawalb54601c2011-06-07 17:39:22 -070065
mukesh agrawal7a4e4002011-09-06 11:26:05 -070066 static const char kManagerErrorPassphraseRequired[];
67 static const char kManagerErrorSSIDTooLong[];
68 static const char kManagerErrorSSIDTooShort[];
69 static const char kManagerErrorSSIDRequired[];
70 static const char kManagerErrorTypeRequired[];
71 static const char kManagerErrorUnsupportedSecurityMode[];
72 static const char kManagerErrorUnsupportedServiceType[];
73 static const char kManagerErrorUnsupportedServiceMode[];
mukesh agrawalab87ea42011-05-18 11:44:49 -070074
Paul Stewart6ab23a92011-11-09 17:17:47 -080075 WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid,
76 const std::string &mode,
77 const std::string &security) const;
Paul Stewartced6a0b2011-11-08 15:32:04 -080078 ByteArrays GetHiddenSSIDList();
mukesh agrawaldc42bb32011-07-28 10:40:26 -070079 void ScanDoneTask();
mukesh agrawal32399322011-09-01 10:53:43 -070080 void ScanTask();
mukesh agrawalb54601c2011-06-07 17:39:22 -070081
Darin Petkovab565bb2011-10-06 02:55:51 -070082 // Store cached copies of singletons for speed/ease of testing.
83 ProxyFactory *proxy_factory_;
84
mukesh agrawalb54601c2011-06-07 17:39:22 -070085 ScopedRunnableMethodFactory<WiFi> task_factory_;
mukesh agrawalaf571952011-07-14 14:31:12 -070086 scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
87 scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
mukesh agrawalb54601c2011-06-07 17:39:22 -070088 EndpointMap endpoint_by_bssid_;
89 ServiceMap service_by_private_id_;
mukesh agrawalab87ea42011-05-18 11:44:49 -070090
Chris Masone853b81b2011-06-24 14:11:41 -070091 // Properties
92 std::string bgscan_method_;
93 uint16 bgscan_short_interval_;
94 int32 bgscan_signal_threshold_;
95 bool scan_pending_;
96 uint16 scan_interval_;
mukesh agrawalf2f68a52011-09-01 12:15:48 -070097 bool link_up_;
Paul Stewartced6a0b2011-11-08 15:32:04 -080098 std::vector<WiFiServiceRefPtr> services_;
Chris Masone853b81b2011-06-24 14:11:41 -070099
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700100 friend class WiFiMainTest; // access to supplicant_*_proxy_, link_up_
Paul Stewartb50f0b92011-05-16 16:31:42 -0700101 DISALLOW_COPY_AND_ASSIGN(WiFi);
102};
103
104} // namespace shill
105
106#endif // SHILL_WIFI_