fix up hostapd for mac80211
[openwrt.git] / package / mac80211 / src / net / mac80211 / cfg.c
1 /*
2  * mac80211 configuration hooks for cfg80211
3  *
4  * Copyright 2006       Johannes Berg <johannes@sipsolutions.net>
5  *
6  * This file is GPLv2 as found in COPYING.
7  */
8
9 #include <linux/nl80211.h>
10 #include <linux/rtnetlink.h>
11 #include <net/cfg80211.h>
12 #include "ieee80211_i.h"
13 #include "cfg.h"
14
15 static enum ieee80211_if_types
16 nl80211_type_to_mac80211_type(enum nl80211_iftype type)
17 {
18         switch (type) {
19         case NL80211_IFTYPE_UNSPECIFIED:
20                 return IEEE80211_IF_TYPE_STA;
21         case NL80211_IFTYPE_ADHOC:
22                 return IEEE80211_IF_TYPE_IBSS;
23         case NL80211_IFTYPE_STATION:
24                 return IEEE80211_IF_TYPE_STA;
25         case NL80211_IFTYPE_MONITOR:
26                 return IEEE80211_IF_TYPE_MNTR;
27         default:
28                 return IEEE80211_IF_TYPE_INVALID;
29         }
30 }
31
32 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
33                                enum nl80211_iftype type)
34 {
35         struct ieee80211_local *local = wiphy_priv(wiphy);
36         enum ieee80211_if_types itype;
37
38         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
39                 return -ENODEV;
40
41         itype = nl80211_type_to_mac80211_type(type);
42         if (itype == IEEE80211_IF_TYPE_INVALID)
43                 return -EINVAL;
44
45         return ieee80211_if_add(local->mdev, name, NULL, itype);
46 }
47
48 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
49 {
50         struct ieee80211_local *local = wiphy_priv(wiphy);
51         struct net_device *dev;
52         char *name;
53
54         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
55                 return -ENODEV;
56
57         /* we're under RTNL */
58         dev = __dev_get_by_index(ifindex);
59         if (!dev)
60                 return 0;
61
62         name = dev->name;
63
64         return ieee80211_if_remove(local->mdev, name, -1);
65 }
66
67 static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
68                                   enum nl80211_iftype type)
69 {
70         struct ieee80211_local *local = wiphy_priv(wiphy);
71         struct net_device *dev;
72         enum ieee80211_if_types itype;
73         struct ieee80211_sub_if_data *sdata;
74
75         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
76                 return -ENODEV;
77
78         /* we're under RTNL */
79         dev = __dev_get_by_index(ifindex);
80         if (!dev)
81                 return -ENODEV;
82
83         if (netif_running(dev))
84                 return -EBUSY;
85
86         itype = nl80211_type_to_mac80211_type(type);
87         if (itype == IEEE80211_IF_TYPE_INVALID)
88                 return -EINVAL;
89
90         sdata = IEEE80211_DEV_TO_SUB_IF(dev);
91
92         if (sdata->type == IEEE80211_IF_TYPE_VLAN)
93                 return -EOPNOTSUPP;
94
95         ieee80211_if_reinit(dev);
96         ieee80211_if_set_type(dev, itype);
97
98         return 0;
99 }
100
101 struct cfg80211_ops mac80211_config_ops = {
102         .add_virtual_intf = ieee80211_add_iface,
103         .del_virtual_intf = ieee80211_del_iface,
104         .change_virtual_intf = ieee80211_change_iface,
105 };