nl80211: Add MLME primitives to support external SME
[safe/jmp/linux-2.6] / net / wireless / nl80211.c
index c034c24..9e1318d 100644 (file)
@@ -111,6 +111,11 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
                              .len = IEEE80211_MAX_DATA_LEN },
        [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
        [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
+
+       [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
+                               .len = IEEE80211_MAX_SSID_LEN },
+       [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
+       [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
 };
 
 /* message building helper */
@@ -265,6 +270,10 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
        CMD(set_mesh_params, SET_MESH_PARAMS);
        CMD(change_bss, SET_BSS);
        CMD(set_mgmt_extra_ie, SET_MGMT_EXTRA_IE);
+       CMD(auth, AUTHENTICATE);
+       CMD(assoc, ASSOCIATE);
+       CMD(deauth, DEAUTHENTICATE);
+       CMD(disassoc, DISASSOCIATE);
 
 #undef CMD
        nla_nest_end(msg, nl_cmds);
@@ -2646,6 +2655,228 @@ static int nl80211_dump_scan(struct sk_buff *skb,
        return err;
 }
 
+static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *drv;
+       struct net_device *dev;
+       struct cfg80211_auth_request req;
+       struct wiphy *wiphy;
+       int err;
+
+       rtnl_lock();
+
+       err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
+       if (err)
+               goto unlock_rtnl;
+
+       if (!drv->ops->auth) {
+               err = -EOPNOTSUPP;
+               goto out;
+       }
+
+       if (!info->attrs[NL80211_ATTR_MAC]) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       wiphy = &drv->wiphy;
+       memset(&req, 0, sizeof(req));
+
+       req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
+
+       if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
+               req.chan = ieee80211_get_channel(
+                       wiphy,
+                       nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
+               if (!req.chan) {
+                       err = -EINVAL;
+                       goto out;
+               }
+       }
+
+       if (info->attrs[NL80211_ATTR_SSID]) {
+               req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
+               req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
+       }
+
+       if (info->attrs[NL80211_ATTR_IE]) {
+               req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
+               req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
+       }
+
+       if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
+               req.auth_type =
+                       nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
+       }
+
+       err = drv->ops->auth(&drv->wiphy, dev, &req);
+
+out:
+       cfg80211_put_dev(drv);
+       dev_put(dev);
+unlock_rtnl:
+       rtnl_unlock();
+       return err;
+}
+
+static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *drv;
+       struct net_device *dev;
+       struct cfg80211_assoc_request req;
+       struct wiphy *wiphy;
+       int err;
+
+       rtnl_lock();
+
+       err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
+       if (err)
+               goto unlock_rtnl;
+
+       if (!drv->ops->assoc) {
+               err = -EOPNOTSUPP;
+               goto out;
+       }
+
+       if (!info->attrs[NL80211_ATTR_MAC] ||
+           !info->attrs[NL80211_ATTR_SSID]) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       wiphy = &drv->wiphy;
+       memset(&req, 0, sizeof(req));
+
+       req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
+
+       if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
+               req.chan = ieee80211_get_channel(
+                       wiphy,
+                       nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
+               if (!req.chan) {
+                       err = -EINVAL;
+                       goto out;
+               }
+       }
+
+       if (nla_len(info->attrs[NL80211_ATTR_SSID]) > IEEE80211_MAX_SSID_LEN) {
+               err = -EINVAL;
+               goto out;
+       }
+       req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
+       req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
+
+       if (info->attrs[NL80211_ATTR_IE]) {
+               req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
+               req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
+       }
+
+       err = drv->ops->assoc(&drv->wiphy, dev, &req);
+
+out:
+       cfg80211_put_dev(drv);
+       dev_put(dev);
+unlock_rtnl:
+       rtnl_unlock();
+       return err;
+}
+
+static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *drv;
+       struct net_device *dev;
+       struct cfg80211_deauth_request req;
+       struct wiphy *wiphy;
+       int err;
+
+       rtnl_lock();
+
+       err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
+       if (err)
+               goto unlock_rtnl;
+
+       if (!drv->ops->deauth) {
+               err = -EOPNOTSUPP;
+               goto out;
+       }
+
+       if (!info->attrs[NL80211_ATTR_MAC]) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       wiphy = &drv->wiphy;
+       memset(&req, 0, sizeof(req));
+
+       req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
+
+       if (info->attrs[NL80211_ATTR_REASON_CODE])
+               req.reason_code =
+                       nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
+
+       if (info->attrs[NL80211_ATTR_IE]) {
+               req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
+               req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
+       }
+
+       err = drv->ops->deauth(&drv->wiphy, dev, &req);
+
+out:
+       cfg80211_put_dev(drv);
+       dev_put(dev);
+unlock_rtnl:
+       rtnl_unlock();
+       return err;
+}
+
+static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *drv;
+       struct net_device *dev;
+       struct cfg80211_disassoc_request req;
+       struct wiphy *wiphy;
+       int err;
+
+       rtnl_lock();
+
+       err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
+       if (err)
+               goto unlock_rtnl;
+
+       if (!drv->ops->disassoc) {
+               err = -EOPNOTSUPP;
+               goto out;
+       }
+
+       if (!info->attrs[NL80211_ATTR_MAC]) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       wiphy = &drv->wiphy;
+       memset(&req, 0, sizeof(req));
+
+       req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
+
+       if (info->attrs[NL80211_ATTR_REASON_CODE])
+               req.reason_code =
+                       nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
+
+       if (info->attrs[NL80211_ATTR_IE]) {
+               req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
+               req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
+       }
+
+       err = drv->ops->disassoc(&drv->wiphy, dev, &req);
+
+out:
+       cfg80211_put_dev(drv);
+       dev_put(dev);
+unlock_rtnl:
+       rtnl_unlock();
+       return err;
+}
+
 static struct genl_ops nl80211_ops[] = {
        {
                .cmd = NL80211_CMD_GET_WIPHY,
@@ -2829,6 +3060,30 @@ static struct genl_ops nl80211_ops[] = {
                .policy = nl80211_policy,
                .dumpit = nl80211_dump_scan,
        },
+       {
+               .cmd = NL80211_CMD_AUTHENTICATE,
+               .doit = nl80211_authenticate,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+       },
+       {
+               .cmd = NL80211_CMD_ASSOCIATE,
+               .doit = nl80211_associate,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+       },
+       {
+               .cmd = NL80211_CMD_DEAUTHENTICATE,
+               .doit = nl80211_deauthenticate,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+       },
+       {
+               .cmd = NL80211_CMD_DISASSOCIATE,
+               .doit = nl80211_disassociate,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+       },
 };
 static struct genl_multicast_group nl80211_mlme_mcgrp = {
        .name = "mlme",