blob: 9bfa52560e476ed43ffd98f4f4ea07d38ddbc61c [file] [log] [blame]
Wade Guthrie0d438532012-05-18 14:18:50 -07001// Copyright (c) 2012 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// This code is derived from the 'iw' source code. The copyright and license
6// of that code is as follows:
7//
8// Copyright (c) 2007, 2008 Johannes Berg
9// Copyright (c) 2007 Andy Lutomirski
10// Copyright (c) 2007 Mike Kershaw
11// Copyright (c) 2008-2009 Luis R. Rodriguez
12//
13// Permission to use, copy, modify, and/or distribute this software for any
14// purpose with or without fee is hereby granted, provided that the above
15// copyright notice and this permission notice appear in all copies.
16//
17// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25#ifndef SHILL_NL80211_SOCKET_H_
26#define SHILL_NL80211_SOCKET_H_
27
Wade Guthrie0d438532012-05-18 14:18:50 -070028#include <string>
29
30#include <linux/nl80211.h>
31
32#include <base/basictypes.h>
Wade Guthrie0d438532012-05-18 14:18:50 -070033
34#include "shill/netlink_socket.h"
35
36struct nl_msg;
37struct sockaddr_nl;
38struct nlmsgerr;
39
40namespace shill {
41
42// Provides a mechanism to communicate with the cfg80211 and mac80211 modules
43// utilizing a netlink socket.
44class Nl80211Socket : public NetlinkSocket {
45 public:
repo syncdc085c82012-12-28 08:54:41 -080046 Nl80211Socket() : family_id_(-1) {}
Wade Guthrie0d438532012-05-18 14:18:50 -070047 virtual ~Nl80211Socket() {}
48
49 // Perform non-trivial initialization.
50 bool Init();
51
52 // Add ourself to the multicast group that gets sent messages of the
53 // specificed type. Legal |group_name| character strings are defined by
54 // cfg80211 module but they include "config", "scan", "regulatory", and
55 // "mlme".
56 virtual bool AddGroupMembership(const std::string &group_name);
57
58 // Returns the value returned by the 'genl_ctrl_resolve' call.
repo syncdc085c82012-12-28 08:54:41 -080059 int family_id() const { return family_id_; }
Wade Guthrie0d438532012-05-18 14:18:50 -070060
61 // Gets the name of the socket family.
62 std::string GetSocketFamilyName() const {
63 return Nl80211Socket::kSocketFamilyName;
64 }
65
66 private:
Christopher Wileya6032b22012-11-07 21:34:46 -080067 // The family name of this particular netlink socket.
Wade Guthrie0d438532012-05-18 14:18:50 -070068 static const char kSocketFamilyName[];
69
Wade Guthrie0d438532012-05-18 14:18:50 -070070 // The id returned by a call to 'genl_ctrl_resolve'.
repo syncdc085c82012-12-28 08:54:41 -080071 int family_id_;
Wade Guthrie0d438532012-05-18 14:18:50 -070072
73 DISALLOW_COPY_AND_ASSIGN(Nl80211Socket);
74};
75
76
77} // namespace shill
78
79#endif // SHILL_NL80211_SOCKET_H_