2 * Copyright (C) 2014 Spreadtrum Communications Inc.
4 * Authors:<jinglong.chen@spreadtrum.com>
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include "wlan_common.h"
19 #include "wlan_cfg80211.h"
22 #define RATETAB_ENT(_rate, _rateid, _flags) \
25 .hw_value = (_rateid), \
29 #define CHAN2G(_channel, _freq, _flags) { \
30 .band = IEEE80211_BAND_2GHZ, \
31 .center_freq = (_freq), \
32 .hw_value = (_channel), \
34 .max_antenna_gain = 0, \
38 #define CHAN5G(_channel, _flags) { \
39 .band = IEEE80211_BAND_5GHZ, \
40 .center_freq = 5000 + (5 * (_channel)), \
41 .hw_value = (_channel), \
43 .max_antenna_gain = 0, \
47 static struct ieee80211_rate itm_rates[] = {
48 RATETAB_ENT(10, 0x1, 0),
49 RATETAB_ENT(20, 0x2, 0),
50 RATETAB_ENT(55, 0x5, 0),
51 RATETAB_ENT(110, 0xb, 0),
52 RATETAB_ENT(60, 0x6, 0),
53 RATETAB_ENT(90, 0x9, 0),
54 RATETAB_ENT(120, 0xc, 0),
55 RATETAB_ENT(180, 0x12, 0),
56 RATETAB_ENT(240, 0x18, 0),
57 RATETAB_ENT(360, 0x24, 0),
58 RATETAB_ENT(480, 0x30, 0),
59 RATETAB_ENT(540, 0x36, 0),
61 RATETAB_ENT(65, 0x80, 0),
62 RATETAB_ENT(130, 0x81, 0),
63 RATETAB_ENT(195, 0x82, 0),
64 RATETAB_ENT(260, 0x83, 0),
65 RATETAB_ENT(390, 0x84, 0),
66 RATETAB_ENT(520, 0x85, 0),
67 RATETAB_ENT(585, 0x86, 0),
68 RATETAB_ENT(650, 0x87, 0),
69 RATETAB_ENT(130, 0x88, 0),
70 RATETAB_ENT(260, 0x89, 0),
71 RATETAB_ENT(390, 0x8a, 0),
72 RATETAB_ENT(520, 0x8b, 0),
73 RATETAB_ENT(780, 0x8c, 0),
74 RATETAB_ENT(1040, 0x8d, 0),
75 RATETAB_ENT(1170, 0x8e, 0),
76 RATETAB_ENT(1300, 0x8f, 0),
79 #define ITM_G_RATE_NUM 28
80 #define itm_g_rates (itm_rates)
81 #define ITM_A_RATE_NUM 24
82 #define itm_a_rates (itm_rates + 4)
84 #define itm_g_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
85 IEEE80211_HT_CAP_SGI_20 | \
86 IEEE80211_HT_CAP_SGI_40)
88 static struct ieee80211_channel itm_2ghz_channels[] = {
105 /*static struct ieee80211_channel itm_5ghz_channels[] =
107 CHAN5G(34, 0), CHAN5G(36, 0),
108 CHAN5G(38, 0), CHAN5G(40, 0),
109 CHAN5G(42, 0), CHAN5G(44, 0),
110 CHAN5G(46, 0), CHAN5G(48, 0),
111 CHAN5G(52, 0), CHAN5G(56, 0),
112 CHAN5G(60, 0), CHAN5G(64, 0),
113 CHAN5G(100, 0), CHAN5G(104, 0),
114 CHAN5G(108, 0), CHAN5G(112, 0),
115 CHAN5G(116, 0), CHAN5G(120, 0),
116 CHAN5G(124, 0), CHAN5G(128, 0),
117 CHAN5G(132, 0), CHAN5G(136, 0),
118 CHAN5G(140, 0), CHAN5G(149, 0),
119 CHAN5G(153, 0), CHAN5G(157, 0),
120 CHAN5G(161, 0), CHAN5G(165, 0),
121 CHAN5G(184, 0), CHAN5G(188, 0),
122 CHAN5G(192, 0), CHAN5G(196, 0),
123 CHAN5G(200, 0), CHAN5G(204, 0),
124 CHAN5G(208, 0), CHAN5G(212, 0),
128 static struct ieee80211_supported_band itm_band_2ghz = {
129 .n_channels = ARRAY_SIZE(itm_2ghz_channels),
130 .channels = itm_2ghz_channels,
131 .n_bitrates = ITM_G_RATE_NUM,
132 .bitrates = itm_g_rates,
133 .ht_cap.cap = itm_g_htcap,
134 .ht_cap.ht_supported = true,
137 /*static struct ieee80211_supported_band itm_band_5ghz = {
138 .n_channels = ARRAY_SIZE(itm_5ghz_channels),
139 .channels = itm_5ghz_channels,
140 .n_bitrates = ITM_A_RATE_NUM,
141 .bitrates = itm_a_rates,
142 .ht_cap.cap = itm_g_htcap,
143 .ht_cap.ht_supported = true,
146 static const u32 itm_cipher_suites[] = {
147 WLAN_CIPHER_SUITE_WEP40,
148 WLAN_CIPHER_SUITE_WEP104,
149 WLAN_CIPHER_SUITE_TKIP,
150 WLAN_CIPHER_SUITE_CCMP,
151 WLAN_CIPHER_SUITE_SMS4,
152 #ifdef BSS_ACCESS_POINT_MODE
153 WLAN_CIPHER_SUITE_ITM_CCMP,
154 WLAN_CIPHER_SUITE_ITM_TKIP,
158 /* Supported mgmt frame types to be advertised to cfg80211 */
159 static const struct ieee80211_txrx_stypes
160 itm_mgmt_stypes[NUM_NL80211_IFTYPES] = {
161 [NL80211_IFTYPE_STATION] = {
162 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
163 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
164 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
165 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
167 [NL80211_IFTYPE_AP] = {
168 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
169 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
170 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
171 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
173 [NL80211_IFTYPE_P2P_CLIENT] = {
174 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
175 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
176 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
177 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
179 [NL80211_IFTYPE_P2P_GO] = {
180 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
181 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
182 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
183 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
185 /* Supported mgmt frame types for p2p*/
186 [NL80211_IFTYPE_ADHOC] = {
188 .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
190 [NL80211_IFTYPE_STATION] = {
192 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
193 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
195 [NL80211_IFTYPE_AP] = {
197 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
198 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
199 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
200 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
201 BIT(IEEE80211_STYPE_AUTH >> 4) |
202 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
203 BIT(IEEE80211_STYPE_ACTION >> 4)
205 [NL80211_IFTYPE_AP_VLAN] = {
208 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
209 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
210 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
211 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
212 BIT(IEEE80211_STYPE_AUTH >> 4) |
213 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
214 BIT(IEEE80211_STYPE_ACTION >> 4)
216 [NL80211_IFTYPE_P2P_CLIENT] = {
218 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
219 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
221 [NL80211_IFTYPE_P2P_GO] = {
223 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
224 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
225 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
226 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
227 BIT(IEEE80211_STYPE_AUTH >> 4) |
228 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
229 BIT(IEEE80211_STYPE_ACTION >> 4)
233 #define WLAN_EID_VENDOR_SPECIFIC 221
235 void get_ssid(unsigned char *data, unsigned char *ssid)
237 unsigned char len = 0;
247 for (i = 0; i < len; i++, j++)
252 void get_bssid(unsigned char *data, unsigned char *bssid)
254 if (1 == ((data[1] & 0x02) >> 1))
255 memcpy(bssid, data + 10, 6);
256 else if ((data[1] & 0x01) == 1)
257 memcpy(bssid, data + 4, 6);
259 memcpy(bssid, data + 16, 6);
263 #ifdef WIFI_DIRECT_SUPPORT
265 struct ieee80211_channel global_channel;
268 static int get_file_size(struct file *f)
272 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
273 error = vfs_getattr(&f->f_path, &stat);
275 error = vfs_getattr(f->f_path.mnt, f->f_path.dentry, &stat);
280 pr_err("get conf file stat error\n");
285 #define P2P_MODE_PATH "/data/misc/wifi/fwpath"
286 int itm_get_p2p_mode_from_file(void)
294 fp = filp_open(P2P_MODE_PATH, O_RDONLY, 0);
296 pr_err("open %s file error\n", P2P_MODE_PATH);
301 size = get_file_size(fp);
303 pr_err("load file:%s error\n", P2P_MODE_PATH);
306 buf = kzalloc(size + 1, GFP_KERNEL);
307 vfs_read(fp, buf, size, &pos);
308 if (strcmp(buf, "p2p_mode") == 0)
312 filp_close(fp, NULL);
318 static bool itm_find_p2p_ie(const u8 *ie, size_t ie_len, u8 *p2p_ie,
325 if (NULL == ie || ie_len <= 0 || NULL == p2p_ie)
328 while (index < ie_len) {
329 if (P2P_IE_ID == ie[index]) {
330 *p2p_ie_len = ie[index + 1];
331 if (ie_len >= *p2p_ie_len &&
332 P2P_IE_OUI_BYTE0 == ie[index + 2] &&
333 P2P_IE_OUI_BYTE1 == ie[index + 3] &&
334 P2P_IE_OUI_BYTE2 == ie[index + 4] &&
335 P2P_IE_OUI_TYPE == ie[index + 5]) {
336 memcpy(p2p_ie, ie + index, *p2p_ie_len + 2);
347 static int wlan_cfg80211_remain_on_channel(struct wiphy *wiphy,
348 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
349 struct wireless_dev *dev,
351 struct net_device *dev,
353 struct ieee80211_channel
355 unsigned int duration, u64 *cookie)
358 unsigned char vif_id;
361 enum nl80211_channel_type channel_type = 0;
362 vif = ndev_to_vif(dev->netdev);
364 if (ITM_NONE_MODE == vif->mode)
366 printkd("[%s][%d] enter\n", __func__, vif_id);
367 memcpy(&global_channel, channel, sizeof(struct ieee80211_channel));
368 global_cookie = *cookie;
369 printkd("remain on channel duration is %d\n", duration);
370 /* send remain chan */
372 wlan_cmd_remain_chan(vif_id, channel, channel_type, duration,
377 /* report remain chan */
378 cfg80211_ready_on_channel(dev, *cookie, channel, duration, GFP_KERNEL);
382 static int wlan_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
383 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
384 struct wireless_dev *dev,
386 struct net_device *dev,
392 unsigned char vif_id;
393 vif = ndev_to_vif(dev->netdev);
395 if (ITM_NONE_MODE == vif->mode)
397 printkd("[%s][%d] enter\n", __func__, vif_id);
398 ret = wlan_cmd_cancel_remain_chan(vif_id, cookie);
404 static int wlan_cfg80211_del_station(struct wiphy *wiphy,
405 struct net_device *ndev, u8 *mac)
408 unsigned char vif_id;
409 vif = ndev_to_vif(ndev);
413 wiphy_dbg(wiphy, "Ignore NULL MAC address!\n");
417 wiphy_info(wiphy, "%s %pM\n", __func__, mac);
418 wlan_cmd_disassoc(vif_id, mac, WLAN_REASON_DEAUTH_LEAVING);
423 static void register_frame_work_fun(struct work_struct *work)
425 unsigned char vif_id;
426 struct wlan_cmd_register_frame_t data;
427 register_frame_param_t *param =
428 container_of(work, register_frame_param_t, work);
429 data.type = param->frame_type;
430 data.reg = param->reg ? 1 : 0;
431 param->frame_type = 0xffff;
433 vif_id = ((wlan_vif_t *) (param->vif))->id;
434 wlan_cmd_register_frame(vif_id, &data);
438 void init_register_frame_param(wlan_vif_t *vif)
440 register_frame_param_t *param;
441 param = &(vif->cfg80211.register_frame);
442 param->frame_type = 0xffff;
444 param->vif = (void *)vif;
445 INIT_WORK(&(param->work), register_frame_work_fun);
448 static int register_frame(wlan_vif_t *vif, unsigned short frame_type, bool reg)
450 vif->cfg80211.register_frame.frame_type = frame_type;
451 vif->cfg80211.register_frame.reg = reg;
452 schedule_work(&(vif->cfg80211.register_frame.work));
456 void cfg80211_report_remain_on_channel_expired(unsigned char vif_id,
461 vif = id_to_vif(vif_id);
462 cfg80211_remain_on_channel_expired(&(vif->wdev), global_cookie,
463 &global_channel, GFP_KERNEL);
467 static void send_deauth_work_func(struct work_struct *work)
470 struct deauth_info *info;
472 info = container_of(work, struct deauth_info, work);
473 vif = container_of(info, wlan_vif_t, deauth_info);
474 cfg80211_send_deauth(vif->ndev, info->mac, info->len);
479 void init_send_deauth_work(wlan_vif_t *vif)
481 struct deauth_info *info;
482 info = &vif->deauth_info;
483 memset(info, 0, sizeof(*info));
484 INIT_WORK(&info->work, send_deauth_work_func);
487 void cfg80211_report_mgmt_deauth(unsigned char vif_id, unsigned char *data,
490 wlan_vif_t *vif = id_to_vif(vif_id);
491 memcpy(&vif->deauth_info.len, data, 2);
492 if (vif->deauth_info.len > sizeof(vif->deauth_info.mac)) {
493 ASSERT("%s len:%d > max:%d\n", __func__,
494 vif->deauth_info.len, sizeof(vif->deauth_info.mac));
498 memcpy(vif->deauth_info.mac, data + 2, vif->deauth_info.len);
499 schedule_work(&vif->deauth_info.work);
504 void cfg80211_report_mgmt_disassoc(unsigned char vif_id, unsigned char *data,
509 wlan_vif_t *vif = id_to_vif(vif_id);
512 memcpy(&mac_len, index, 2);
515 cfg80211_send_disassoc(vif->ndev, mac_ptr, mac_len);
518 void cfg80211_report_station(unsigned char vif_id, unsigned char *data,
523 u16 req_len, mac_len;
527 struct station_info sinfo;
528 wlan_vif_t *vif = id_to_vif(vif_id);
529 struct wiphy *wiphy = vif->wdev.wiphy;
536 /* The first byte of event data is connection */
537 memcpy(&connect_ap, index, 1);
541 /* The second byte of event data is mac */
542 memcpy(&mac_len, index, 2);
547 printkd("channel len %d not equal 6 bytes\n", mac_len);
556 printkd("There is no associa req frame!\n");
560 /* The third event data is associate request */
561 memcpy(&req_len, index, 2);
568 memset(&sinfo, 0, sizeof(struct station_info));
569 sinfo.assoc_req_ies = req_ptr;
570 sinfo.assoc_req_ies_len = req_len;
571 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
574 cfg80211_new_sta(vif->ndev, sta_mac, &sinfo, GFP_KERNEL);
575 wiphy_info(wiphy, "New station (" MACSTR ") connected\n",
578 cfg80211_del_sta(vif->ndev, sta_mac, GFP_KERNEL);
579 wiphy_info(wiphy, "A station (" MACSTR ") disconnected\n",
584 void cfg80211_report_frame(unsigned char vif_id, unsigned char *data,
587 unsigned short mac_len;
588 unsigned char *mac_ptr = NULL;
589 unsigned char channel = 0, type = 0;
591 struct wlan_event_report_frame_t *report_frame = NULL;
592 wlan_vif_t *vif = id_to_vif(vif_id);
594 report_frame = (struct wlan_event_report_frame_t *)data;
595 channel = report_frame->channel;
596 type = report_frame->frame_type;
597 freq = ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
598 mac_ptr = (unsigned char *)(report_frame + 1);
599 mac_len = report_frame->frame_len;
600 printkd("%s, frame_len:%d\n", __func__, mac_len);
601 cfg80211_rx_mgmt(&(vif->wdev), freq, 0, mac_ptr, mac_len, GFP_KERNEL);
604 #endif /*WIFI_DIRECT_SUPPORT */
606 static bool itm_is_wps_ie(const unsigned char *pos)
608 return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
610 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
614 static bool itm_find_wpsie(const unsigned char *ies, size_t ies_len,
615 unsigned char *buf, size_t *wps_len)
617 const unsigned char *pos;
622 * Filter out RSN/WPA IE(s)
624 if (ies && ies_len) {
627 while (pos + 1 < ies + ies_len) {
628 if (pos + 2 + pos[1] > ies + ies_len)
631 if (itm_is_wps_ie(pos)) {
632 memcpy(buf + len, pos, 2 + pos[1]);
645 static bool itm_find_ft_ie(const unsigned char *ies, size_t ies_len,
646 unsigned char *buf, size_t *ie_len)
648 const unsigned char *pos;
651 if (ies && ies_len) {
653 while (pos + 1 < ies + ies_len) {
654 if (pos + 2 + pos[1] > ies + ies_len)
656 if ((WLAN_11R_FT_IE_ID == pos[0])
657 || (WLAN_11R_MD_IE_ID == pos[0])) {
658 memcpy(buf + len, pos, 2 + pos[1]);
670 static int itm_wlan_add_cipher_key(wlan_vif_t *vif, bool pairwise,
671 unsigned char key_index, unsigned int cipher,
672 const unsigned char *key_seq,
673 const unsigned char *macaddr)
675 unsigned char pn_key[16] = {
676 0x5c, 0x36, 0x5c, 0x36, 0x5c, 0x36, 0x5c, 0x36,
677 0x5c, 0x36, 0x5c, 0x36, 0x5c, 0x36, 0x5c, 0x36
680 unsigned char vif_id;
682 printkd("%s()\n", __func__);
683 if (vif->cfg80211.key_len[pairwise][0]
684 || vif->cfg80211.key_len[pairwise][1]
685 || vif->cfg80211.key_len[pairwise][2]
686 || vif->cfg80211.key_len[pairwise][3]) {
687 /* Only set wep keys if we have at least one of them.
688 pairwise: 0:GTK 1:PTK */
690 case WLAN_CIPHER_SUITE_WEP40:
691 vif->cfg80211.cipher_type = WEP40;
693 case WLAN_CIPHER_SUITE_WEP104:
694 vif->cfg80211.cipher_type = WEP104;
696 case WLAN_CIPHER_SUITE_TKIP:
697 vif->cfg80211.cipher_type = TKIP;
699 case WLAN_CIPHER_SUITE_CCMP:
700 vif->cfg80211.cipher_type = CCMP;
702 case WLAN_CIPHER_SUITE_SMS4:
703 vif->cfg80211.cipher_type = WAPI;
706 printkd("Invalid cipher select: %d\n",
707 vif->cfg80211.cipher_type);
710 memcpy(vif->cfg80211.key_txrsc[pairwise], pn_key,
713 wlan_cmd_add_key(vif_id,
714 vif->cfg80211.key[pairwise][key_index],
715 vif->cfg80211.key_len[pairwise][key_index],
716 pairwise, key_index, key_seq,
717 vif->cfg80211.cipher_type, macaddr);
719 printkd("wlan_cmd_add_key failed %d\n", ret);
726 u8 sprdwl_find_ssid_count(wlan_vif_t *vif)
728 buf_scan_frame_t *scan_buf = NULL;
731 struct wiphy *wiphy = vif->wdev.wiphy;
733 if (!vif->cfg80211.scan_frame_array)
736 for (i = 0; i < MAX_SCAN_FRAME_BUF_NUM; i++) {
737 scan_buf = (buf_scan_frame_t *) (vif->cfg80211.scan_frame_array
739 i * sizeof(buf_scan_frame_t));
741 if (0xff != scan_buf->live)
744 if (0 == scan_buf->ssid[0])
748 memcmp(vif->cfg80211.ssid, scan_buf->ssid,
749 vif->cfg80211.ssid_len))
755 wiphy_info(wiphy, "the same ssid num %d with current connect ssid",
761 static int wlan_cfg80211_scan(struct wiphy *wiphy,
762 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
763 struct net_device *dev,
765 struct cfg80211_scan_request *request)
768 unsigned char vif_id;
769 struct wireless_dev *wdev;
770 struct cfg80211_ssid *ssids;
771 struct wlan_cmd_scan_ssid *scan_ssids;
772 int scan_ssids_len = 0;
773 unsigned char *data = NULL;
774 unsigned int i, n, j;
776 unsigned char channels[16] = { 0 };
778 ssids = request->ssids;
779 wdev = request->wdev;
780 vif = ndev_to_vif(wdev->netdev);
782 if (ITM_NONE_MODE == vif->mode)
784 printkd("[%s][%d] enter\n", __func__, vif_id);
785 if (vif->cfg80211.scan_request) {
786 printkd("Already scanning\n");
789 /* check we are client side */
790 switch (wdev->iftype) {
791 case NL80211_IFTYPE_AP:
793 /* case NL80211_IFTYPE_P2P_CLIENT:
794 case NL80211_IFTYPE_P2P_GO:
796 case NL80211_IFTYPE_STATION:
798 case NL80211_IFTYPE_P2P_CLIENT:
799 case NL80211_IFTYPE_P2P_GO:
800 case NL80211_IFTYPE_P2P_DEVICE:
804 printkd("%s(), end\n", __func__);
810 if (request->ie_len > 0) {
811 if (request->ie_len > 255) {
812 printkd("%s invalid ie len(%d)\n", __func__,
817 wlan_cmd_set_wps_ie(vif_id, WPS_REQ_IE, request->ie,
820 printkd("wlan_cmd_set_wps_ie failed with ret %d\n",
822 printkd("%s(), end\n", __func__);
826 printkd("%s request->ie_len is 0\n", __func__);
828 n = min(request->n_ssids, 9);
830 data = kzalloc(512, GFP_KERNEL);
832 printkd("%s failed to alloc for combo ssid\n",
836 scan_ssids = (struct wlan_cmd_scan_ssid *)data;
837 for (i = 0; i < n; i++) {
838 if (!ssids[i].ssid_len)
840 scan_ssids->len = ssids[i].ssid_len;
841 memcpy(scan_ssids->ssid, ssids[i].ssid,
843 scan_ssids_len += (ssids[i].ssid_len
844 + sizeof(scan_ssids->len));
845 scan_ssids = (struct wlan_cmd_scan_ssid *)
846 (data + scan_ssids_len);
850 n = min(request->n_channels, 14);
853 for (i = 0, j = 0; i < n; i++) {
854 int ch = request->channels[i]->hw_value;
856 printkd("Scan requested for unknown frequency %dMhz\n",
857 request->channels[i]->center_freq);
860 channels[j + 1] = ch;
865 /* Arm scan timeout timer */
866 mod_timer(&vif->cfg80211.scan_timeout,
867 jiffies + ITM_SCAN_TIMER_INTERVAL_MS * HZ / 1000);
868 vif->cfg80211.scan_request = request;
870 ret = wlan_cmd_scan(vif_id, data, channels, scan_ssids_len);
872 printkd("wlan_cmd_scan failed with ret %d\n", ret);
877 #ifdef CONFIG_HAS_WAKELOCK
878 if (vif->cfg80211.scan_done_lock.link.next == LIST_POISON1 ||
879 vif->cfg80211.scan_done_lock.link.prev == LIST_POISON2)
880 wake_lock(&vif->cfg80211.scan_done_lock);
883 printkd("%s(), ok!\n", __func__);
887 static int wlan_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
888 struct cfg80211_connect_params *sme)
891 unsigned char vif_id;
892 struct wireless_dev *wdev;
894 unsigned int cipher = 0;
895 unsigned char key_mgmt = 0;
896 int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40)
897 || (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
898 bool is_wapi = false;
900 unsigned char *buf = NULL;
902 unsigned short p2p_len = 0;
904 vif = ndev_to_vif(ndev);
907 if (ITM_NONE_MODE == vif->mode)
909 printkd("[%s][%d] enter\n", __func__, vif_id);
910 printkd("%s(), Begin connect: %s\n", __func__, sme->ssid);
912 /* To avoid confused wapi frame */
913 vif->cfg80211.cipher_type = NONE;
914 /* Get request status, type, bss, ie and so on */
915 /* Set appending ie */
917 if (sme->ie_len > 0) {
918 if (sme->ie_len > 255) {
919 printkd("%s invalid sme->len(%d)\n", __func__,
923 buf = kmalloc(sme->ie_len, GFP_KERNEL);
925 printkd("%s(), end\n", __func__);
928 if (itm_find_wpsie(sme->ie, sme->ie_len, buf, &wps_len) == true) {
930 wlan_cmd_set_wps_ie(vif_id, WPS_ASSOC_IE, buf,
934 ("wlan_cmd_set_wps_ie failed with ret %d\n",
940 #ifdef WIFI_DIRECT_SUPPORT
941 if (itm_find_p2p_ie(sme->ie, sme->ie_len, buf, &p2p_len) == true) {
942 ret = wlan_cmd_set_p2p_ie(vif_id, P2P_ASSOC_IE, buf, p2p_len);
944 printkd("wlan_cmd_set_p2p_ie failed with ret %d\n",
949 #endif /*WIFI_DIRECT_SUPPORT */
950 #ifdef WLAN_11R_SUPPORT
951 if (itm_find_ft_ie(sme->ie, sme->ie_len, buf, &ftie_len)) {
952 ret = wlan_cmd_set_ft_ie(vif_id, buf, ftie_len);
954 printkd("wlan_cmd_set_ft_ie failed with ret %d\n", ret);
958 /* Set WPA version */
959 printkd("Set wpa_versions %#x\n", sme->crypto.wpa_versions);
960 ret = wlan_cmd_set_wpa_version(vif_id, sme->crypto.wpa_versions);
962 printkd("wlan_cmd_set_wpa_version failed with ret %d\n", ret);
963 printkd("%s(), end\n", __func__);
968 printkd("Set auth_type %#x\n", sme->auth_type);
969 /* Set the authorisation */
970 if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
971 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
972 auth_type = ITM_AUTH_OPEN;
973 else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
974 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
975 auth_type = ITM_AUTH_SHARED;
976 ret = wlan_cmd_set_auth_type(vif_id, auth_type);
978 printkd("wlan_cmd_set_auth_type failed with ret %d\n", ret);
981 /* Set cipher - pairewise and group */
982 printkd("n_ciphers_pairwise %d\n", sme->crypto.n_ciphers_pairwise);
983 if (sme->crypto.n_ciphers_pairwise) {
984 switch (sme->crypto.ciphers_pairwise[0]) {
985 case WLAN_CIPHER_SUITE_WEP40:
988 case WLAN_CIPHER_SUITE_WEP104:
991 case WLAN_CIPHER_SUITE_TKIP:
994 case WLAN_CIPHER_SUITE_CCMP:
997 /* WAPI cipher is not processed by CP2 */
998 case WLAN_CIPHER_SUITE_SMS4:
1003 printkd("Unicast cipher suite 0x%x is not supported\n",
1004 sme->crypto.ciphers_pairwise[0]);
1005 printkd("%s(), end\n", __func__);
1010 if (is_wapi != true) {
1012 wlan_cmd_set_cipher(vif_id, cipher,
1013 WIFI_CMD_SET_PAIRWISE_CIPHER);
1016 ("set_cipher_cmd pairwise failed with ret %d\n",
1018 printkd("%s(), end\n", __func__);
1023 /*No pairewise cipher */
1024 printkd("No pairewise cipher\n");
1027 /* Set group cipher */
1028 switch (sme->crypto.cipher_group) {
1032 case WLAN_CIPHER_SUITE_WEP40:
1035 case WLAN_CIPHER_SUITE_WEP104:
1038 case WLAN_CIPHER_SUITE_TKIP:
1041 case WLAN_CIPHER_SUITE_CCMP:
1045 printkd("Group cipher suite 0x%x is not supported\n",
1046 sme->crypto.cipher_group);
1047 printkd("%s(), end\n", __func__);
1052 if (is_wapi != true) {
1054 wlan_cmd_set_cipher(vif_id, cipher,
1055 WIFI_CMD_SET_GROUP_CIPHER);
1057 printkd("set_cipher_cmd group failed with ret %d\n",
1059 printkd("%s(), end\n", __func__);
1065 /* Set Auth type again because of CP2 process's differece */
1066 printkd("Set auth_type %#x\n", sme->auth_type);
1067 /* Set the authorisation */
1068 if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
1069 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
1070 auth_type = ITM_AUTH_OPEN;
1071 else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
1072 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
1073 auth_type = ITM_AUTH_SHARED;
1074 ret = wlan_cmd_set_auth_type(vif_id, auth_type);
1076 printkd("wlan_cmd_set_auth_type failed with ret %d\n", ret);
1077 printkd("%s(), end\n", __func__);
1081 /* Set auth key management (akm) */
1082 printkd("akm_suites %#x\n", sme->crypto.n_akm_suites);
1083 if (sme->crypto.n_akm_suites) {
1084 if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_PSK)
1085 key_mgmt = AKM_SUITE_PSK;
1086 else if (WLAN_AKM_SUITE_FT_PSK == sme->crypto.akm_suites[0])
1087 key_mgmt = AKM_SUITE_FT_PSK;
1088 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_8021X)
1089 key_mgmt = AKM_SUITE_8021X;
1090 /* WAPI akm is not processed by CP2 */
1091 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_CERT)
1092 key_mgmt = AKM_SUITE_WAPI_CERT;
1093 else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_PSK)
1094 key_mgmt = AKM_SUITE_WAPI_PSK;
1095 else if (WLAN_AKM_SUITE_FT_8021X == sme->crypto.akm_suites[0])
1096 key_mgmt = AKM_SUITE_FT_8021X;
1099 ret = wlan_cmd_set_key_management(vif_id, key_mgmt);
1101 printkd("wlan_cmd_set_key_management failed %d\n", ret);
1102 printkd("%s(), end\n", __func__);
1108 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40 ||
1109 sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104 ||
1110 sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP40 ||
1111 sme->crypto.ciphers_pairwise[0] == WLAN_CIPHER_SUITE_WEP104) {
1112 printkd("Don't need to set PSK since driver is using WEP\n");
1113 vif->cfg80211.key_index[GROUP] = sme->key_idx;
1114 vif->cfg80211.key_len[GROUP][sme->key_idx] = sme->key_len;
1115 memcpy(vif->cfg80211.key[GROUP][sme->key_idx], sme->key,
1118 itm_wlan_add_cipher_key(vif, 0, sme->key_idx,
1119 sme->crypto.ciphers_pairwise[0],
1122 printkd("itm_wlan_add_key failed %d\n", ret);
1123 printkd("%s(), end\n", __func__);
1128 unsigned char psk[32];
1130 if (wdev->iftype == NL80211_IFTYPE_AP) {
1131 ret = hostap_conf_load(HOSTAP_CONF_FILE_NAME, psk);
1133 printkd("load hostap failed with ret %d\n",
1135 printkd("%s(), end\n", __func__);
1138 key_len = sizeof(psk);
1140 if (sme->key_len > 32) {
1141 printkd("Invalid key len (%d)\n", sme->key_len);
1142 printkd("%s(), end\n", __func__);
1146 memcpy(psk, sme->key, sme->key_len);
1147 key_len = sme->key_len;
1149 ret = wlan_cmd_set_psk(vif_id, psk, key_len);
1151 printkd("set_psk_cmd failed with ret %d\n", ret);
1152 printkd("%s(), end\n", __func__);
1157 /* Auth RX unencrypted EAPOL is not implemented, do nothing */
1159 if (sme->channel != NULL) {
1160 printkd("Settting channel to %d\n",
1161 ieee80211_frequency_to_channel(sme->
1162 channel->center_freq));
1164 wlan_cmd_set_channel(vif_id,
1165 ieee80211_frequency_to_channel
1166 (sme->channel->center_freq));
1168 printkd("wlan_cmd_set_channel failed with ret %d\n",
1170 printkd("%s(), end\n", __func__);
1174 printkd("Channel is not specified\n");
1178 if (sme->bssid != NULL) {
1179 ret = wlan_cmd_set_bssid(vif_id, sme->bssid);
1181 printkd("wlan_cmd_set_bssid failed with ret %d\n", ret);
1182 printkd("%s(), end\n", __func__);
1185 memcpy(vif->cfg80211.bssid, sme->bssid, 6);
1187 printkd("BSSID is not specified\n");
1190 /* Special process for WEP(WEP key must be set before itm_set_essid) */
1191 if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40 ||
1192 sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104) {
1193 printkd("Setting WEP group cipher\n");
1194 if (sme->key_len <= 0) {
1195 printkd("No key is specified\n");
1197 if (sme->key_len != WLAN_KEY_LEN_WEP104 &&
1198 sme->key_len != WLAN_KEY_LEN_WEP40) {
1199 printkd("Invalid key length for WEP\n");
1200 printkd("%s(), end\n", __func__);
1204 wlan_cmd_set_key(vif_id, sme->key_idx);
1208 if (sme->ssid != NULL) {
1209 printkd("sme->ssid:%s\n", sme->ssid);
1210 ret = wlan_cmd_set_essid(vif_id, sme->ssid, (int)sme->ssid_len);
1212 printkd("wlan_cmd_set_essid failed with ret %d\n", ret);
1213 printkd("%s(), end\n", __func__);
1217 memcpy(vif->cfg80211.ssid, sme->ssid, sme->ssid_len);
1218 vif->cfg80211.ssid_len = sme->ssid_len;
1220 vif->cfg80211.connect_status = ITM_CONNECTING;
1222 printkd("%s(), ok\n", __func__);
1226 static int wlan_cfg80211_disconnect(struct wiphy *wiphy,
1227 struct net_device *ndev,
1228 unsigned short reason_code)
1231 unsigned char vif_id;
1232 struct cfg80211_bss *bss = NULL;
1235 vif = ndev_to_vif(ndev);
1237 if (ITM_NONE_MODE == vif->mode)
1239 printkd("[%s][%d] enter\n", __func__, vif_id);
1240 printkd("Begin disconnect: %s\n", vif->cfg80211.ssid);
1242 ret = wlan_cmd_disconnect(vif_id, reason_code);
1244 printkd("swifi_disconnect_cmd failed with ret %d\n", ret);
1246 memset(vif->cfg80211.ssid, 0, sizeof(vif->cfg80211.ssid));
1250 static int wlan_cfg80211_add_key(struct wiphy *wiphy,
1251 struct net_device *netdev, u8 idx,
1252 bool pairwise, const u8 *mac_addr,
1253 struct key_params *params)
1256 unsigned char vif_id;
1258 unsigned char key[32];
1259 vif = ndev_to_vif(netdev);
1261 if (ITM_NONE_MODE == vif->mode)
1263 printkd("[%s][%d] enter\n", __func__, vif_id);
1265 vif->cfg80211.key_index[pairwise] = idx;
1266 vif->cfg80211.key_len[pairwise][idx] = params->key_len;
1267 memcpy(vif->cfg80211.key[pairwise][idx], params->key, params->key_len);
1269 itm_wlan_add_cipher_key(vif, pairwise, idx, params->cipher,
1270 params->seq, mac_addr);
1272 printkd("%s failed to add cipher key!\n", __func__);
1279 static int wlan_cfg80211_del_key(struct wiphy *wiphy,
1280 struct net_device *ndev,
1281 unsigned char key_index, bool pairwise,
1282 const unsigned char *mac_addr)
1285 unsigned char vif_id;
1287 vif = ndev_to_vif(ndev);
1289 if (ITM_NONE_MODE == vif->mode)
1291 printkd("[%s][%d] enter\n", __func__, vif_id);
1292 if (key_index > WLAN_MAX_KEY_INDEX) {
1293 printkd("key index %d out of bounds\n", key_index);
1296 if (!vif->cfg80211.key_len[pairwise][key_index]) {
1297 printkd("index %d is empty\n", key_index);
1300 vif->cfg80211.key_len[pairwise][key_index] = 0;
1301 vif->cfg80211.cipher_type = NONE;
1303 return wlan_cmd_del_key(vif_id, key_index, mac_addr);
1306 static int wlan_cfg80211_set_default_key(struct wiphy *wiphy,
1307 struct net_device *ndev,
1308 unsigned char key_index, bool unicast,
1313 unsigned char vif_id;
1314 vif = ndev_to_vif(ndev);
1316 if (ITM_NONE_MODE == vif->mode)
1318 printkd("[%s][%d] enter\n", __func__, vif_id);
1319 if (key_index < 0 || key_index > 3) {
1320 printkd("Invalid key index %d\n", key_index);
1323 ret = wlan_cmd_set_key(vif_id, key_index);
1325 printkd("wlan_cmd_set_key failed\n");
1332 static int wlan_cfg80211_set_wiphy_params(struct wiphy *wiphy,
1333 unsigned int changed)
1337 unsigned char vif_id;
1338 vif_id = NETIF_0_ID;
1339 vif = id_to_vif(vif_id);
1340 if (ITM_NONE_MODE == vif->mode)
1342 printkd("[%s][%d] enter\n", __func__, vif_id);
1343 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1344 ret = wlan_cmd_set_rts(vif_id, wiphy->rts_threshold);
1346 printkd("wlan_cmd_set_rts failed\n");
1351 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1352 ret = wlan_cmd_set_frag(vif_id, wiphy->frag_threshold);
1354 printkd("wlan_cmd_set_frag failed\n");
1361 static int wlan_cfg80211_get_station(struct wiphy *wiphy,
1362 struct net_device *dev, unsigned char *mac,
1363 struct station_info *sinfo)
1365 unsigned char signal, noise;
1366 int rate, ret, i, failed;
1368 unsigned char vif_id;
1369 static int cfg80211_get_station_time;
1370 static char cfg80211_get_station_signal;
1371 static int cfg80211_get_station_txrate;
1372 static int cfg80211_get_station_txfailed;
1374 vif = ndev_to_vif(dev);
1376 if (ITM_NONE_MODE == vif->mode)
1378 if (NULL == sinfo) {
1379 printke("[%s][sinfo null]\n", __func__);
1384 STATION_INFO_TX_BYTES | STATION_INFO_TX_PACKETS |
1385 STATION_INFO_RX_BYTES | STATION_INFO_RX_PACKETS;
1386 sinfo->tx_bytes = vif->ndev->stats.tx_bytes;
1387 sinfo->tx_packets = vif->ndev->stats.tx_packets;
1388 sinfo->rx_bytes = vif->ndev->stats.rx_bytes;
1389 sinfo->rx_packets = vif->ndev->stats.rx_packets;
1391 if (0 != cfg80211_get_station_time) {
1392 sinfo->signal = cfg80211_get_station_signal;
1393 sinfo->filled |= STATION_INFO_SIGNAL;
1394 sinfo->txrate.legacy = cfg80211_get_station_txrate;
1395 sinfo->filled |= STATION_INFO_TX_BITRATE;
1396 sinfo->tx_failed = cfg80211_get_station_txfailed;
1397 sinfo->filled |= STATION_INFO_TX_FAILED;
1398 if (2 == cfg80211_get_station_time) {
1399 cfg80211_get_station_time = 0;
1401 cfg80211_get_station_time++;
1406 ret = wlan_cmd_get_rssi(vif_id, &signal, &noise);
1408 sinfo->signal = signal;
1409 sinfo->filled |= STATION_INFO_SIGNAL;
1411 printkd("wlan_cmd_get_rssi error!\n");
1415 ret = wlan_cmd_get_txrate_txfailed(vif_id, &rate, &failed);
1417 sinfo->tx_failed = failed;
1419 STATION_INFO_TX_BITRATE | STATION_INFO_TX_FAILED;
1421 printkd("wlan_cmd_get_txrate_txfailed error!\n");
1425 if (!(rate & 0x7f)) {
1426 sinfo->txrate.legacy = 10;
1428 for (i = 0; i < ARRAY_SIZE(itm_rates); i++) {
1429 if (rate == itm_rates[i].hw_value) {
1430 sinfo->txrate.legacy = itm_rates[i].bitrate;
1433 itm_rates[i].hw_value;
1437 if (i >= ARRAY_SIZE(itm_rates))
1438 sinfo->txrate.legacy = 10;
1440 cfg80211_get_station_signal = sinfo->signal;
1441 cfg80211_get_station_txrate = sinfo->txrate.legacy;
1442 cfg80211_get_station_txfailed = sinfo->tx_failed;
1443 cfg80211_get_station_time++;
1448 static int wlan_cfg80211_set_pmksa(struct wiphy *wiphy,
1449 struct net_device *netdev,
1450 struct cfg80211_pmksa *pmksa)
1454 unsigned char vif_id;
1455 vif = ndev_to_vif(netdev);
1457 if (ITM_NONE_MODE == vif->mode)
1459 printkd("[%s][%d] enter\n", __func__, vif_id);
1461 wlan_cmd_pmksa(vif_id, pmksa->bssid, pmksa->pmkid,
1462 WIFI_CMD_SET_PMKSA);
1466 static int wlan_cfg80211_del_pmksa(struct wiphy *wiphy,
1467 struct net_device *netdev,
1468 struct cfg80211_pmksa *pmksa)
1472 unsigned char vif_id;
1473 vif = ndev_to_vif(netdev);
1475 if (ITM_NONE_MODE == vif->mode)
1477 printkd("[%s][%d] enter\n", __func__, vif_id);
1479 wlan_cmd_pmksa(vif_id, pmksa->bssid, pmksa->pmkid,
1480 WIFI_CMD_DEL_PMKSA);
1484 static int wlan_cfg80211_flush_pmksa(struct wiphy *wiphy,
1485 struct net_device *netdev)
1489 unsigned char vif_id;
1490 vif = ndev_to_vif(netdev);
1492 if (ITM_NONE_MODE == vif->mode)
1494 printkd("[%s][%d] enter\n", __func__, vif_id);
1496 wlan_cmd_pmksa(vif_id, vif->cfg80211.bssid, NULL,
1497 WIFI_CMD_FLUSH_PMKSA);
1501 void cfg80211_report_connect_result(unsigned char vif_id, unsigned char *pData,
1504 unsigned char *req_ie_ptr, *resp_ie_ptr, *bssid_ptr, *pos, *value_ptr;
1505 unsigned char status_code = 0;
1506 unsigned short bssid_len;
1507 unsigned char req_ie_len;
1508 unsigned short resp_ie_len;
1509 unsigned int event_len;
1511 unsigned char reassociate_rsp_flag = 0;
1513 wlan_vif_t *vif = id_to_vif(vif_id);
1514 printkd("%s(), enter\n", __func__);
1516 /* status_len 2 + status_code 1 = 3 bytes */
1517 if (event_len < 3) {
1518 printkd("filled event len(%d) is not a valid len\n", event_len);
1521 pos = kmalloc(event_len, GFP_KERNEL);
1523 printkd("[%s][%d][%d]\n", __func__, __LINE__, event_len);
1524 if (event_len > 16384)
1528 /* The first byte of event data is status and len */
1529 memcpy(pos, pData, event_len);
1531 * byte [0] the length for status_code,here is 1
1532 * byte [1] reassociate_rsp_flag
1533 * byte [2] status_code
1537 ASSERT("msg first byte err:%d != 1", (int)*pos);
1541 reassociate_rsp_flag = *(pos + 1);
1542 status_code = *(pos + 2);
1544 /* FIXME later the status code should be reported by CP2 */
1545 if (status_code != 0) {
1546 printkd("%s, Connect is failled (%d)\n", __func__, status_code);
1551 value_ptr = pos + 3;
1552 left = event_len - 3;
1553 /* BSSID is 6 + len is 2 = 8 */
1555 printkd("%s(), Do not have a vaild bssid\n", __func__);
1559 memcpy(&bssid_len, value_ptr, 2);
1561 bssid_ptr = value_ptr + 2;
1565 printkd("%s(), There is no req_ie frame!\n", __func__);
1569 req_ie_len = *(unsigned char *)(bssid_ptr + bssid_len);
1571 req_ie_ptr = bssid_ptr + bssid_len + 1;
1574 printkd("%s(), There is no resp_ie frame!\n", __func__);
1579 *(unsigned char *)(req_ie_ptr + req_ie_len) +
1580 *(unsigned char *)(req_ie_ptr + req_ie_len + 1);
1581 resp_ie_ptr = req_ie_ptr + req_ie_len + 2;
1583 if ((vif->cfg80211.connect_status == ITM_CONNECTING)
1584 || (1 == reassociate_rsp_flag)) {
1585 /* inform connect result to cfg80211 */
1586 vif->cfg80211.connect_status = ITM_CONNECTED;
1587 if (1 == reassociate_rsp_flag) {
1588 vif->wdev.sme_state = CFG80211_SME_CONNECTING;
1590 cfg80211_connect_result(vif->ndev, bssid_ptr, req_ie_ptr,
1591 req_ie_len, resp_ie_ptr, resp_ie_len,
1592 WLAN_STATUS_SUCCESS, GFP_KERNEL);
1593 if (!netif_carrier_ok(vif->ndev)) {
1594 printkd("%s(), netif_carrier_on, ssid:%s\n", __func__,
1595 vif->cfg80211.ssid);
1596 netif_carrier_on(vif->ndev);
1597 netif_wake_queue(vif->ndev);
1601 printkd("%s(), ok\n", __func__);
1604 if (vif->cfg80211.scan_request
1605 && (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) == 1)) {
1606 del_timer_sync(&vif->cfg80211.scan_timeout);
1607 cfg80211_scan_done(vif->cfg80211.scan_request, true);
1608 vif->cfg80211.scan_request = NULL;
1609 #ifdef CONFIG_HAS_WAKELOCK
1610 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1 &&
1611 vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
1612 wake_unlock(&vif->cfg80211.scan_done_lock);
1614 atomic_dec(&vif->cfg80211.scan_status);
1616 if (vif->cfg80211.connect_status == ITM_CONNECTING) {
1617 cfg80211_connect_result(vif->ndev, vif->cfg80211.bssid, NULL, 0,
1619 WLAN_STATUS_UNSPECIFIED_FAILURE,
1621 } else if (vif->cfg80211.connect_status == ITM_CONNECTED) {
1622 cfg80211_disconnected(vif->ndev, status_code, NULL, 0,
1626 printkd("%s(), err\n", __func__);
1630 void cfg80211_unlink_ssid(unsigned char vif_id, unsigned char *bssid, unsigned char *ssid, int ssid_len)
1633 struct cfg80211_bss *bss = NULL;
1634 struct wiphy *wiphy = NULL;
1636 buf_scan_frame_t *scan_buf;
1638 vif = id_to_vif(vif_id);
1639 wiphy = vif->wdev.wiphy;
1640 bss = cfg80211_get_bss(wiphy, NULL,bssid,ssid,ssid_len,WLAN_CAPABILITY_ESS,WLAN_CAPABILITY_ESS);
1643 cfg80211_unlink_bss(wiphy, bss);
1644 vif->beacon_loss = 0;
1645 printkd("[%s][unlink][%s]\n",__func__, ssid);
1647 for (i = 0; i < MAX_SCAN_FRAME_BUF_NUM; i++)
1649 scan_buf = (buf_scan_frame_t *) (vif->
1650 cfg80211.scan_frame_array +
1651 i * sizeof(buf_scan_frame_t));
1652 if (0xff != scan_buf->live)
1654 if (0 != memcmp(bssid, scan_buf->bssid, 6))
1656 if(ssid_len != strlen(scan_buf->ssid) )
1658 if( 0 != strncmp(ssid, scan_buf->ssid, ssid_len) )
1660 memset((char *)(scan_buf), 0, sizeof(buf_scan_frame_t) );
1661 printkd("[%s][clear][%s]\n",__func__, ssid);
1667 void cfg80211_report_disconnect_done(unsigned char vif_id, unsigned char *pData,
1670 struct cfg80211_bss *bss = NULL;
1671 unsigned short reason_code = 0;
1673 wlan_vif_t *vif = id_to_vif(vif_id);
1674 printkd("%s()\n", __func__);
1676 cfg80211_unlink_ssid(vif_id, vif->cfg80211.bssid, vif->cfg80211.ssid, vif->cfg80211.ssid_len );
1678 /* This should filled if disconnect reason is not only one */
1679 memcpy(&reason_code, pData, 2);
1680 if (vif->cfg80211.scan_request
1681 && (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) == 1)) {
1682 del_timer_sync(&vif->cfg80211.scan_timeout);
1683 cfg80211_scan_done(vif->cfg80211.scan_request, true);
1684 vif->cfg80211.scan_request = NULL;
1685 #ifdef CONFIG_HAS_WAKELOCK
1686 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1
1687 && vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
1688 wake_unlock(&vif->cfg80211.scan_done_lock);
1690 atomic_dec(&vif->cfg80211.scan_status);
1692 if (vif->cfg80211.connect_status == ITM_CONNECTING) {
1693 cfg80211_connect_result(vif->ndev,
1694 vif->cfg80211.bssid, NULL, 0,
1696 WLAN_STATUS_UNSPECIFIED_FAILURE,
1698 } else if (vif->cfg80211.connect_status == ITM_CONNECTED) {
1699 if (reason_code == AP_LEAVING /*||
1700 reason_code == AP_DEAUTH */) {
1702 bss = cfg80211_get_bss(vif->wdev.wiphy, NULL,
1703 vif->cfg80211.bssid,
1705 vif->cfg80211.ssid_len,
1706 WLAN_CAPABILITY_ESS,
1707 WLAN_CAPABILITY_ESS);
1709 cfg80211_unlink_bss(vif->wdev.wiphy,
1717 cfg80211_disconnected(vif->ndev, reason_code,
1718 NULL, 0, GFP_KERNEL);
1721 vif->cfg80211.connect_status = ITM_DISCONNECTED;
1722 if (netif_carrier_ok(vif->ndev)) {
1723 printkd("netif_carrier_off\n");
1724 netif_carrier_off(vif->ndev);
1725 netif_stop_queue(vif->ndev);
1730 static void wlan_scan_timeout(unsigned long data)
1732 wlan_vif_t *vif = (wlan_vif_t *) data;
1734 printkd("%s()\n", __func__);
1735 if (vif->cfg80211.scan_request
1736 && (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) == 1)) {
1737 printkd("scan timer expired!\n");
1738 cfg80211_scan_done(vif->cfg80211.scan_request, true);
1739 vif->cfg80211.scan_request = NULL;
1740 #ifdef CONFIG_HAS_WAKELOCK
1741 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1
1742 && vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
1743 wake_unlock(&vif->cfg80211.scan_done_lock);
1745 atomic_dec(&vif->cfg80211.scan_status);
1746 printkd("%s() end\n", __func__);
1751 printkd("%s() end, wrong scan timer expired!\n", __func__);
1755 void cfg80211_report_scan_done(unsigned char vif_id, unsigned char *pData,
1756 int len, bool aborted)
1758 struct ieee80211_mgmt *mgmt;
1759 struct ieee80211_channel *channel;
1760 struct ieee80211_supported_band *band;
1761 struct wiphy *wiphy;
1762 struct cfg80211_bss *itm_bss = NULL;
1763 unsigned char ssid[33] = { 0 };
1764 unsigned char bssid[6] = { 0 };
1765 unsigned int mgmt_len = 0;
1766 unsigned short channel_num, channel_len;
1767 unsigned short rssi_len;
1771 unsigned int left = len;
1772 wlan_vif_t *vif = id_to_vif(vif_id);
1773 const unsigned char *pos = pData;
1775 wiphy = vif->wdev.wiphy;
1776 printkd("%s()\n", __func__);
1777 if (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) == 0) {
1778 printkd("scan event is aborted\n");
1782 if (!vif->cfg80211.scan_request) {
1783 printkd("vif->cfg80211.scan_request is null\n");
1784 atomic_dec(&vif->cfg80211.scan_status);
1788 if (left < 10 || aborted) {
1789 printkd("filled event len(%d) is not a valid len\n", len);
1793 mgmt = kmalloc(left, GFP_KERNEL);
1795 printkd("[%s][%d]\n", __func__, left);
1798 while (left >= 10) {
1799 /* must use memcpy to protect unaligned */
1800 /* The formate of frame is len(two bytes) + data */
1801 memcpy(&channel_len, pos, 2);
1804 if (channel_len > 2) {
1805 ASSERT("channel_len %u > 2\n", channel_len);
1809 memcpy(&channel_num, pos, channel_len);
1811 left -= channel_len;
1812 /* The second two value of frame is rssi */
1813 memcpy(&rssi_len, pos, 2);
1816 memcpy(&rssi, pos, rssi_len);
1819 /* The third two value of frame is following data len */
1820 memcpy(&mgmt_len, pos, 2);
1824 if (mgmt_len > left) {
1825 printkd("mgmt_len(0x%08x) > left(0x%08x)!\n", mgmt_len,
1831 /* The following is real data */
1832 memcpy(mgmt, pos, mgmt_len);
1836 /* FIXME Now only support 2GHZ */
1837 band = wiphy->bands[IEEE80211_BAND_2GHZ];
1838 freq = ieee80211_channel_to_frequency(channel_num, band->band);
1839 channel = ieee80211_get_channel(wiphy, freq);
1841 printkd("freq is %d\n", freq);
1845 /*printkd("[report][%s][%d][%d]\n",ssid, channel_num, signal); */
1847 cfg80211_inform_bss_frame(wiphy, channel, mgmt,
1848 le16_to_cpu(mgmt_len), signal,
1851 if (unlikely(!itm_bss))
1852 printkd("cfg80211_inform_bss_frame error\n");
1853 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
1854 cfg80211_put_bss(wiphy, itm_bss);
1856 cfg80211_put_bss(itm_bss);
1866 del_timer_sync(&vif->cfg80211.scan_timeout);
1867 cfg80211_scan_done(vif->cfg80211.scan_request, aborted);
1868 vif->cfg80211.scan_request = NULL;
1869 #ifdef CONFIG_HAS_WAKELOCK
1870 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1
1871 && vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
1872 wake_unlock(&vif->cfg80211.scan_done_lock);
1874 atomic_dec(&vif->cfg80211.scan_status);
1876 printkd("%s(), ok!\n", __func__);
1880 del_timer_sync(&vif->cfg80211.scan_timeout);
1881 cfg80211_scan_done(vif->cfg80211.scan_request, true);
1882 vif->cfg80211.scan_request = NULL;
1883 #ifdef CONFIG_HAS_WAKELOCK
1884 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1 &&
1885 vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
1886 wake_unlock(&vif->cfg80211.scan_done_lock);
1888 atomic_dec(&vif->cfg80211.scan_status);
1890 printkd("%s(), err\n", __func__);
1894 void cfg80211_report_scan_frame(unsigned char vif_id, unsigned char *pData,
1897 struct cfg80211_bss *bss = NULL;
1900 buf_scan_frame_t *scan_buf;
1901 wlan_event_scan_rsp_t *event;
1903 unsigned char ssid[33] = { 0 };
1904 unsigned char bssid[6] = { 0 };
1906 struct ieee80211_channel *channel = NULL;
1907 struct ieee80211_supported_band *band = NULL;
1908 struct wiphy *wiphy = NULL;
1909 struct cfg80211_bss *itm_bss = NULL;
1910 struct ieee80211_mgmt *mgmt = NULL;
1913 u16 capability, beacon_interval;
1917 vif = id_to_vif(vif_id);
1918 wiphy = vif->wdev.wiphy;
1919 event = (wlan_event_scan_rsp_t *) (pData);
1920 if (((event->frame_len + sizeof(wlan_event_scan_rsp_t)) > len)
1921 || (event->ops > 2)) {
1922 printkd("[%s %d][line %d err]\n", __func__, vif_id, __LINE__);
1925 if (0 == event->ops) {
1926 if (event->frame_len < 37) {
1927 printkd("[%s %d][line %d err]\n", __func__, vif_id,
1931 msa = (unsigned char *)(event + 1);
1932 get_ssid(msa, ssid);
1933 get_bssid(msa, bssid);
1934 /*if (0 == strlen(ssid)) {
1935 printkd("[%s %d][line %d err]\n", __func__, vif_id,
1939 if (1024 < event->frame_len) {
1940 printkd("[%s %d][line %d err]\n", __func__, vif_id,
1944 for (i = 0; i < MAX_SCAN_FRAME_BUF_NUM; i++) {
1946 (buf_scan_frame_t *) (vif->
1947 cfg80211.scan_frame_array +
1948 i * sizeof(buf_scan_frame_t));
1949 if (0xff != scan_buf->live)
1951 if (0 != memcmp(bssid, scan_buf->bssid, 6))
1953 strcpy(scan_buf->ssid, ssid);
1954 memcpy(scan_buf->msa, msa, event->frame_len);
1955 scan_buf->msa_len = event->frame_len;
1956 scan_buf->channel = event->channel;
1957 scan_buf->signal = event->signal;
1958 scan_buf->live = 0xff;
1962 for (i = 0; i < MAX_SCAN_FRAME_BUF_NUM; i++) {
1964 (buf_scan_frame_t *) (vif->
1965 cfg80211.scan_frame_array +
1966 i * sizeof(buf_scan_frame_t));
1967 if (0xff == scan_buf->live)
1969 memcpy(scan_buf->bssid, bssid, 6);
1970 strcpy(scan_buf->ssid, ssid);
1971 memcpy(scan_buf->msa, msa, event->frame_len);
1972 scan_buf->msa_len = event->frame_len;
1973 scan_buf->channel = event->channel;
1974 scan_buf->signal = event->signal;
1976 scan_buf->live = 0xff;
1977 printkd("[netif:%d find_ssid][%s][%d][%d]\n", vif_id,
1978 scan_buf->ssid, scan_buf->channel,
1984 if (1 != event->ops) {
1985 printkd("[%s %d][line %d err]\n", __func__, vif_id, __LINE__);
1988 if (!vif->cfg80211.scan_request) {
1989 printkd("[%s %d][line %d err]\n", __func__, vif_id, __LINE__);
1990 atomic_dec(&vif->cfg80211.scan_status);
1993 if (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) == 0) {
1994 printkd("[%s %d][line %d err]\n", __func__, vif_id, __LINE__);
1997 if (!vif->cfg80211.scan_request) {
1998 printkd("[%s %d][line %d err]\n", __func__, vif_id, __LINE__);
1999 atomic_dec(&vif->cfg80211.scan_status);
2003 band = wiphy->bands[IEEE80211_BAND_2GHZ];
2004 for (i = 0; i < MAX_SCAN_FRAME_BUF_NUM; i++) {
2006 (buf_scan_frame_t *) (vif->cfg80211.scan_frame_array +
2007 i * sizeof(buf_scan_frame_t));
2008 if (0xff != scan_buf->live)
2010 if (0 == scan_buf->keep) {
2011 printkd("[netif:%d leave_ssid][%s][%d][%d]\n", vif_id,
2012 scan_buf->ssid, event->channel, event->signal);
2013 memset((char *)scan_buf, 0, sizeof(buf_scan_frame_t));
2018 ieee80211_channel_to_frequency(scan_buf->channel,
2020 channel = ieee80211_get_channel(wiphy, freq);
2022 printkd("[%s %d][line %d err]\n", __func__, vif_id,
2026 mgmt = (struct ieee80211_mgmt *)(&scan_buf->msa[0]);
2027 tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
2028 capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
2029 beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
2030 ie = mgmt->u.probe_resp.variable;
2032 le16_to_cpu(scan_buf->msa_len) -
2033 offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
2034 signal = scan_buf->signal;
2035 signal = signal * 100;
2036 wiphy_info(wiphy, " %s, " MACSTR ", channel %2u, signal %d\n",
2037 ieee80211_is_probe_resp(mgmt->frame_control)
2038 ? "proberesp" : "beacon ",
2039 MAC2STR(mgmt->bssid), scan_buf->channel,
2042 cfg80211_inform_bss(wiphy, channel, mgmt->bssid, tsf,
2043 capability, beacon_interval, ie, ielen,
2044 signal, GFP_KERNEL);
2045 if (unlikely(!itm_bss))
2046 printkd("[%s %d][line %d err]\n", __func__, vif_id,
2048 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2049 cfg80211_put_bss(wiphy, itm_bss);
2051 cfg80211_put_bss(itm_bss);
2056 if (vif->beacon_loss) {
2057 bss = cfg80211_get_bss(wiphy, NULL,
2058 vif->cfg80211.bssid,
2060 vif->cfg80211.ssid_len,
2061 WLAN_CAPABILITY_ESS,
2062 WLAN_CAPABILITY_ESS);
2064 cfg80211_unlink_bss(wiphy, bss);
2065 wiphy_info(wiphy, "find beacon loss event " MACSTR "",
2066 MAC2STR(bss->bssid));
2067 vif->beacon_loss = 0;
2071 if (-1 == report_null) {
2072 printkd("[%s %d][report-ssid][NULL]\n", __func__, vif_id);
2074 del_timer_sync(&vif->cfg80211.scan_timeout);
2075 cfg80211_scan_done(vif->cfg80211.scan_request, false);
2076 vif->cfg80211.scan_request = NULL;
2077 #ifdef CONFIG_HAS_WAKELOCK
2078 if (vif->cfg80211.scan_done_lock.link.next != LIST_POISON1
2079 && vif->cfg80211.scan_done_lock.link.prev != LIST_POISON2)
2080 wake_unlock(&vif->cfg80211.scan_done_lock);
2082 atomic_dec(&vif->cfg80211.scan_status);
2083 /*memset(vif->cfg80211.scan_frame_array, 0, */
2084 /*MAX_SCAN_FRAME_BUF_NUM * sizeof(buf_scan_frame_t)); */
2085 printkd("[%s %d] ok!\n", __func__, vif_id);
2089 void cfg80211_report_mic_failure(unsigned char vif_id,
2090 unsigned char *pdata, int len)
2092 struct wlan_event_mic_failure *mic_failure;
2095 mic_failure = (struct wlan_event_mic_failure *)pdata;
2096 vif = id_to_vif(vif_id);
2098 /* debug info,Pls remove it in the future */
2100 ("[%s %d] is_mcast:0x%x key_id: 0x%x bssid: %x %x %x %x %x %x\n",
2101 __func__, vif_id, mic_failure->is_mcast,
2102 mic_failure->key_id, vif->cfg80211.bssid[0],
2103 vif->cfg80211.bssid[1], vif->cfg80211.bssid[2],
2104 vif->cfg80211.bssid[3], vif->cfg80211.bssid[4],
2105 vif->cfg80211.bssid[5]);
2106 cfg80211_michael_mic_failure(vif->ndev, vif->cfg80211.bssid,
2107 (mic_failure->is_mcast ?
2108 NL80211_KEYTYPE_GROUP :
2109 NL80211_KEYTYPE_PAIRWISE),
2110 mic_failure->key_id, NULL,
2115 void cfg80211_report_cqm_low(unsigned char vif_id,
2116 unsigned char *pdata, int len)
2118 wlan_vif_t *vif = id_to_vif(vif_id);
2121 struct wiphy *wiphy = vif->wdev.wiphy;
2122 wiphy_info(wiphy, "Recv NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW");
2123 if (sprdwl_find_ssid_count(vif) >= 2) {
2124 cfg80211_cqm_rssi_notify(vif->ndev,
2125 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2131 void cfg80211_report_cqm_high(unsigned char vif_id,
2132 unsigned char *pdata, int len)
2134 wlan_vif_t *vif = id_to_vif(vif_id);
2137 struct wiphy *wiphy = vif->wdev.wiphy;
2139 "Recv NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH");
2140 if (sprdwl_find_ssid_count(vif) >= 2) {
2141 cfg80211_cqm_rssi_notify(vif->ndev,
2142 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2148 void cfg80211_report_cqm_beacon_loss(unsigned char vif_id,
2149 unsigned char *pdata, int len)
2151 wlan_vif_t *vif = id_to_vif(vif_id);
2152 cfg80211_unlink_ssid(vif_id, vif->cfg80211.bssid, vif->cfg80211.ssid, vif->cfg80211.ssid_len );
2154 struct wiphy *wiphy = vif->wdev.wiphy;
2155 wiphy_info(wiphy, "Recv NL80211_CQM_RSSI_BEACON_LOSS_EVENT");
2156 vif->beacon_loss = 1;
2158 TODO wpa_supplicant not support the event ,
2159 so we workaround this issue
2161 cfg80211_cqm_rssi_notify(vif->ndev,
2162 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2167 void cfg80211_report_version(unsigned char vif_id,
2168 unsigned char *pdata, int len)
2170 unsigned char wifi_info[100] = { 0 };
2171 struct file *fp = 0;
2174 ("[wifi driver version is 0x%04x] [cp version is 0x%04x date is 0x%04x]\n",
2175 g_wlan.version, *((int *)(pdata + 4)), *((int *)pdata));
2177 fp = filp_open(WIFI_VERSION_FILE, O_CREAT | O_RDWR, 0666);
2179 printke("%s %d err\n", __func__, __LINE__);
2184 "[wifi driver version is 0x%04x] [cp version is 0x%2x date is 0x%04x]",
2185 g_wlan.version, *((int *)(pdata + 4)), *((int *)pdata));
2186 vfs_write(fp, wifi_info, strlen(wifi_info), pos);
2190 filp_close(fp, NULL);
2194 void cfg80211_report_mlme_tx_status(unsigned char vif_id,
2195 unsigned char *pdata, int len)
2197 struct wlan_report_mgmt_tx_status *tx_status = NULL;
2200 vif = id_to_vif(vif_id);
2201 tx_status = (struct wlan_report_mgmt_tx_status *)pdata;
2202 printkd("[%s]: index: %lld\n", __func__, tx_status->cookie);
2203 printkd("data len is %d\n", len);
2204 hex_dump("receive is:", strlen("receive is:"), pdata, len);
2205 cfg80211_mgmt_tx_status(&vif->wdev, tx_status->cookie, tx_status->buf,
2206 tx_status->len, tx_status->ack, GFP_KERNEL);
2207 printkd("cfg80211_mgmt_tx_status end\n");
2210 static int wlan_cfg80211_mgmt_tx(struct wiphy *wiphy,
2211 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2212 struct wireless_dev *wdev,
2214 struct net_device *ndev,
2216 #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || \
2217 defined(COMPAT_KERNEL_RELEASE))
2218 struct ieee80211_channel *chan, bool offchan,
2219 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
2220 enum nl80211_channel_type channel_type,
2221 bool channel_type_valid,
2224 #else /*(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) */
2225 struct ieee80211_channel *chan,
2226 enum nl80211_channel_type channel_type,
2227 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || \
2228 defined(COMPAT_KERNEL_RELEASE)
2229 bool channel_type_valid,
2231 #endif /*(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) */
2232 const u8 *buf, size_t len,
2233 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
2236 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
2237 bool dont_wait_for_ack,
2243 unsigned char vif_id;
2244 static u64 mgmt_index = 0;
2247 vif = ndev_to_vif(wdev->netdev);
2249 if (ITM_NONE_MODE == vif->mode) {
2250 printke("%s err\n", __func__);
2254 printkd("[%s][%d]enter\n", __func__, vif_id);
2255 printkd("[%s], index: %lld, cookie: %lld\n", __func__, mgmt_index,
2257 *cookie = mgmt_index;
2260 wlan_cmd_set_tx_mgmt(vif_id, chan, dont_wait_for_ack, wait,
2263 if (dont_wait_for_ack == false)
2264 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len,
2266 printkd("[%s] Failed to set tx mgmt!\n", __func__);
2273 static void wlan_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
2274 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2275 struct wireless_dev *wdev,
2277 struct net_device *ndev,
2279 u16 frame_type, bool reg)
2282 unsigned char vif_id;
2283 vif = ndev_to_vif(wdev->netdev);
2285 if (ITM_NONE_MODE == vif->mode)
2287 if (NETIF_0_ID == vif_id)
2289 printkd("[%s][%d]\n", __func__, vif_id);
2290 register_frame(vif, frame_type, reg);
2294 static int wlan_change_beacon(wlan_vif_t *vif,
2295 struct cfg80211_beacon_data *beacon)
2300 unsigned char vif_id = vif->id;
2302 printkd("%s enter\n", __func__);
2303 #ifdef WIFI_DIRECT_SUPPORT
2304 /* send beacon extra ies */
2305 if (beacon->head != NULL) {
2306 ie_len = beacon->head_len;
2307 ie_ptr = kmalloc(ie_len, GFP_KERNEL);
2308 if (ie_ptr == NULL) {
2309 printkd("[%s][%d][%d]\n", __func__, __LINE__, ie_ptr);
2312 memcpy(ie_ptr, beacon->head, ie_len);
2313 printkd("begin send beacon head ies\n");
2316 wlan_cmd_set_p2p_ie(vif_id, P2P_BEACON_IE_HEAD, ie_ptr,
2320 ("itm_wlan_set_p2p_ie beacon_ies head failed with ret %d\n",
2323 printkd("send beacon head ies successfully\n");
2329 /* send beacon extra ies */
2330 if (beacon->tail != NULL) {
2331 ie_len = beacon->tail_len;
2333 ie_ptr = kmalloc(ie_len, GFP_KERNEL);
2334 if (ie_ptr == NULL) {
2335 printkd("[%s][%d][%d]\n", __func__, __LINE__, ie_ptr);
2338 memcpy(ie_ptr, beacon->tail, ie_len);
2339 printkd("begin send beacon tail ies\n");
2341 ret = wlan_cmd_set_p2p_ie(vif_id,
2342 P2P_BEACON_IE_TAIL, ie_ptr, ie_len);
2345 ("wlan_cmd_set_p2p_ie beacon_ies tail failed with ret %d\n",
2348 printkd("send beacon tail ies successfully\n");
2354 /* send probe response ies */
2356 /* send beacon extra ies */
2357 if (beacon->beacon_ies != NULL) {
2358 ie_len = beacon->beacon_ies_len;
2360 ie_ptr = kmalloc(ie_len, GFP_KERNEL);
2361 if (ie_ptr == NULL) {
2362 printkd("[%s][%d][%d]\n", __func__, __LINE__, ie_ptr);
2365 memcpy(ie_ptr, beacon->beacon_ies, ie_len);
2366 printkd("begin send beacon extra ies\n");
2369 wlan_cmd_set_p2p_ie(vif_id, P2P_BEACON_IE, ie_ptr, ie_len);
2372 ("wlan_cmd_set_p2p_ie beacon_ies failed with ret %d\n",
2375 printkd("send beacon extra ies successfully\n");
2381 /* send probe response ies */
2383 if (beacon->proberesp_ies != NULL) {
2384 printkd("%s line:%d\n", __func__, __LINE__);
2385 ie_len = beacon->proberesp_ies_len;
2387 ie_ptr = kmalloc(ie_len, GFP_KERNEL);
2388 if (ie_ptr == NULL) {
2389 printkd("[%s][%d][%d]\n", __func__, __LINE__, ie_ptr);
2392 memcpy(ie_ptr, beacon->proberesp_ies, ie_len);
2393 printkd("begin send probe response extra ies\n");
2396 wlan_cmd_set_p2p_ie(vif_id, P2P_PROBERESP_IE, ie_ptr,
2400 ("wlan_cmd_set_p2p_ie proberesp_ies failed with ret %d\n",
2403 printkd("send probe response ies successfully\n");
2409 /* send associate response ies */
2411 if (beacon->assocresp_ies != NULL) {
2412 printkd("%s line:%d\n", __func__, __LINE__);
2413 ie_len = beacon->assocresp_ies_len;
2415 ie_ptr = kmalloc(ie_len, GFP_KERNEL);
2416 if (ie_ptr == NULL) {
2417 printkd("[%s][%d][%d]\n", __func__, __LINE__, ie_ptr);
2420 memcpy(ie_ptr, beacon->assocresp_ies, ie_len);
2421 printkd("begin send associate response extra ies\n");
2424 wlan_cmd_set_p2p_ie(vif_id, P2P_ASSOCRESP_IE, ie_ptr,
2428 ("wlan_cmd_set_p2p_ie assocresp_ies failed with ret %d\n",
2431 printkd("send associate response ies successfully\n");
2436 #endif /*WIFI_DIRECT_SUPPORT */
2440 static int itm_wlan_start_ap(wlan_vif_t *vif,
2441 struct cfg80211_beacon_data *beacon)
2443 #define SSID_LEN_OFFSET (37)
2444 struct ieee80211_mgmt *mgmt;
2445 u16 mgmt_len, index = 0;
2447 unsigned char vif_id = vif->id;
2449 struct wlan_cmd_hidden_ssid *hssid = &(vif->hssid);
2450 printkd("%s enter\n", __func__);
2451 wlan_change_beacon(vif, beacon);
2452 if (beacon->head == NULL) {
2453 printke("%s line:%d err\n", __func__, __LINE__);
2456 mgmt_len = beacon->head_len;
2458 /*add 1 byte for hidden ssid flag */
2462 mgmt_len += beacon->tail_len;
2464 mgmt = kmalloc(mgmt_len, GFP_KERNEL);
2466 printkd("[%s][%d][%d]\n", __func__, __LINE__, mgmt);
2471 memcpy(data, beacon->head, SSID_LEN_OFFSET);
2472 index += SSID_LEN_OFFSET;
2474 /*hostapd config ssid by ioctl */
2475 if (hssid->ssid_len == (unsigned char)*(beacon->head + index)) {
2476 /*modify ssid_len */
2477 *(data + index) = (unsigned char)(hssid->ssid_len + 1);
2480 memcpy(data + index, hssid->ssid, hssid->ssid_len);
2481 index += hssid->ssid_len;
2482 /*set hidden ssid flag */
2483 *(data + index) = (unsigned char)(hssid->ignore_broadcast_ssid);
2485 } else { /*hostapd not config ssid */
2486 unsigned char org_len = (unsigned char)*(beacon->head + index);
2487 /*modify ssid_len */
2488 *(data + index) = org_len + 1;
2491 memcpy(data + index, beacon->head + index, org_len);
2493 /*set no hidden ssid flag */
2494 *(data + index) = 0;
2498 memcpy(data + index, beacon->head + index - 1,
2499 beacon->head_len + 1 - index);
2502 memcpy(data + beacon->head_len + 1,
2503 beacon->tail, beacon->tail_len);
2505 ret = wlan_cmd_start_ap(vif_id, (unsigned char *)mgmt, mgmt_len);
2507 if (!netif_carrier_ok(vif->ndev)) {
2508 printkd("%s(), netif_carrier_on, ssid:%s\n", __func__,
2509 vif->cfg80211.ssid);
2510 netif_carrier_on(vif->ndev);
2511 netif_wake_queue(vif->ndev);
2514 printke("%s line:%d err\n", __func__, __LINE__);
2519 static int wlan_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
2520 struct cfg80211_ap_settings *info)
2523 unsigned char vif_id;
2524 vif = ndev_to_vif(ndev);
2526 if (ITM_NONE_MODE == vif->mode)
2528 printkd("[%s][%d] enter\n", __func__, vif_id);
2529 if (info->ssid == NULL) {
2530 printkd("%s line:%d\n", __func__, __LINE__);
2533 printkd("[cfg80211] \t ==>>>%s\n", __func__);
2534 memcpy(vif->cfg80211.ssid, info->ssid, info->ssid_len);
2535 vif->cfg80211.ssid_len = info->ssid_len;
2536 return itm_wlan_start_ap(vif, &info->beacon);
2539 static int wlan_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
2543 unsigned char vif_id;
2544 vif = ndev_to_vif(ndev);
2546 if (ITM_NONE_MODE == vif->mode)
2548 printkd("[%s][%d] enter\n", __func__, vif_id);
2549 ret = wlan_cmd_mac_close(vif_id, vif->mode);
2553 static int wlan_cfg80211_change_beacon(struct wiphy *wiphy,
2554 struct net_device *ndev,
2555 struct cfg80211_beacon_data *beacon)
2558 unsigned char vif_id;
2559 vif = ndev_to_vif(ndev);
2561 if (ITM_NONE_MODE == vif->mode)
2563 printkd("[%s][%d] enter\n", __func__, vif_id);
2564 #ifdef WIFI_DIRECT_SUPPORT
2565 return wlan_change_beacon(vif, beacon);
2567 return itm_wlan_start_ap(vif, beacon);
2572 static int itm_wlan_change_mode(wlan_vif_t *vif, enum nl80211_iftype type)
2576 unsigned char vif_id = vif->id;
2578 case NL80211_IFTYPE_STATION:
2579 if (NETIF_0_ID == vif->id)
2580 mode = ITM_STATION_MODE;
2582 mode = ITM_P2P_CLIENT_MODE;
2584 case NL80211_IFTYPE_AP:
2585 if (NETIF_0_ID == vif->id)
2588 mode = ITM_P2P_GO_MODE;
2590 case NL80211_IFTYPE_P2P_CLIENT:
2591 mode = ITM_P2P_CLIENT_MODE;
2593 case NL80211_IFTYPE_P2P_GO:
2594 mode = ITM_P2P_GO_MODE;
2597 printkd("invalid interface type %u\n", type);
2600 vif->wdev.iftype = type;
2601 if (mode == vif->mode) {
2602 printkd("not need change mode\n");
2605 vif->wdev.iftype = type;
2607 printkd("[%s][%d][%d]\n", __func__, vif_id, mode);
2608 ret = wlan_cmd_mac_open(vif_id, mode, vif->ndev->dev_addr);
2611 vif->wdev.iftype = type;
2613 #ifdef CONFIG_MACH_SAMSUNG
2614 wlan_cmd_set_psm_cap();
2619 static int wlan_cfg80211_change_iface(struct wiphy *wiphy,
2620 struct net_device *ndev,
2621 enum nl80211_iftype type,
2622 unsigned int *flags,
2623 struct vif_params *params)
2626 unsigned char vif_id;
2627 vif = ndev_to_vif(ndev);
2629 #ifdef WIFI_DIRECT_SUPPORT
2630 if (NETIF_1_ID == vif_id) {
2631 vif->cfg80211.p2p_mode = itm_get_p2p_mode_from_file();
2632 printkd("[%s][%d][%d]\n", __func__, vif_id,
2633 (vif->cfg80211.p2p_mode ? 1 : 0));
2635 #endif /* WIFI_DIRECT_SUPPORT */
2636 return itm_wlan_change_mode(vif, type);
2639 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2640 static int wlan_cfg80211_set_channel(struct wiphy *wiphy,
2641 struct net_device *ndev,
2642 struct ieee80211_channel *channel)
2644 static int wlan_cfg80211_set_channel(struct wiphy *wiphy,
2645 struct net_device *ndev,
2646 struct ieee80211_channel *channel,
2647 enum nl80211_channel_type channel_type)
2650 int ret = -ENOTSUPP;
2652 unsigned char vif_id;
2653 vif = ndev_to_vif(ndev);
2655 if (ITM_NONE_MODE == vif->mode)
2657 printkd("[%s][%d] enter\n", __func__, vif_id);
2659 * FIXME: To be handled properly when monitor mode is supported.
2662 wlan_cmd_set_channel(vif_id,
2663 ieee80211_frequency_to_channel
2664 (channel->center_freq));
2666 printkd("wlan_cmd_set_channel failed with ret %d\n", ret);
2673 int wlan_cfg80211_update_ft_ies(struct wiphy *wiphy, struct net_device *ndev,
2674 struct cfg80211_update_ft_ies_params *ftie)
2677 unsigned char vif_id;
2678 vif = ndev_to_vif(ndev);
2680 printkd("%s enter\n", __func__);
2681 return wlan_cmd_update_ft_ies(vif_id, ftie);
2684 static void wlan_cfg80211_reg_notify(struct wiphy *wiphy,
2685 struct regulatory_request *request)
2687 struct ieee80211_supported_band *sband;
2688 struct ieee80211_channel *chan;
2689 const struct ieee80211_freq_range *freq_range;
2690 const struct ieee80211_reg_rule *reg_rule;
2691 wlan_ieee80211_regdomain *rd = NULL;
2692 u32 band, channel, i;
2693 u32 last_start_freq;
2694 u32 n_rules = 0, rd_size;
2697 wiphy_info(wiphy, "%s %c%c initiator %d hint_type %d\n", __func__,
2698 request->alpha2[0], request->alpha2[1], request->initiator,
2699 request->user_reg_hint_type);
2701 if ((num != 1) && (num != 2)) {
2706 /* Figure out the actual rule number */
2707 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2708 sband = wiphy->bands[band];
2712 last_start_freq = 0;
2713 for (channel = 0; channel < sband->n_channels; channel++) {
2714 chan = &sband->channels[channel];
2717 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
2718 if (IS_ERR(reg_rule))
2721 freq_range = ®_rule->freq_range;
2722 if (last_start_freq != freq_range->start_freq_khz) {
2723 last_start_freq = freq_range->start_freq_khz;
2728 rd_size = sizeof(wlan_ieee80211_regdomain) +
2729 n_rules * sizeof(struct ieee80211_reg_rule);
2731 rd = kzalloc(rd_size, GFP_KERNEL);
2734 "Failed to allocate itm_ieee80211_regdomain\n");
2738 /* Fill regulatory domain */
2739 rd->n_reg_rules = n_rules;
2740 memcpy(rd->alpha2, request->alpha2, ARRAY_SIZE(rd->alpha2));
2741 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2742 sband = wiphy->bands[band];
2746 last_start_freq = 0;
2747 for (channel = i = 0; channel < sband->n_channels; channel++) {
2748 chan = &sband->channels[channel];
2750 if (chan->flags & IEEE80211_CHAN_DISABLED)
2754 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
2755 if (IS_ERR(reg_rule))
2758 freq_range = ®_rule->freq_range;
2759 if (last_start_freq != freq_range->start_freq_khz
2761 last_start_freq = freq_range->start_freq_khz;
2762 memcpy(&rd->reg_rules[i], reg_rule,
2763 sizeof(struct ieee80211_reg_rule));
2766 "%s %d KHz - %d KHz @ %d KHz flags %#x\n",
2767 __func__, freq_range->start_freq_khz,
2768 freq_range->end_freq_khz,
2769 freq_range->max_bandwidth_khz,
2774 if (wlan_cmd_set_regdom(0, (u8 *) rd, rd_size))
2775 wiphy_err(wiphy, "%s failed to set regdomain!\n", __func__);
2780 int lte_concur_proc_open(struct inode *inode, struct file *filp)
2785 int lte_concur_proc_release(struct inode *inode, struct file *filp)
2790 ssize_t lte_concur_proc_ioctl(struct file *filp, unsigned int cmd,
2794 lte_concur_data_t *val;
2795 unsigned char buff[100];
2798 case LTE_CONCUR_REQ:
2800 (buff, (unsigned char *)arg,
2801 ((lte_concur_data_t *) arg)->size +
2802 sizeof(lte_concur_data_t))) {
2806 val = (lte_concur_data_t *) buff;
2809 wlan_cmd_req_lte_concur(0,
2810 (unsigned char *)val +
2811 sizeof(lte_concur_data_t), len);
2813 printkd("wlan_cmd_req_lte_concur failed with ret %d\n",
2825 * CFG802.11 operation handler for connection quality monitoring.
2827 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
2830 int wlan_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
2831 struct net_device *ndev,
2832 s32 rssi_thold, u32 rssi_hyst)
2834 int ret = -ENOTSUPP;
2835 wlan_vif_t *vif = ndev_to_vif(ndev);
2836 unsigned char vif_id = vif->id;
2837 if (ITM_NONE_MODE == vif->mode)
2839 wiphy_info(wiphy, "[%s][%d] rssi_thold %d rssi_hyst %d",
2840 __func__, vif_id, rssi_thold, rssi_hyst);
2841 if (rssi_thold && rssi_hyst)
2842 ret = wlan_cmd_cmq_rssi(vif_id, rssi_thold, rssi_hyst,
2843 WIFI_CMD_SET_CQM_RSSI);
2847 static struct cfg80211_ops wlan_cfg80211_ops = {
2848 .scan = wlan_cfg80211_scan,
2849 .connect = wlan_cfg80211_connect,
2850 .disconnect = wlan_cfg80211_disconnect,
2851 .add_key = wlan_cfg80211_add_key,
2852 .del_key = wlan_cfg80211_del_key,
2853 .set_default_key = wlan_cfg80211_set_default_key,
2854 .set_wiphy_params = wlan_cfg80211_set_wiphy_params,
2855 .get_station = wlan_cfg80211_get_station,
2856 .set_pmksa = wlan_cfg80211_set_pmksa,
2857 .del_pmksa = wlan_cfg80211_del_pmksa,
2858 .flush_pmksa = wlan_cfg80211_flush_pmksa,
2859 .start_ap = wlan_cfg80211_start_ap,
2860 .change_beacon = wlan_cfg80211_change_beacon,
2861 .stop_ap = wlan_cfg80211_stop_ap,
2862 .mgmt_tx = wlan_cfg80211_mgmt_tx,
2863 .mgmt_frame_register = wlan_cfg80211_mgmt_frame_register,
2864 .change_virtual_intf = wlan_cfg80211_change_iface,
2865 .update_ft_ies = wlan_cfg80211_update_ft_ies,
2866 .set_cqm_rssi_config = wlan_cfg80211_set_cqm_rssi_config,
2867 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2868 .libertas_set_mesh_channel = wlan_cfg80211_set_channel,
2870 .set_channel = wlan_cfg80211_set_channel,
2873 #ifdef WIFI_DIRECT_SUPPORT
2874 .remain_on_channel = wlan_cfg80211_remain_on_channel,
2875 .cancel_remain_on_channel = wlan_cfg80211_cancel_remain_on_channel,
2876 .del_station = wlan_cfg80211_del_station,
2880 /*Init wiphy parameters*/
2881 static void init_wiphy_parameters(struct wiphy *wiphy)
2883 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2884 wiphy->mgmt_stypes = itm_mgmt_stypes;
2886 wiphy->max_scan_ssids = MAX_SITES_FOR_SCAN;
2887 wiphy->max_scan_ie_len = SCAN_IE_LEN_MAX;
2888 wiphy->max_num_pmkids = MAX_NUM_PMKIDS;
2890 wiphy->interface_modes =
2891 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_STATION) |
2892 BIT(NL80211_IFTYPE_AP);
2894 wiphy->interface_modes |=
2895 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO) |
2896 BIT(NL80211_IFTYPE_P2P_DEVICE);
2897 wiphy->max_remain_on_channel_duration = 2000;
2898 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
2899 /* set AP SME flag, also needed by STA mode? */
2900 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
2901 wiphy->ap_sme_capa = 1;
2903 wiphy->software_iftypes =
2904 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_STATION) |
2905 BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_P2P_CLIENT) |
2906 BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_DEVICE);
2907 /*Attach cipher suites */
2908 wiphy->cipher_suites = itm_cipher_suites;
2909 wiphy->n_cipher_suites = ARRAY_SIZE(itm_cipher_suites);
2911 wiphy->bands[IEEE80211_BAND_2GHZ] = &itm_band_2ghz;
2912 /*wiphy->bands[IEEE80211_BAND_5GHZ] = &itm_band_5ghz; */
2914 /*Default not in powersave state */
2915 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
2916 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
2917 #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
2918 /*Set WoWLAN flags */
2919 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT;
2921 wiphy->reg_notifier = wlan_cfg80211_reg_notify;
2924 int wlan_wiphy_new(wlan_info_t *wlan)
2927 printke("%s enter\n", __func__);
2928 wlan->wiphy = wiphy_new(&wlan_cfg80211_ops, 0);
2929 if (wlan->wiphy == NULL) {
2933 *(struct wlan_info_t **)wiphy_priv(wlan->wiphy) = wlan;
2934 set_wiphy_dev(wlan->wiphy, wlan->dev);
2935 init_wiphy_parameters(wlan->wiphy);
2936 ret = wiphy_register(wlan->wiphy);
2938 printke("%s err:%d\n", __func__, ret);
2940 goto out_free_wiphy;
2944 wiphy_free(wlan->wiphy);
2948 int wlan_wiphy_free(wlan_info_t *wlan)
2954 for (i = 0; i < 2; i++) {
2955 vif = &(g_wlan.netif[i]);
2956 if (vif->cfg80211.scan_request
2957 && (atomic_add_unless(&vif->cfg80211.scan_status, 1, 1) ==
2959 if (vif->cfg80211.scan_request->wiphy !=
2962 ("Scan request is from a wrong wiphy device\n");
2964 /*If there's a pending scan request,abort it */
2965 cfg80211_scan_done(vif->cfg80211.scan_request,
2968 vif->cfg80211.scan_request = NULL;
2969 #ifdef CONFIG_HAS_WAKELOCK
2970 if (vif->cfg80211.scan_done_lock.link.next !=
2972 && vif->cfg80211.scan_done_lock.link.prev !=
2974 wake_unlock(&vif->cfg80211.scan_done_lock);
2976 atomic_dec(&vif->cfg80211.scan_status);
2978 #ifdef CONFIG_HAS_WAKELOCK
2979 wake_lock_destroy(&vif->cfg80211.scan_done_lock);
2981 del_timer_sync(&(vif->cfg80211.scan_timeout));
2982 vfree(vif->cfg80211.scan_frame_array);
2983 vif->cfg80211.scan_frame_array = NULL;
2985 wiphy_unregister(wlan->wiphy);
2986 wiphy_free(wlan->wiphy);
2991 int mac_addr_cfg(wlan_vif_t *vif, unsigned char vif_id)
2993 struct file *fp = 0;
2996 bool no_file = false;
2997 unsigned char file_data[64] = { 0 };
2998 unsigned char mac_addr[18] = { 0 };
2999 unsigned char *tmp_p = NULL;
3003 fp = filp_open(ENG_MAC_ADDR_PATH, O_RDONLY, 0);
3005 random_ether_addr(vif->ndev->dev_addr);
3006 #ifdef CONFIG_MACH_SAMSUNG
3007 vif->ndev->dev_addr[0] = 0x00;
3008 vif->ndev->dev_addr[1] = 0x12;
3009 vif->ndev->dev_addr[2] = 0x36;
3010 #endif /* CONFIG_MACH_SAMSUNG */
3011 fp = filp_open(ENG_MAC_ADDR_PATH, O_CREAT | O_RDWR, 0666);
3013 printke("%s %d err\n", __func__, __LINE__);
3019 if (false == no_file) {
3021 vfs_read(fp, file_data, sizeof(file_data), pos);
3022 memcpy(mac_addr, tmp_p, 18);
3023 sscanf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
3024 (unsigned int *)&(vif->ndev->dev_addr[0]),
3025 (unsigned int *)&(vif->ndev->dev_addr[1]),
3026 (unsigned int *)&(vif->ndev->dev_addr[2]),
3027 (unsigned int *)&(vif->ndev->dev_addr[3]),
3028 (unsigned int *)&(vif->ndev->dev_addr[4]),
3029 (unsigned int *)&(vif->ndev->dev_addr[5]));
3030 mac_addr[17] = '\n';
3032 sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X\n",
3033 vif->ndev->dev_addr[0],
3034 vif->ndev->dev_addr[1],
3035 vif->ndev->dev_addr[2],
3036 vif->ndev->dev_addr[3],
3037 vif->ndev->dev_addr[4],
3038 vif->ndev->dev_addr[5]);
3039 vfs_write(fp, mac_addr, 18, pos);
3040 printke("[%s write addr:%s]\n", __func__, mac_addr);
3044 vif->ndev->dev_addr[0] = vif->ndev->dev_addr[0] ^ 0x02;
3046 if (!(IS_ERR(fp))) {
3047 filp_close(fp, NULL);
3050 fp = filp_open(ENG_MAC_ADDR_INFO_PATH, O_CREAT | O_RDWR, 0666);
3052 printke("[%s %s: File create err]\n", __func__, ENG_MAC_ADDR_INFO_PATH);
3055 vfs_write(fp, mac_addr, 18, pos);
3056 printke("[%s write addr:%s to %s]\n", __func__, mac_addr, ENG_MAC_ADDR_INFO_PATH);
3061 if (!(IS_ERR(fp))) {
3062 filp_close(fp, NULL);
3068 int wlan_vif_init(wlan_vif_t *vif, int type, const char *name, void *ops)
3071 struct net_device *ndev;
3072 unsigned char str[64] = { 0 };
3073 ndev = alloc_netdev(4, name, ether_setup);
3079 vif->beacon_loss = 0;
3080 memcpy((unsigned char *)(netdev_priv(ndev)), (unsigned char *)(&vif),
3082 ndev->netdev_ops = ops;
3083 ndev->watchdog_timeo = 1 * HZ;
3084 ndev->ieee80211_ptr = &(vif->wdev);
3085 vif->wdev.iftype = type;
3086 init_register_frame_param(vif);
3087 init_send_deauth_work(vif);
3088 vif->wdev.wiphy = g_wlan.wiphy;
3089 SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
3090 vif->wdev.netdev = ndev;
3091 init_timer(&(vif->cfg80211.scan_timeout));
3092 vif->cfg80211.scan_timeout.data = (unsigned long)vif;
3093 vif->cfg80211.scan_timeout.function = wlan_scan_timeout;
3094 vif->cfg80211.scan_request = NULL;
3095 vif->cfg80211.scan_frame_array =
3096 vmalloc(MAX_SCAN_FRAME_BUF_NUM * sizeof(buf_scan_frame_t));
3097 memset(vif->cfg80211.scan_frame_array, 0,
3098 MAX_SCAN_FRAME_BUF_NUM * sizeof(buf_scan_frame_t));
3099 atomic_set(&vif->cfg80211.scan_status, 0);
3100 vif->cfg80211.connect_status = ITM_DISCONNECTED;
3101 memset(vif->cfg80211.bssid, 0, sizeof(vif->cfg80211.bssid));
3102 vif->mode = ITM_NONE_MODE;
3103 #ifdef CONFIG_HAS_WAKELOCK
3104 wake_lock_init(&(vif->cfg80211.scan_done_lock), WAKE_LOCK_SUSPEND,
3107 mac_addr_cfg(vif, vif->id);
3108 ret = register_netdev(vif->ndev);
3110 printkd("[%s][register_netdev err:%d]\n", __func__, ret);
3113 sprintf(str, "[%s][%d][%s][0x%p][addr]:", __func__, vif->id,
3114 vif->ndev->name, vif->ndev);
3115 hex_dump(str, strlen(str), (unsigned char *)(&(vif->ndev->dev_addr[0])),
3120 int wlan_vif_free(wlan_vif_t *vif)
3122 if (NULL == vif->ndev)
3124 printkd("[unregister_netdev][%s][0x%p]\n", __func__, vif->ndev->name);
3125 cancel_work_sync(&vif->cfg80211.register_frame.work);
3126 cancel_work_sync(&vif->deauth_info.work);
3127 unregister_netdev(vif->ndev);
3128 printkd("[free_netdev][%s][0x%p]\n", __func__, vif->ndev->name);
3129 free_netdev(vif->ndev);
3130 printkd("%s(), ok\n", __func__);
3134 wlan_vif_t *id_to_vif(unsigned char id)
3136 if ((NETIF_0_ID != id) && (NETIF_1_ID != id))
3138 return &(g_wlan.netif[id]);
3141 wlan_vif_t *ndev_to_vif(struct net_device * ndev)
3144 memcpy((unsigned char *)(&vif), (unsigned char *)(netdev_priv(ndev)),