blob: 86b623fe52ccc4e2d04c3b17a46c803855241275 [file] [log] [blame]
mukesh agrawalb54601c2011-06-07 17:39:22 -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_SERVICE_
6#define SHILL_WIFI_SERVICE_
7
8#include <string>
9#include <vector>
10
Darin Petkov4a09b6b2011-07-19 12:52:06 -070011#include "shill/dbus_bindings/supplicant-interface.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070012#include "shill/event_dispatcher.h"
Chris Masone2b105542011-06-22 10:58:09 -070013#include "shill/refptr_types.h"
mukesh agrawalb54601c2011-06-07 17:39:22 -070014#include "shill/service.h"
mukesh agrawalb54601c2011-06-07 17:39:22 -070015
16namespace shill {
17
Chris Masone6791a432011-07-12 13:23:19 -070018class ControlInterface;
19class EventDispatcher;
mukesh agrawal1a056262011-10-05 14:36:54 -070020class Error;
Chris Masone6791a432011-07-12 13:23:19 -070021class Manager;
22
mukesh agrawalb54601c2011-06-07 17:39:22 -070023class WiFiService : public Service {
24 public:
25 WiFiService(ControlInterface *control_interface,
26 EventDispatcher *dispatcher,
Chris Masone6791a432011-07-12 13:23:19 -070027 Manager *manager,
Chris Masone2b105542011-06-22 10:58:09 -070028 const WiFiRefPtr &device,
mukesh agrawal7ec71312011-11-10 02:08:26 +000029 const std::vector<uint8_t> &ssid,
Chris Masone092df3e2011-08-22 09:41:39 -070030 const std::string &mode,
Paul Stewartced6a0b2011-11-08 15:32:04 -080031 const std::string &security,
32 bool hidden_ssid);
mukesh agrawalb54601c2011-06-07 17:39:22 -070033 ~WiFiService();
Darin Petkov4d6d9412011-08-24 13:19:54 -070034
35 // Inherited from Service.
36 virtual void Connect(Error *error);
37 virtual void Disconnect();
Chris Masone34af2182011-08-22 11:59:36 -070038
Paul Stewart22aa71b2011-09-16 12:15:11 -070039 virtual bool TechnologyIs(const Technology::Identifier type) const;
40
Chris Masone34af2182011-08-22 11:59:36 -070041 // wifi_<MAC>_<BSSID>_<mode_string>_<security_string>
Chris Masone6515aab2011-10-12 16:19:09 -070042 std::string GetStorageIdentifier() const;
Paul Stewarta41e38d2011-11-11 07:47:29 -080043 static bool ParseStorageIdentifier(const std::string &storage_name,
44 std::string *address,
45 std::string *mode,
46 std::string *security);
Chris Masone34af2182011-08-22 11:59:36 -070047
Chris Masone092df3e2011-08-22 09:41:39 -070048 const std::string &mode() const;
mukesh agrawal445e72c2011-06-22 11:13:50 -070049 const std::string &key_management() const;
50 const std::vector<uint8_t> &ssid() const;
mukesh agrawalb54601c2011-06-07 17:39:22 -070051
mukesh agrawal1a056262011-10-05 14:36:54 -070052 void SetPassphrase(const std::string &passphrase, Error *error);
53
Paul Stewartd08f4432011-11-04 07:48:20 -070054 // Overrride Load and Save from parent Service class. We will call
55 // the parent method.
56 virtual bool IsLoadableFrom(StoreInterface *storage) const;
57 virtual bool Load(StoreInterface *storage);
58 virtual bool Save(StoreInterface *storage);
59
Paul Stewarta41e38d2011-11-11 07:47:29 -080060 virtual bool IsVisible() const;
Paul Stewart6ab23a92011-11-09 17:17:47 -080061 bool IsSecurityMatch(const std::string &security) const;
Paul Stewartced6a0b2011-11-08 15:32:04 -080062 bool hidden_ssid() const { return hidden_ssid_; }
63
mukesh agrawalb54601c2011-06-07 17:39:22 -070064 private:
Paul Stewartd08f4432011-11-04 07:48:20 -070065 friend class WiFiServiceSecurityTest;
mukesh agrawalf2fd7452011-10-03 16:38:47 -070066 FRIEND_TEST(WiFiServiceTest, ConnectTaskRSN);
67 FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA);
Gaurav Shahf8721ee2011-11-07 09:12:46 -080068 FRIEND_TEST(WiFiServiceTest, ConnectTaskPSK);
Thieu Lef4cbda92011-11-10 23:41:24 +000069 FRIEND_TEST(WiFiServiceTest, ConnectTaskWEP);
Paul Stewartd08f4432011-11-04 07:48:20 -070070 FRIEND_TEST(WiFiServiceTest, LoadHidden);
71
72 static const char kStorageHiddenSSID[];
mukesh agrawal6e277772011-09-29 15:04:23 -070073
Thieu Lef7709452011-11-15 01:13:19 +000074 void HelpRegisterDerivedString(
75 PropertyStore *store,
76 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -080077 std::string(WiFiService::*get)(Error *error),
78 void(WiFiService::*set)(const std::string &value, Error *error));
Thieu Lef7709452011-11-15 01:13:19 +000079
mukesh agrawaldc42bb32011-07-28 10:40:26 -070080 void ConnectTask();
mukesh agrawalb54601c2011-06-07 17:39:22 -070081
Gaurav Shah1b7a6162011-11-09 11:41:01 -080082 std::string GetDeviceRpcId(Error *error);
mukesh agrawal29c13a12011-11-24 00:09:19 +000083 void UpdateConnectable();
Chris Masone95207da2011-06-29 16:50:49 -070084
Thieu Lef4cbda92011-11-10 23:41:24 +000085 static void ValidateWEPPassphrase(const std::string &passphrase,
86 Error *error);
87 static void ValidateWPAPassphrase(const std::string &passphrase,
88 Error *error);
89 static void ParseWEPPassphrase(const std::string &passphrase,
90 int *key_index,
91 std::vector<uint8> *password_bytes,
92 Error *error);
mukesh agrawal1a056262011-10-05 14:36:54 -070093 static bool CheckWEPIsHex(const std::string &passphrase, Error *error);
94 static bool CheckWEPKeyIndex(const std::string &passphrase, Error *error);
95 static bool CheckWEPPrefix(const std::string &passphrase, Error *error);
96
mukesh agrawald835b202011-10-07 15:26:47 -070097 // replace non-ASCII characters with '?'. return true if one or more
98 // characters were changed
99 static bool SanitizeSSID(std::string *ssid);
100
Paul Stewart6ab23a92011-11-09 17:17:47 -0800101 // "wpa", "rsn" and "psk" are equivalent from a configuration perspective.
102 // This function maps them all into "psk".
103 static std::string GetSecurityClass(const std::string &security);
104
Paul Stewartd08f4432011-11-04 07:48:20 -0700105 // Profile data for a WPA/RSN service can be stored under a number of
106 // different names. These functions create different storage identifiers
107 // based on whether they are referred to by their generic "psk" name or
108 // if they use the (legacy) specific "wpa" or "rsn" names.
109 std::string GetGenericStorageIdentifier() const;
110 std::string GetSpecificStorageIdentifier() const;
111 std::string GetStorageIdentifierForSecurity(
112 const std::string &security) const;
113
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700114 // Properties
115 std::string passphrase_;
116 bool need_passphrase_;
117 std::string security_;
118 uint8 strength_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700119 // TODO(cmasone): see if the below can be pulled from the endpoint associated
120 // with this service instead.
Chris Masone092df3e2011-08-22 09:41:39 -0700121 const std::string mode_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700122 std::string auth_mode_;
123 bool hidden_ssid_;
124 uint16 frequency_;
125 uint16 physical_mode_;
mukesh agrawal32399322011-09-01 10:53:43 -0700126 std::string hex_ssid_;
Paul Stewartd08f4432011-11-04 07:48:20 -0700127 std::string storage_identifier_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700128
mukesh agrawalb54601c2011-06-07 17:39:22 -0700129 ScopedRunnableMethodFactory<WiFiService> task_factory_;
Chris Masone2b105542011-06-22 10:58:09 -0700130 WiFiRefPtr wifi_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700131 const std::vector<uint8_t> ssid_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700132 DISALLOW_COPY_AND_ASSIGN(WiFiService);
133};
134
135} // namespace shill
136
137#endif // SHILL_WIFI_SERVICE_