cdada7d8973ca8dc0ffdd0ae754d33e67af21235
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / esp8089 / esp_driver / esp_cfg80211.c
1 /*
2  * Copyright (c) 2010 - 2012 Espressif System.
3  */
4 #if 0
5 #define RATETAB_ENT(_rate, _rateid, _flags) {   \
6         .bitrate    = (_rate),                  \
7         .flags      = (_flags),                 \
8         .hw_value   = (_rateid),                \
9 }
10
11 #define CHAN2G(_channel, _freq, _flags) {   \
12         .band           = IEEE80211_BAND_2GHZ,  \
13         .hw_value       = (_channel),           \
14         .center_freq    = (_freq),              \
15         .flags          = (_flags),             \
16         .max_antenna_gain   = 0,                \
17         .max_power      = 30,                   \
18 }
19
20 static struct ieee80211_channel esp_2ghz_channels[] = {
21         CHAN2G(1, 2412, 0),
22         CHAN2G(2, 2417, 0),
23         CHAN2G(3, 2422, 0),
24         CHAN2G(4, 2427, 0),
25         CHAN2G(5, 2432, 0),
26         CHAN2G(6, 2437, 0),
27         CHAN2G(7, 2442, 0),
28         CHAN2G(8, 2447, 0),
29         CHAN2G(9, 2452, 0),
30         CHAN2G(10, 2457, 0),
31         CHAN2G(11, 2462, 0),
32         CHAN2G(12, 2467, 0),
33         CHAN2G(13, 2472, 0),
34         CHAN2G(14, 2484, 0),
35 };
36
37 static int esp_cfg80211_change_iface(struct wiphy *wiphy,
38                                      struct net_device *ndev,
39                                      enum nl80211_iftype type, u32 *flags,
40                                      struct vif_params *params)
41 {
42         struct esp_pub *epub = wdev_priv(dev->ieee80211_ptr);
43         struct wireless_dev *wdev = epub->wdev;
44
45
46         /* only support STA mode for now */
47         if (type != NL80211_IFTYPE_STATION)
48                 return -EOPNOTSUPP;
49 }
50
51 wdev->iftype = type;
52
53 return 0;
54 }
55
56 static int esp_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
57                              struct cfg80211_scan_request *request)
58 {
59         struct esp_pub *epub = wdev_priv(dev->ieee80211_ptr);
60         int ret = 0;
61
62         if (!esp_ready(ar))
63                 return -EIO;
64
65         if (request->n_ssids && request->ssids[0].ssid_len) {
66                 u8 i;
67
68                 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
69                         request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
70
71                 for (i = 0; i < request->n_ssids; i++)
72                         esp_wl_probedssid_cmd(epub->wl, i + 1,
73                                               SPECIFIC_SSID_FLAG,
74                                               request->ssids[i].ssid_len,
75                                               request->ssids[i].ssid);
76         }
77
78         if (esp_wl_startscan_cmd(epub->wl, WL_LONG_SCAN, 0,
79                                  false, 0, 0, 0, NULL) != 0) {
80                 esp_dbg(ESP_DBG_ERROR, "wl_startscan_cmd failed\n");
81                 ret = -EIO;
82         }
83
84         epub->wl->scan_req = request;
85
86         return ret;
87 }
88
89 static struct cfg80211_ops esp_cfg80211_ops = {
90         .change_virtual_intf = esp_cfg80211_change_iface,
91         .scan = esp_cfg80211_scan,
92         .connect = esp_cfg80211_connect,
93         .disconnect = esp_cfg80211_disconnect,
94         .add_key = esp_cfg80211_add_key,
95         .get_key = esp_cfg80211_get_key,
96         .del_key = esp_cfg80211_del_key,
97         .set_default_key = esp_cfg80211_set_default_key,
98         .set_wiphy_params = esp_cfg80211_set_wiphy_params,
99         .set_tx_power = esp_cfg80211_set_txpower,
100         .get_tx_power = esp_cfg80211_get_txpower,
101         .set_power_mgmt = esp_cfg80211_set_power_mgmt,
102         .join_ibss = esp_cfg80211_join_ibss,
103         .leave_ibss = esp_cfg80211_leave_ibss,
104         .get_station = esp_get_station,
105         .set_pmksa = esp_set_pmksa,
106         .del_pmksa = esp_del_pmksa,
107         .flush_pmksa = esp_flush_pmksa,
108 };
109
110 static struct ieee80211_ops esp_ieee80211_ops = {
111 }
112
113 static struct cfg80211_ops esp_cfg80211_ops = {0};
114
115 static struct ieee80211_rate esp_g_rates[] = {
116         RATETAB_ENT(10, 0x1, 0),
117         RATETAB_ENT(20, 0x2, 0),
118         RATETAB_ENT(55, 0x4, 0),
119         RATETAB_ENT(110, 0x8, 0),
120         RATETAB_ENT(60, 0x10, 0),
121         RATETAB_ENT(90, 0x20, 0),
122         RATETAB_ENT(120, 0x40, 0),
123         RATETAB_ENT(180, 0x80, 0),
124         RATETAB_ENT(240, 0x100, 0),
125         RATETAB_ENT(360, 0x200, 0),
126         RATETAB_ENT(480, 0x400, 0),
127         RATETAB_ENT(540, 0x800, 0),
128 };
129
130 #define esp_g_rates_size 12
131 static struct ieee80211_supported_band esp_band_2ghz = {
132         .n_channels = ARRAY_SIZE(esp_2ghz_channels),
133         .channels = esp_2ghz_channels,
134         .n_bitrates = esp_g_rates_size,
135         .bitrates = esp_g_rates,
136 };
137
138 static const u32 cipher_suites[] = {
139         WLAN_CIPHER_SUITE_WEP40,
140         WLAN_CIPHER_SUITE_WEP104,
141         WLAN_CIPHER_SUITE_TKIP,
142         WLAN_CIPHER_SUITE_CCMP,
143 };
144
145 static struct wireless_dev *
146 esp_cfg80211_init(struct device *dev) {
147         int ret = 0;
148         struct wireless_dev *wdev;
149
150         wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
151
152         if (!wdev) {
153                 esp_dbg(ESP_DBG_ERROR, "couldn't allocate wireless device\n");
154                 return NULL;
155         }
156
157         wdev->wiphy = wiphy_new(&esp_cfg80211_ops, sizeof(struct esp_pub));
158
159         if (!wdev->wiphy) {
160                 esp_dbg(ESP_DBG_ERROR, "couldn't allocate wiphy device\n");
161                 kfree(wdev);
162                 return NULL;
163         }
164
165         set_wiphy_dev(wdev->wiphy, dev);
166
167         wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
168         wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
169         wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &esp_band_2ghz;
170         //wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &esp_band_5ghz;
171         wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
172
173         wdev->wiphy->cipher_suites = cipher_suites;
174         wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
175
176         ret = wiphy_register(wdev->wiphy);
177
178         if (ret < 0) {
179                 esp_dbg(ESP_DBG_ERROR, "couldn't register wiphy device\n");
180                 wiphy_free(wdev->wiphy);
181                 kfree(wdev);
182                 return NULL;
183         }
184
185         return wdev;
186 }
187
188 static void
189 esp_cfg80211_descory(struct esp_pub *pub)
190 {
191         return;
192 }
193
194 static int esp_open(struct net_device *dev)
195 {
196         return 0;
197 }
198
199 static struct net_device_stats *
200 esp_get_stats(struct net_device *dev) {
201         struct net_device_stats *stats = NULL;
202         return stats;
203 }
204
205 static int esp_close(struct net_device *dev)
206 {
207         return 0;
208 }
209
210
211 static int esp_data_tx(struct sk_buff *skb, struct net_device *dev)
212 {
213         return 0;
214 }
215
216 static struct net_device_ops esp_netdev_ops = {
217         .ndo_open               = esp_open,
218         .ndo_stop               = esp_close,
219         .ndo_start_xmit         = esp_data_tx,
220         .ndo_get_stats          = esp_get_stats,
221 };
222
223 static inline void
224 esp_init_netdev(struct net_device *dev)
225 {
226         dev->netdev_ops = &esp_netdev_ops;
227         dev->watchdog_timeo = 10;
228
229         dev->needed_headroom = ETH_HLEN + sizeof(struct llc_snap_hdr) + SIP_HDR_LEN;
230
231         return;
232 }
233
234 static void
235 esp_disconnect(struct esp_pub *epub)
236 {
237         return;
238 }
239
240 static void
241 esp_disconnect_timeout_handler(unsigned long ptr)
242 {
243         struct net_device *netdev = (struct net_device *)ptr;
244         struct esp_pub *epub = wdev_priv(netdev->ieee80211_ptr);
245
246         //esp_init_profile(epub);
247         esp_disconnect(epub);
248 }
249
250 struct esp_pub *
251 esp_pub_alloc_cfg80211(struct device *dev) {
252         struct net_device *netdev;
253         struct wireless_dev *wdev;
254         struct esp_pub *epub;
255         struct esp_wl *wl;
256
257         wdev = esp_cfg80211_init(dev);
258
259         if (wdev == NULL) {
260                 esp_dbg(ESP_DBG_ERROR, "%s: cfg80211_init failed \n", __func__);
261                 return NULL;
262         }
263
264         epub = wdev_priv(wdev);
265         epub->dev = dev;
266         epub->wdev = wdev;
267         wdev->iftype = NL80211_IFTYPE_STATION;
268
269         /* Still register ethernet device */
270         netdev = alloc_netdev(0, "wlan%d", ether_setup);
271
272         if (!netdev) {
273                 esp_dbg(ESP_DBG_ERROR, "%s: alloc_netdev failed \n", __func__);
274                 esp_cfg80211_descory(epub);
275                 return NULL;
276         }
277
278         netdev->ieee80211_ptr = wdev;
279         SET_NETDEV_DEV(netdev, wiphy_dev(wdev->wiphy));
280         wdev->netdev = netdev;
281
282         esp_init_netdev(netdev);
283
284         epub->net_dev = netdev;
285
286         //spin_lock_init(&epub->lock);
287
288         wl = &epub->wl;
289         //esp_init_wl(wl);
290         init_waitqueue_head(&epub->ev_waitq);
291         //sema_init(epub->sem, 1);
292
293         INIT_LIST_HEAD(&wl->amsdu_rx_buffer_queue);
294
295         setup_timer(&wl->disconnect_timer, esp_disconnect_timeout_handler,
296                     (unsigned long) netdev);
297
298         return epub;
299 }
300
301 #endif