blob: a12b11151e423f6ab3f1b432113d6d4205f30a6d [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#include "shill/wifi_service.h"
6
7#include <string>
8
9#include <base/logging.h>
10
11#include "shill/control_interface.h"
12#include "shill/device.h"
13#include "shill/shill_event.h"
14#include "shill/wifi.h"
15
16using std::string;
17
18namespace shill {
19const char WiFiService::kSupplicantPropertySSID[] = "ssid";
20const char WiFiService::kSupplicantPropertyNetworkMode[] = "mode";
21const char WiFiService::kSupplicantPropertyKeyMode[] = "key_mgmt";
22
23WiFiService::WiFiService(ControlInterface *control_interface,
24 EventDispatcher *dispatcher,
25 WiFi *device,
26 const std::vector<uint8_t> ssid,
27 uint32_t mode,
28 const std::string &key_management,
29 const std::string &name)
30 : Service(control_interface, dispatcher, device, name),
31 task_factory_(this),
32 wifi_(device),
33 ssid_(ssid),
34 mode_(mode),
35 key_management_(key_management) {
36}
37
38WiFiService::~WiFiService() {
39 LOG(INFO) << __func__;
40}
41
42void WiFiService::Connect() {
43 LOG(INFO) << __func__;
44
45 // NB(quiche) defer handling, since dbus-c++ does not permit us to
46 // send an outbound request while processing an inbound one.
47 dispatcher_->PostTask(
48 task_factory_.NewRunnableMethod(&WiFiService::RealConnect));
49}
50
51void WiFiService::RealConnect() {
52 std::map<string, DBus::Variant> add_network_args;
53 DBus::MessageIter mi;
54 DBus::Path network_path;
55
56 add_network_args[kSupplicantPropertyNetworkMode].writer().
57 append_uint32(mode_);
58 add_network_args[kSupplicantPropertyKeyMode].writer().
59 append_string(key_management_.c_str());
60 // TODO(quiche): figure out why we can't use operator<< without the
61 // temporary variable.
62 mi = add_network_args[kSupplicantPropertySSID].writer();
63 mi << ssid_;
64 // TODO(quiche): set scan_ssid=1, like flimflam does?
65
66 network_path = wifi_->AddNetwork(add_network_args);
67 wifi_->SelectNetwork(network_path);
68 // XXX add to favorite networks list?
69}
70
71void WiFiService::Disconnect() {
72 // TODO(quiche) RemoveNetwork from supplicant
73 // XXX remove from favorite networks list?
74}
75
76} // namespace shill