Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // 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 | |
| 28 | #include <iomanip> |
| 29 | #include <string> |
| 30 | |
| 31 | #include <linux/nl80211.h> |
| 32 | |
| 33 | #include <base/basictypes.h> |
| 34 | #include <base/bind.h> |
| 35 | |
| 36 | #include "shill/netlink_socket.h" |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 37 | #include "shill/kernel_bound_nlmessage.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 38 | |
| 39 | struct nl_msg; |
| 40 | struct sockaddr_nl; |
| 41 | struct nlmsgerr; |
| 42 | |
| 43 | namespace shill { |
| 44 | |
| 45 | // Provides a mechanism to communicate with the cfg80211 and mac80211 modules |
| 46 | // utilizing a netlink socket. |
| 47 | class Nl80211Socket : public NetlinkSocket { |
| 48 | public: |
| 49 | Nl80211Socket() : nl80211_id_(-1) {} |
| 50 | virtual ~Nl80211Socket() {} |
| 51 | |
| 52 | // Perform non-trivial initialization. |
| 53 | bool Init(); |
| 54 | |
| 55 | // Add ourself to the multicast group that gets sent messages of the |
| 56 | // specificed type. Legal |group_name| character strings are defined by |
| 57 | // cfg80211 module but they include "config", "scan", "regulatory", and |
| 58 | // "mlme". |
| 59 | virtual bool AddGroupMembership(const std::string &group_name); |
| 60 | |
| 61 | // Returns the value returned by the 'genl_ctrl_resolve' call. |
| 62 | int GetFamilyId() const { return nl80211_id_; } |
| 63 | |
| 64 | // Gets the name of the socket family. |
| 65 | std::string GetSocketFamilyName() const { |
| 66 | return Nl80211Socket::kSocketFamilyName; |
| 67 | } |
| 68 | |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 69 | virtual uint32 Send(KernelBoundNlMessage *message); |
| 70 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 71 | private: |
Christopher Wiley | a6032b2 | 2012-11-07 21:34:46 -0800 | [diff] [blame] | 72 | // The family name of this particular netlink socket. |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 73 | static const char kSocketFamilyName[]; |
| 74 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 75 | // The id returned by a call to 'genl_ctrl_resolve'. |
| 76 | int nl80211_id_; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(Nl80211Socket); |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | } // namespace shill |
| 83 | |
| 84 | #endif // SHILL_NL80211_SOCKET_H_ |