2 * Implement cfg80211 ("iw") support.
4 * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
5 * Holger Schurig <hs4233@mail.mn-solutions.de>
9 #include <linux/slab.h>
10 #include <net/cfg80211.h>
16 #define CHAN2G(_channel, _freq, _flags) { \
17 .band = IEEE80211_BAND_2GHZ, \
18 .center_freq = (_freq), \
19 .hw_value = (_channel), \
21 .max_antenna_gain = 0, \
25 static struct ieee80211_channel lbs_2ghz_channels
[] = {
42 #define RATETAB_ENT(_rate, _rateid, _flags) { \
44 .hw_value = (_rateid), \
49 static struct ieee80211_rate lbs_rates
[] = {
50 RATETAB_ENT(10, 0x1, 0),
51 RATETAB_ENT(20, 0x2, 0),
52 RATETAB_ENT(55, 0x4, 0),
53 RATETAB_ENT(110, 0x8, 0),
54 RATETAB_ENT(60, 0x10, 0),
55 RATETAB_ENT(90, 0x20, 0),
56 RATETAB_ENT(120, 0x40, 0),
57 RATETAB_ENT(180, 0x80, 0),
58 RATETAB_ENT(240, 0x100, 0),
59 RATETAB_ENT(360, 0x200, 0),
60 RATETAB_ENT(480, 0x400, 0),
61 RATETAB_ENT(540, 0x800, 0),
64 static struct ieee80211_supported_band lbs_band_2ghz
= {
65 .channels
= lbs_2ghz_channels
,
66 .n_channels
= ARRAY_SIZE(lbs_2ghz_channels
),
67 .bitrates
= lbs_rates
,
68 .n_bitrates
= ARRAY_SIZE(lbs_rates
),
72 static const u32 cipher_suites
[] = {
73 WLAN_CIPHER_SUITE_WEP40
,
74 WLAN_CIPHER_SUITE_WEP104
,
75 WLAN_CIPHER_SUITE_TKIP
,
76 WLAN_CIPHER_SUITE_CCMP
,
81 static int lbs_cfg_set_channel(struct wiphy
*wiphy
,
82 struct net_device
*netdev
,
83 struct ieee80211_channel
*chan
,
84 enum nl80211_channel_type channel_type
)
86 struct lbs_private
*priv
= wiphy_priv(wiphy
);
89 lbs_deb_enter_args(LBS_DEB_CFG80211
, "freq %d, type %d", chan
->center_freq
, channel_type
);
91 if (channel_type
!= NL80211_CHAN_NO_HT
)
94 ret
= lbs_set_channel(priv
, chan
->hw_value
);
97 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
104 static struct cfg80211_ops lbs_cfg80211_ops
= {
105 .set_channel
= lbs_cfg_set_channel
,
110 * At this time lbs_private *priv doesn't even exist, so we just allocate
111 * memory and don't initialize the wiphy further. This is postponed until we
112 * can talk to the firmware and happens at registration time in
113 * lbs_cfg_wiphy_register().
115 struct wireless_dev
*lbs_cfg_alloc(struct device
*dev
)
118 struct wireless_dev
*wdev
;
120 lbs_deb_enter(LBS_DEB_CFG80211
);
122 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
124 dev_err(dev
, "cannot allocate wireless device\n");
125 return ERR_PTR(-ENOMEM
);
128 wdev
->wiphy
= wiphy_new(&lbs_cfg80211_ops
, sizeof(struct lbs_private
));
130 dev_err(dev
, "cannot allocate wiphy\n");
135 lbs_deb_leave(LBS_DEB_CFG80211
);
140 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
146 * This function get's called after lbs_setup_firmware() determined the
147 * firmware capabities. So we can setup the wiphy according to our
150 int lbs_cfg_register(struct lbs_private
*priv
)
152 struct wireless_dev
*wdev
= priv
->wdev
;
155 lbs_deb_enter(LBS_DEB_CFG80211
);
157 wdev
->wiphy
->max_scan_ssids
= 1;
158 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
160 /* TODO: BIT(NL80211_IFTYPE_ADHOC); */
161 wdev
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
163 /* TODO: honor priv->regioncode */
164 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &lbs_band_2ghz
;
167 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
168 * never seen a firmware without WPA
170 wdev
->wiphy
->cipher_suites
= cipher_suites
;
171 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
173 ret
= wiphy_register(wdev
->wiphy
);
175 lbs_pr_err("cannot register wiphy device\n");
177 priv
->wiphy_registered
= true;
179 ret
= register_netdev(priv
->dev
);
181 lbs_pr_err("cannot register network device\n");
183 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
188 void lbs_cfg_free(struct lbs_private
*priv
)
190 struct wireless_dev
*wdev
= priv
->wdev
;
192 lbs_deb_enter(LBS_DEB_CFG80211
);
197 if (priv
->wiphy_registered
)
198 wiphy_unregister(wdev
->wiphy
);
201 wiphy_free(wdev
->wiphy
);