Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 1 | // 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 agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 8 | #include <map> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 9 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 10 | #include <vector> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 11 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 14 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 15 | #include "shill/device.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 16 | #include "shill/event_dispatcher.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 17 | #include "shill/refptr_types.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 18 | |
| 19 | namespace shill { |
| 20 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 21 | class Error; |
| 22 | class KeyValueStore; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 23 | class ProxyFactory; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 24 | class SupplicantInterfaceProxyInterface; |
| 25 | class SupplicantProcessProxyInterface; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 26 | class WiFiService; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 27 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 28 | // WiFi class. Specialization of Device for WiFi. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 29 | class WiFi : public Device { |
| 30 | public: |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 31 | WiFi(ControlInterface *control_interface, |
| 32 | EventDispatcher *dispatcher, |
| 33 | Manager *manager, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 34 | const std::string &link, |
| 35 | const std::string &address, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 36 | int interface_index); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 37 | virtual ~WiFi(); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 38 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 39 | virtual void Start(); |
| 40 | virtual void Stop(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame^] | 41 | virtual bool Load(StoreInterface *storage); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 42 | virtual void Scan(Error *error); |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 43 | virtual bool TechnologyIs(const Technology::Identifier type) const; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 44 | virtual void LinkEvent(unsigned int flags, unsigned int change); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 45 | |
| 46 | // called by SupplicantInterfaceProxy, in response to events from |
| 47 | // wpa_supplicant. |
| 48 | void BSSAdded(const ::DBus::Path &BSS, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 49 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 50 | void PropertiesChanged( |
| 51 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 52 | void ScanDone(); |
| 53 | |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 54 | // called by WiFiService |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 55 | virtual void ConnectTo( |
| 56 | WiFiService *service, |
| 57 | const std::map<std::string, ::DBus::Variant> &service_params); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 58 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 59 | // called by Manager |
| 60 | virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error); |
| 61 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 62 | private: |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 63 | friend class WiFiMainTest; // access to supplicant_*_proxy_, link_up_ |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 64 | FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 65 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 66 | typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap; |
mukesh agrawal | 3195024 | 2011-07-14 11:53:38 -0700 | [diff] [blame] | 67 | typedef std::map<const std::string, WiFiServiceRefPtr> ServiceMap; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 68 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 69 | 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 agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 77 | static const char kInterfaceStateUnknown[]; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 78 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 79 | WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid, |
| 80 | const std::string &mode, |
| 81 | const std::string &security) const; |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 82 | ByteArrays GetHiddenSSIDList(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame^] | 83 | // Create services for hidden networks stored in |storage|. Returns true |
| 84 | // if any were found, otherwise returns false. |
| 85 | bool LoadHiddenServices(StoreInterface *storage); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 86 | void ScanDoneTask(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 87 | void ScanTask(); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 88 | void StateChanged(const std::string &new_state); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 89 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 90 | // Store cached copies of singletons for speed/ease of testing. |
| 91 | ProxyFactory *proxy_factory_; |
| 92 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 93 | ScopedRunnableMethodFactory<WiFi> task_factory_; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 94 | scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; |
| 95 | scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 96 | EndpointMap endpoint_by_bssid_; |
| 97 | ServiceMap service_by_private_id_; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 98 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 99 | // 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 agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 105 | bool link_up_; |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 106 | std::vector<WiFiServiceRefPtr> services_; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 107 | WiFiServiceRefPtr pending_service_; |
| 108 | std::string supplicant_state_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 109 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 110 | DISALLOW_COPY_AND_ASSIGN(WiFi); |
| 111 | }; |
| 112 | |
| 113 | } // namespace shill |
| 114 | |
| 115 | #endif // SHILL_WIFI_ |