New: mac80211 stack from the wireless-dev tree
[openwrt.git] / package / mac80211 / src / mac80211 / ieee80211_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 "ieee80211_cfg.h"
14
15 static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
16                                unsigned int type)
17 {
18         struct ieee80211_local *local = wiphy_priv(wiphy);
19         int itype;
20
21         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
22                 return -ENODEV;
23
24         switch (type) {
25         case NL80211_IFTYPE_UNSPECIFIED:
26                 itype = IEEE80211_IF_TYPE_STA;
27                 break;
28         case NL80211_IFTYPE_ADHOC:
29                 itype = IEEE80211_IF_TYPE_IBSS;
30                 break;
31         case NL80211_IFTYPE_STATION:
32                 itype = IEEE80211_IF_TYPE_STA;
33                 break;
34         case NL80211_IFTYPE_AP:
35                 itype = IEEE80211_IF_TYPE_AP;
36                 break;
37         case NL80211_IFTYPE_WDS:
38                 itype = IEEE80211_IF_TYPE_WDS;
39                 break;
40         case NL80211_IFTYPE_MONITOR:
41                 itype = IEEE80211_IF_TYPE_MNTR;
42                 break;
43         default:
44                 return -EINVAL;
45         }
46
47         return ieee80211_if_add(local->mdev, name, NULL, itype);
48 }
49
50 static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
51 {
52         struct ieee80211_local *local = wiphy_priv(wiphy);
53         struct net_device *dev;
54         char *name;
55
56         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
57                 return -ENODEV;
58
59         dev = dev_get_by_index(ifindex);
60         if (!dev)
61                 return 0;
62
63         name = dev->name;
64         dev_put(dev);
65
66         return ieee80211_if_remove(local->mdev, name, -1);
67 }
68
69 struct cfg80211_ops mac80211_config_ops = {
70         .add_virtual_intf = ieee80211_add_iface,
71         .del_virtual_intf = ieee80211_del_iface,
72 };