repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [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 | #ifndef SHILL_ATTRIBUTE_LIST_H_ |
| 6 | #define SHILL_ATTRIBUTE_LIST_H_ |
| 7 | |
| 8 | #include <linux/nl80211.h> |
| 9 | #include <netlink/netlink.h> |
| 10 | |
| 11 | #include <map> |
| 12 | #include <string> |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 13 | #include <tr1/memory> |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 14 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 15 | #include <base/memory/weak_ptr.h> |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 16 | |
| 17 | struct nlattr; |
| 18 | namespace shill { |
| 19 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 20 | class ByteString; |
| 21 | class Nl80211Attribute; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 22 | class Nl80211RawAttribute; |
| 23 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 24 | class AttributeList : public base::SupportsWeakPtr<AttributeList> { |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 25 | public: |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 26 | typedef std::tr1::shared_ptr<Nl80211Attribute> AttributePointer; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 27 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 28 | // Instantiates an Nl80211Attribute of the appropriate type from |id|, |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 29 | // and adds it to |attributes_|. |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 30 | bool CreateAttribute(nl80211_attrs id); |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 31 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 32 | // Instantiates an Nl80211Attribute of the appropriate type from |id|, |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 33 | // initializes it from |data|, and adds it to |attributes_|. |
| 34 | // TODO(wdg): This is a stop-gap for use before message constructors add |
| 35 | // their attributes as message templates. |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 36 | bool CreateAndInitFromNlAttr(nl80211_attrs id, const nlattr *data); |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 37 | |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 38 | std::string ToString() const; |
| 39 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 40 | bool GetU8AttributeValue(int id, uint8_t *value) const; |
| 41 | bool GetU16AttributeValue(int id, uint16_t *value) const; |
| 42 | bool GetU32AttributeValue(int id, uint32_t *value) const; |
| 43 | bool GetU64AttributeValue(int id, uint64_t *value) const; |
| 44 | bool GetFlagAttributeValue(int id, bool *value) const; |
| 45 | // |IsFlagAttributeTrue| returns true if the flag attribute |id| is true. It |
| 46 | // retruns false if the attribute does not exist, is not of type kTypeFlag, |
| 47 | // or is not true. |
| 48 | bool IsFlagAttributeTrue(int id) const; |
| 49 | bool GetStringAttributeValue(int id, std::string *value) const; |
| 50 | bool GetNestedAttributeValue(int id, |
| 51 | base::WeakPtr<AttributeList> *value) const; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 52 | |
| 53 | // A raw attribute is a place to store unrecognized attributes when they |
| 54 | // from the kernel. For this reason, only limited support is provided for |
| 55 | // them. |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 56 | bool GetRawAttributeValue(int id, ByteString *output) const; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 57 | // TODO(wdg): |GetRawAttribute| is a stopgap to support various |
| 58 | // UserBoundNlMessage::ToString methods and must, once those are re-written, |
| 59 | // be destroyed. |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 60 | const Nl80211RawAttribute *GetRawAttribute(int id) const; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 61 | |
| 62 | private: |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 63 | // The Create*Attribute and Set*Attribute methods are specifically for use |
| 64 | // by nested attributes to add their sub-attributes. Classes derived from |
| 65 | // Nl80211NestedAttribute should be added, here. |
| 66 | friend class Nl80211AttributeCqm; |
| 67 | friend class Nl80211AttributeStaInfo; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 68 | |
repo sync | 12cca80 | 2012-12-19 17:34:22 -0800 | [diff] [blame] | 69 | bool CreateU8Attribute(int id, const char *id_string); |
| 70 | bool SetU8AttributeValue(int id, uint8_t value) const; |
| 71 | |
| 72 | bool CreateU16Attribute(int id, const char *id_string); |
| 73 | bool SetU16AttributeValue(int id, uint16_t value) const; |
| 74 | |
| 75 | bool CreateU32Attribute(int id, const char *id_string); |
| 76 | bool SetU32AttributeValue(int id, uint32_t value) const; |
| 77 | |
| 78 | bool CreateU64Attribute(int id, const char *id_string); |
| 79 | bool SetU64AttributeValue(int id, uint64_t value) const; |
| 80 | |
| 81 | bool CreateFlagAttribute(int id, const char *id_string); |
| 82 | bool SetFlagAttributeValue(int id, bool value) const; |
| 83 | |
| 84 | bool CreateStringAttribute(int id, const char *id_string); |
| 85 | bool SetStringAttributeValue(int id, std::string value) const; |
| 86 | |
| 87 | bool CreateNestedAttribute(int id, const char *id_string); |
| 88 | // No |SetNestedAttributeValue| method as it would make no sense. |
| 89 | |
| 90 | // Using this to get around issues with const and operator[]. |
| 91 | Nl80211Attribute *GetAttribute(int id) const; |
| 92 | |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 93 | // TODO(wdg): This is only used to support |GetRawAttribute|. Delete this |
| 94 | // when that goes away. |
| 95 | bool HasRawAttribute(int id) const; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 96 | |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame^] | 97 | std::map<int, AttributePointer> attributes_; |
repo sync | 90ee0fa | 2012-12-18 10:08:08 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace shill |
| 101 | |
| 102 | #endif // SHILL_ATTRIBUTE_LIST_H_ |