Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Implement cfg80211 ("iw") support. |
| 3 | * |
| 4 | * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany |
| 5 | * Holger Schurig <hs4233@mail.mn-solutions.de> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <net/cfg80211.h> |
| 10 | |
| 11 | #include "cfg.h" |
| 12 | #include "cmd.h" |
| 13 | |
| 14 | |
| 15 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 16 | .band = IEEE80211_BAND_2GHZ, \ |
| 17 | .center_freq = (_freq), \ |
| 18 | .hw_value = (_channel), \ |
| 19 | .flags = (_flags), \ |
| 20 | .max_antenna_gain = 0, \ |
| 21 | .max_power = 30, \ |
| 22 | } |
| 23 | |
| 24 | static struct ieee80211_channel lbs_2ghz_channels[] = { |
| 25 | CHAN2G(1, 2412, 0), |
| 26 | CHAN2G(2, 2417, 0), |
| 27 | CHAN2G(3, 2422, 0), |
| 28 | CHAN2G(4, 2427, 0), |
| 29 | CHAN2G(5, 2432, 0), |
| 30 | CHAN2G(6, 2437, 0), |
| 31 | CHAN2G(7, 2442, 0), |
| 32 | CHAN2G(8, 2447, 0), |
| 33 | CHAN2G(9, 2452, 0), |
| 34 | CHAN2G(10, 2457, 0), |
| 35 | CHAN2G(11, 2462, 0), |
| 36 | CHAN2G(12, 2467, 0), |
| 37 | CHAN2G(13, 2472, 0), |
| 38 | CHAN2G(14, 2484, 0), |
| 39 | }; |
| 40 | |
| 41 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ |
| 42 | .bitrate = (_rate), \ |
| 43 | .hw_value = (_rateid), \ |
| 44 | .flags = (_flags), \ |
| 45 | } |
| 46 | |
| 47 | |
| 48 | static struct ieee80211_rate lbs_rates[] = { |
| 49 | RATETAB_ENT(10, 0x1, 0), |
| 50 | RATETAB_ENT(20, 0x2, 0), |
| 51 | RATETAB_ENT(55, 0x4, 0), |
| 52 | RATETAB_ENT(110, 0x8, 0), |
| 53 | RATETAB_ENT(60, 0x10, 0), |
| 54 | RATETAB_ENT(90, 0x20, 0), |
| 55 | RATETAB_ENT(120, 0x40, 0), |
| 56 | RATETAB_ENT(180, 0x80, 0), |
| 57 | RATETAB_ENT(240, 0x100, 0), |
| 58 | RATETAB_ENT(360, 0x200, 0), |
| 59 | RATETAB_ENT(480, 0x400, 0), |
| 60 | RATETAB_ENT(540, 0x800, 0), |
| 61 | }; |
| 62 | |
| 63 | static struct ieee80211_supported_band lbs_band_2ghz = { |
| 64 | .channels = lbs_2ghz_channels, |
| 65 | .n_channels = ARRAY_SIZE(lbs_2ghz_channels), |
| 66 | .bitrates = lbs_rates, |
| 67 | .n_bitrates = ARRAY_SIZE(lbs_rates), |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | static const u32 cipher_suites[] = { |
| 72 | WLAN_CIPHER_SUITE_WEP40, |
| 73 | WLAN_CIPHER_SUITE_WEP104, |
| 74 | WLAN_CIPHER_SUITE_TKIP, |
| 75 | WLAN_CIPHER_SUITE_CCMP, |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | |
| 80 | static int lbs_cfg_set_channel(struct wiphy *wiphy, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame^] | 81 | struct net_device *netdev, |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 82 | struct ieee80211_channel *chan, |
| 83 | enum nl80211_channel_type channel_type) |
| 84 | { |
| 85 | struct lbs_private *priv = wiphy_priv(wiphy); |
| 86 | int ret = -ENOTSUPP; |
| 87 | |
| 88 | lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d", chan->center_freq, channel_type); |
| 89 | |
| 90 | if (channel_type != NL80211_CHAN_NO_HT) |
| 91 | goto out; |
| 92 | |
| 93 | ret = lbs_set_channel(priv, chan->hw_value); |
| 94 | |
| 95 | out: |
| 96 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | static struct cfg80211_ops lbs_cfg80211_ops = { |
| 104 | .set_channel = lbs_cfg_set_channel, |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * At this time lbs_private *priv doesn't even exist, so we just allocate |
| 110 | * memory and don't initialize the wiphy further. This is postponed until we |
| 111 | * can talk to the firmware and happens at registration time in |
| 112 | * lbs_cfg_wiphy_register(). |
| 113 | */ |
| 114 | struct wireless_dev *lbs_cfg_alloc(struct device *dev) |
| 115 | { |
| 116 | int ret = 0; |
| 117 | struct wireless_dev *wdev; |
| 118 | |
| 119 | lbs_deb_enter(LBS_DEB_CFG80211); |
| 120 | |
| 121 | wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); |
| 122 | if (!wdev) { |
| 123 | dev_err(dev, "cannot allocate wireless device\n"); |
| 124 | return ERR_PTR(-ENOMEM); |
| 125 | } |
| 126 | |
| 127 | wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private)); |
| 128 | if (!wdev->wiphy) { |
| 129 | dev_err(dev, "cannot allocate wiphy\n"); |
| 130 | ret = -ENOMEM; |
| 131 | goto err_wiphy_new; |
| 132 | } |
| 133 | |
| 134 | lbs_deb_leave(LBS_DEB_CFG80211); |
| 135 | return wdev; |
| 136 | |
| 137 | err_wiphy_new: |
| 138 | kfree(wdev); |
| 139 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); |
| 140 | return ERR_PTR(ret); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
| 145 | * This function get's called after lbs_setup_firmware() determined the |
| 146 | * firmware capabities. So we can setup the wiphy according to our |
| 147 | * hardware/firmware. |
| 148 | */ |
| 149 | int lbs_cfg_register(struct lbs_private *priv) |
| 150 | { |
| 151 | struct wireless_dev *wdev = priv->wdev; |
| 152 | int ret; |
| 153 | |
| 154 | lbs_deb_enter(LBS_DEB_CFG80211); |
| 155 | |
| 156 | wdev->wiphy->max_scan_ssids = 1; |
| 157 | wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; |
| 158 | |
| 159 | /* TODO: BIT(NL80211_IFTYPE_ADHOC); */ |
| 160 | wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
| 161 | |
| 162 | /* TODO: honor priv->regioncode */ |
| 163 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz; |
| 164 | |
| 165 | /* |
| 166 | * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have |
| 167 | * never seen a firmware without WPA |
| 168 | */ |
| 169 | wdev->wiphy->cipher_suites = cipher_suites; |
| 170 | wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 171 | |
| 172 | ret = wiphy_register(wdev->wiphy); |
| 173 | if (ret < 0) |
| 174 | lbs_pr_err("cannot register wiphy device\n"); |
| 175 | |
Daniel Mack | 7371400 | 2010-03-29 17:14:18 +0200 | [diff] [blame] | 176 | priv->wiphy_registered = true; |
| 177 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 178 | ret = register_netdev(priv->dev); |
| 179 | if (ret) |
| 180 | lbs_pr_err("cannot register network device\n"); |
| 181 | |
| 182 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | |
| 187 | void lbs_cfg_free(struct lbs_private *priv) |
| 188 | { |
| 189 | struct wireless_dev *wdev = priv->wdev; |
| 190 | |
| 191 | lbs_deb_enter(LBS_DEB_CFG80211); |
| 192 | |
| 193 | if (!wdev) |
| 194 | return; |
| 195 | |
Daniel Mack | 7371400 | 2010-03-29 17:14:18 +0200 | [diff] [blame] | 196 | if (priv->wiphy_registered) |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 197 | wiphy_unregister(wdev->wiphy); |
Daniel Mack | 7371400 | 2010-03-29 17:14:18 +0200 | [diff] [blame] | 198 | |
| 199 | if (wdev->wiphy) |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 200 | wiphy_free(wdev->wiphy); |
Daniel Mack | 7371400 | 2010-03-29 17:14:18 +0200 | [diff] [blame] | 201 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 202 | kfree(wdev); |
| 203 | } |