diff options
author | colin@cozybit.com <colin@cozybit.com> | 2008-10-21 15:03:48 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-10-31 19:00:39 -0400 |
commit | 93da9cc17c5ae8a751886fd4732db89ad5e9bdb9 (patch) | |
tree | 5c8c16eaeca4c6e4555682a4ab1b448cdbe21595 /net/wireless | |
parent | 4a68ec535ef1043319928f601d633f78e650a16f (diff) |
Add nl80211 commands to get and set o11s mesh networking parameters
The two new commands are NL80211_CMD_GET_MESH_PARAMS and
NL80211_CMD_SET_MESH_PARAMS. There is a new attribute enum,
NL80211_ATTR_MESH_PARAMS, which enumerates the various mesh configuration
parameters.
Moved struct mesh_config from mac80211/ieee80211_i.h to net/cfg80211.h.
nl80211_get_mesh_params and nl80211_set_mesh_params unpack the netlink messages
and ask the driver to get or set the configuration. This is done via two new
function stubs, get_mesh_params and set_mesh_params, in struct cfg80211_ops.
Signed-off-by: Colin McCabe <colin@cozybit.com>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/wireless')
-rw-r--r-- | net/wireless/nl80211.c | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 2b87aec231ea..9a16e9e6c5ca 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -96,6 +96,8 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { | |||
96 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | 96 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
97 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | 97 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
98 | 98 | ||
99 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, | ||
100 | |||
99 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, | 101 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
100 | .len = NL80211_HT_CAPABILITY_LEN }, | 102 | .len = NL80211_HT_CAPABILITY_LEN }, |
101 | }; | 103 | }; |
@@ -1698,6 +1700,183 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |||
1698 | return r; | 1700 | return r; |
1699 | } | 1701 | } |
1700 | 1702 | ||
1703 | static int nl80211_get_mesh_params(struct sk_buff *skb, | ||
1704 | struct genl_info *info) | ||
1705 | { | ||
1706 | struct cfg80211_registered_device *drv; | ||
1707 | struct mesh_config cur_params; | ||
1708 | int err; | ||
1709 | struct net_device *dev; | ||
1710 | void *hdr; | ||
1711 | struct nlattr *pinfoattr; | ||
1712 | struct sk_buff *msg; | ||
1713 | |||
1714 | /* Look up our device */ | ||
1715 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | ||
1716 | if (err) | ||
1717 | return err; | ||
1718 | |||
1719 | /* Get the mesh params */ | ||
1720 | rtnl_lock(); | ||
1721 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); | ||
1722 | rtnl_unlock(); | ||
1723 | if (err) | ||
1724 | goto out; | ||
1725 | |||
1726 | /* Draw up a netlink message to send back */ | ||
1727 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
1728 | if (!msg) { | ||
1729 | err = -ENOBUFS; | ||
1730 | goto out; | ||
1731 | } | ||
1732 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | ||
1733 | NL80211_CMD_GET_MESH_PARAMS); | ||
1734 | if (!hdr) | ||
1735 | goto nla_put_failure; | ||
1736 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); | ||
1737 | if (!pinfoattr) | ||
1738 | goto nla_put_failure; | ||
1739 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | ||
1740 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | ||
1741 | cur_params.dot11MeshRetryTimeout); | ||
1742 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | ||
1743 | cur_params.dot11MeshConfirmTimeout); | ||
1744 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | ||
1745 | cur_params.dot11MeshHoldingTimeout); | ||
1746 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | ||
1747 | cur_params.dot11MeshMaxPeerLinks); | ||
1748 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | ||
1749 | cur_params.dot11MeshMaxRetries); | ||
1750 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | ||
1751 | cur_params.dot11MeshTTL); | ||
1752 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | ||
1753 | cur_params.auto_open_plinks); | ||
1754 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | ||
1755 | cur_params.dot11MeshHWMPmaxPREQretries); | ||
1756 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | ||
1757 | cur_params.path_refresh_time); | ||
1758 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | ||
1759 | cur_params.min_discovery_timeout); | ||
1760 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | ||
1761 | cur_params.dot11MeshHWMPactivePathTimeout); | ||
1762 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | ||
1763 | cur_params.dot11MeshHWMPpreqMinInterval); | ||
1764 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | ||
1765 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | ||
1766 | nla_nest_end(msg, pinfoattr); | ||
1767 | genlmsg_end(msg, hdr); | ||
1768 | err = genlmsg_unicast(msg, info->snd_pid); | ||
1769 | goto out; | ||
1770 | |||
1771 | nla_put_failure: | ||
1772 | genlmsg_cancel(msg, hdr); | ||
1773 | err = -EMSGSIZE; | ||
1774 | out: | ||
1775 | /* Cleanup */ | ||
1776 | cfg80211_put_dev(drv); | ||
1777 | dev_put(dev); | ||
1778 | return err; | ||
1779 | } | ||
1780 | |||
1781 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | ||
1782 | do {\ | ||
1783 | if (table[attr_num]) {\ | ||
1784 | cfg.param = nla_fn(table[attr_num]); \ | ||
1785 | mask |= (1 << (attr_num - 1)); \ | ||
1786 | } \ | ||
1787 | } while (0);\ | ||
1788 | |||
1789 | static struct nla_policy | ||
1790 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { | ||
1791 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, | ||
1792 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | ||
1793 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | ||
1794 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | ||
1795 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | ||
1796 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | ||
1797 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | ||
1798 | |||
1799 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | ||
1800 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | ||
1801 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | ||
1802 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | ||
1803 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | ||
1804 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | ||
1805 | }; | ||
1806 | |||
1807 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | ||
1808 | { | ||
1809 | int err; | ||
1810 | u32 mask; | ||
1811 | struct cfg80211_registered_device *drv; | ||
1812 | struct net_device *dev; | ||
1813 | struct mesh_config cfg; | ||
1814 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | ||
1815 | struct nlattr *parent_attr; | ||
1816 | |||
1817 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; | ||
1818 | if (!parent_attr) | ||
1819 | return -EINVAL; | ||
1820 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | ||
1821 | parent_attr, nl80211_meshconf_params_policy)) | ||
1822 | return -EINVAL; | ||
1823 | |||
1824 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | ||
1825 | if (err) | ||
1826 | return err; | ||
1827 | |||
1828 | /* This makes sure that there aren't more than 32 mesh config | ||
1829 | * parameters (otherwise our bitfield scheme would not work.) */ | ||
1830 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | ||
1831 | |||
1832 | /* Fill in the params struct */ | ||
1833 | mask = 0; | ||
1834 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, | ||
1835 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | ||
1836 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | ||
1837 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | ||
1838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | ||
1839 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | ||
1840 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | ||
1841 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | ||
1842 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | ||
1843 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | ||
1844 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | ||
1845 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | ||
1846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, | ||
1847 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | ||
1848 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | ||
1849 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | ||
1850 | nla_get_u8); | ||
1851 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | ||
1852 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | ||
1853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | ||
1854 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | ||
1855 | nla_get_u16); | ||
1856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | ||
1857 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | ||
1858 | nla_get_u32); | ||
1859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | ||
1860 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | ||
1861 | nla_get_u16); | ||
1862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | ||
1863 | dot11MeshHWMPnetDiameterTraversalTime, | ||
1864 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | ||
1865 | nla_get_u16); | ||
1866 | |||
1867 | /* Apply changes */ | ||
1868 | rtnl_lock(); | ||
1869 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); | ||
1870 | rtnl_unlock(); | ||
1871 | |||
1872 | /* cleanup */ | ||
1873 | cfg80211_put_dev(drv); | ||
1874 | dev_put(dev); | ||
1875 | return err; | ||
1876 | } | ||
1877 | |||
1878 | #undef FILL_IN_MESH_PARAM_IF_SET | ||
1879 | |||
1701 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | 1880 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
1702 | { | 1881 | { |
1703 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | 1882 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
@@ -1915,6 +2094,18 @@ static struct genl_ops nl80211_ops[] = { | |||
1915 | .policy = nl80211_policy, | 2094 | .policy = nl80211_policy, |
1916 | .flags = GENL_ADMIN_PERM, | 2095 | .flags = GENL_ADMIN_PERM, |
1917 | }, | 2096 | }, |
2097 | { | ||
2098 | .cmd = NL80211_CMD_GET_MESH_PARAMS, | ||
2099 | .doit = nl80211_get_mesh_params, | ||
2100 | .policy = nl80211_policy, | ||
2101 | /* can be retrieved by unprivileged users */ | ||
2102 | }, | ||
2103 | { | ||
2104 | .cmd = NL80211_CMD_SET_MESH_PARAMS, | ||
2105 | .doit = nl80211_set_mesh_params, | ||
2106 | .policy = nl80211_policy, | ||
2107 | .flags = GENL_ADMIN_PERM, | ||
2108 | }, | ||
1918 | }; | 2109 | }; |
1919 | 2110 | ||
1920 | /* multicast groups */ | 2111 | /* multicast groups */ |