2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
9 #include <linux/nl80211.h>
10 #include <linux/rtnetlink.h>
11 #include <net/cfg80211.h>
12 #include "ieee80211_i.h"
15 static enum ieee80211_if_types
16 nl80211_type_to_mac80211_type(enum nl80211_iftype 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
;
28 return IEEE80211_IF_TYPE_INVALID
;
32 static int ieee80211_add_iface(struct wiphy
*wiphy
, char *name
,
33 enum nl80211_iftype type
)
35 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
36 enum ieee80211_if_types itype
;
38 if (unlikely(local
->reg_state
!= IEEE80211_DEV_REGISTERED
))
41 itype
= nl80211_type_to_mac80211_type(type
);
42 if (itype
== IEEE80211_IF_TYPE_INVALID
)
45 return ieee80211_if_add(local
->mdev
, name
, NULL
, itype
);
48 static int ieee80211_del_iface(struct wiphy
*wiphy
, int ifindex
)
50 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
51 struct net_device
*dev
;
54 if (unlikely(local
->reg_state
!= IEEE80211_DEV_REGISTERED
))
57 /* we're under RTNL */
58 dev
= __dev_get_by_index(ifindex
);
64 return ieee80211_if_remove(local
->mdev
, name
, -1);
67 static int ieee80211_change_iface(struct wiphy
*wiphy
, int ifindex
,
68 enum nl80211_iftype type
)
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
;
75 if (unlikely(local
->reg_state
!= IEEE80211_DEV_REGISTERED
))
78 /* we're under RTNL */
79 dev
= __dev_get_by_index(ifindex
);
83 if (netif_running(dev
))
86 itype
= nl80211_type_to_mac80211_type(type
);
87 if (itype
== IEEE80211_IF_TYPE_INVALID
)
90 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
92 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
95 ieee80211_if_reinit(dev
);
96 ieee80211_if_set_type(dev
, itype
);
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
,