2 * Copyright (c) 2010 - 2012 Espressif System.
5 #define RATETAB_ENT(_rate, _rateid, _flags) { \
8 .hw_value = (_rateid), \
11 #define CHAN2G(_channel, _freq, _flags) { \
12 .band = IEEE80211_BAND_2GHZ, \
13 .hw_value = (_channel), \
14 .center_freq = (_freq), \
16 .max_antenna_gain = 0, \
20 static struct ieee80211_channel esp_2ghz_channels[] = {
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)
42 struct esp_pub *epub = wdev_priv(dev->ieee80211_ptr);
43 struct wireless_dev *wdev = epub->wdev;
46 /* only support STA mode for now */
47 if (type != NL80211_IFTYPE_STATION)
56 static int esp_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
57 struct cfg80211_scan_request *request)
59 struct esp_pub *epub = wdev_priv(dev->ieee80211_ptr);
65 if (request->n_ssids && request->ssids[0].ssid_len) {
68 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
69 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
71 for (i = 0; i < request->n_ssids; i++)
72 esp_wl_probedssid_cmd(epub->wl, i + 1,
74 request->ssids[i].ssid_len,
75 request->ssids[i].ssid);
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");
84 epub->wl->scan_req = request;
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,
110 static struct ieee80211_ops esp_ieee80211_ops = {
113 static struct cfg80211_ops esp_cfg80211_ops = {0};
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),
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,
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,
145 static struct wireless_dev *
146 esp_cfg80211_init(struct device *dev) {
148 struct wireless_dev *wdev;
150 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
153 esp_dbg(ESP_DBG_ERROR, "couldn't allocate wireless device\n");
157 wdev->wiphy = wiphy_new(&esp_cfg80211_ops, sizeof(struct esp_pub));
160 esp_dbg(ESP_DBG_ERROR, "couldn't allocate wiphy device\n");
165 set_wiphy_dev(wdev->wiphy, dev);
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;
173 wdev->wiphy->cipher_suites = cipher_suites;
174 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
176 ret = wiphy_register(wdev->wiphy);
179 esp_dbg(ESP_DBG_ERROR, "couldn't register wiphy device\n");
180 wiphy_free(wdev->wiphy);
189 esp_cfg80211_descory(struct esp_pub *pub)
194 static int esp_open(struct net_device *dev)
199 static struct net_device_stats *
200 esp_get_stats(struct net_device *dev) {
201 struct net_device_stats *stats = NULL;
205 static int esp_close(struct net_device *dev)
211 static int esp_data_tx(struct sk_buff *skb, struct net_device *dev)
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,
224 esp_init_netdev(struct net_device *dev)
226 dev->netdev_ops = &esp_netdev_ops;
227 dev->watchdog_timeo = 10;
229 dev->needed_headroom = ETH_HLEN + sizeof(struct llc_snap_hdr) + SIP_HDR_LEN;
235 esp_disconnect(struct esp_pub *epub)
241 esp_disconnect_timeout_handler(unsigned long ptr)
243 struct net_device *netdev = (struct net_device *)ptr;
244 struct esp_pub *epub = wdev_priv(netdev->ieee80211_ptr);
246 //esp_init_profile(epub);
247 esp_disconnect(epub);
251 esp_pub_alloc_cfg80211(struct device *dev) {
252 struct net_device *netdev;
253 struct wireless_dev *wdev;
254 struct esp_pub *epub;
257 wdev = esp_cfg80211_init(dev);
260 esp_dbg(ESP_DBG_ERROR, "%s: cfg80211_init failed \n", __func__);
264 epub = wdev_priv(wdev);
267 wdev->iftype = NL80211_IFTYPE_STATION;
269 /* Still register ethernet device */
270 netdev = alloc_netdev(0, "wlan%d", ether_setup);
273 esp_dbg(ESP_DBG_ERROR, "%s: alloc_netdev failed \n", __func__);
274 esp_cfg80211_descory(epub);
278 netdev->ieee80211_ptr = wdev;
279 SET_NETDEV_DEV(netdev, wiphy_dev(wdev->wiphy));
280 wdev->netdev = netdev;
282 esp_init_netdev(netdev);
284 epub->net_dev = netdev;
286 //spin_lock_init(&epub->lock);
290 init_waitqueue_head(&epub->ev_waitq);
291 //sema_init(epub->sem, 1);
293 INIT_LIST_HEAD(&wl->amsdu_rx_buffer_queue);
295 setup_timer(&wl->disconnect_timer, esp_disconnect_timeout_handler,
296 (unsigned long) netdev);