blob: 919891fe87a1d8888eb3aa4f08d59d060375195e [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>
13
Paul Stewartb50f0b92011-05-16 16:31:42 -070014#include "shill/device.h"
Chris Masone2b105542011-06-22 10:58:09 -070015#include "shill/refptr_types.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070016#include "shill/shill_event.h"
17
18namespace shill {
19
mukesh agrawal7a4e4002011-09-06 11:26:05 -070020class Error;
21class KeyValueStore;
mukesh agrawalaf571952011-07-14 14:31:12 -070022class SupplicantInterfaceProxyInterface;
23class SupplicantProcessProxyInterface;
mukesh agrawal445e72c2011-06-22 11:13:50 -070024class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -070025
mukesh agrawalab87ea42011-05-18 11:44:49 -070026// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070027class WiFi : public Device {
28 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070029 WiFi(ControlInterface *control_interface,
30 EventDispatcher *dispatcher,
31 Manager *manager,
Chris Masone626719f2011-08-18 16:58:48 -070032 const std::string &link,
33 const std::string &address,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070034 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070035 virtual ~WiFi();
Darin Petkovc0865312011-09-16 15:31:20 -070036
mukesh agrawalab87ea42011-05-18 11:44:49 -070037 virtual void Start();
38 virtual void Stop();
Darin Petkovc0865312011-09-16 15:31:20 -070039 virtual void Scan(Error *error);
Paul Stewartfdd16072011-09-16 12:41:35 -070040 virtual bool TechnologyIs(const Technology::Identifier type) const;
mukesh agrawalf2f68a52011-09-01 12:15:48 -070041 virtual void LinkEvent(unsigned int flags, unsigned int change);
mukesh agrawalab87ea42011-05-18 11:44:49 -070042
43 // called by SupplicantInterfaceProxy, in response to events from
44 // wpa_supplicant.
45 void BSSAdded(const ::DBus::Path &BSS,
Chris Masonea82b7112011-05-25 15:16:29 -070046 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070047 void ScanDone();
48
mukesh agrawal445e72c2011-06-22 11:13:50 -070049 // called by WiFiService
mukesh agrawal6e277772011-09-29 15:04:23 -070050 virtual void ConnectTo(
51 WiFiService *service,
52 const std::map<std::string, ::DBus::Variant> &service_params);
mukesh agrawalb54601c2011-06-07 17:39:22 -070053
mukesh agrawal7a4e4002011-09-06 11:26:05 -070054 // called by Manager
55 virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error);
56
Paul Stewartb50f0b92011-05-16 16:31:42 -070057 private:
mukesh agrawalb54601c2011-06-07 17:39:22 -070058 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
mukesh agrawal31950242011-07-14 11:53:38 -070059 typedef std::map<const std::string, WiFiServiceRefPtr> ServiceMap;
mukesh agrawalb54601c2011-06-07 17:39:22 -070060
mukesh agrawal7a4e4002011-09-06 11:26:05 -070061 static const char kManagerErrorPassphraseRequired[];
62 static const char kManagerErrorSSIDTooLong[];
63 static const char kManagerErrorSSIDTooShort[];
64 static const char kManagerErrorSSIDRequired[];
65 static const char kManagerErrorTypeRequired[];
66 static const char kManagerErrorUnsupportedSecurityMode[];
67 static const char kManagerErrorUnsupportedServiceType[];
68 static const char kManagerErrorUnsupportedServiceMode[];
mukesh agrawalab87ea42011-05-18 11:44:49 -070069
mukesh agrawaldc42bb32011-07-28 10:40:26 -070070 void ScanDoneTask();
mukesh agrawal32399322011-09-01 10:53:43 -070071 void ScanTask();
mukesh agrawalb54601c2011-06-07 17:39:22 -070072
mukesh agrawal7a4e4002011-09-06 11:26:05 -070073 static std::string ParseWEPPassphrase(const std::string &passphrase,
74 Error *error);
75 static bool CheckWEPIsHex(const std::string &passphrase, Error *error);
76 static bool CheckWEPKeyIndex(const std::string &passphrase, Error *error);
77 static bool CheckWEPPrefix(const std::string &passphrase, Error *error);
78
mukesh agrawalb54601c2011-06-07 17:39:22 -070079 ScopedRunnableMethodFactory<WiFi> task_factory_;
mukesh agrawalaf571952011-07-14 14:31:12 -070080 scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
81 scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
mukesh agrawalb54601c2011-06-07 17:39:22 -070082 EndpointMap endpoint_by_bssid_;
83 ServiceMap service_by_private_id_;
mukesh agrawalab87ea42011-05-18 11:44:49 -070084
Chris Masone853b81b2011-06-24 14:11:41 -070085 // Properties
86 std::string bgscan_method_;
87 uint16 bgscan_short_interval_;
88 int32 bgscan_signal_threshold_;
89 bool scan_pending_;
90 uint16 scan_interval_;
mukesh agrawalf2f68a52011-09-01 12:15:48 -070091 bool link_up_;
Chris Masone853b81b2011-06-24 14:11:41 -070092
mukesh agrawalf2f68a52011-09-01 12:15:48 -070093 friend class WiFiMainTest; // access to supplicant_*_proxy_, link_up_
Paul Stewartb50f0b92011-05-16 16:31:42 -070094 DISALLOW_COPY_AND_ASSIGN(WiFi);
95};
96
97} // namespace shill
98
99#endif // SHILL_WIFI_