• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * net_bdh_adpater.c
3  *
4  * hdf driver
5  *
6  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22 
23 #include "net_bdh_adpater.h"
24 #include <net/cfg80211.h>
25 #include <securec.h>
26 #include "eapol.h"
27 #include "hdf_wlan_utils.h"
28 #include "hdf_wl_interface.h"
29 #include "hdf_public_ap6275s.h"
30 #include "hdf_wifi_event.h"
31 
32 #define HDF_LOG_TAG BDH6Driver
33 
34 typedef enum {
35     WAL_ADDR_IDX_STA0 = 0,
36     WAL_ADDR_IDX_AP0  = 1,
37     WAL_ADDR_IDX_STA1 = 2,
38     WAL_ADDR_IDX_STA2 = 3,
39     WAL_ADDR_IDX_BUTT
40 } wal_addr_idx;
41 
42 struct wiphy *g_linux_wiphy = NULL;
set_krn_netdev(struct NetDevice * hnetdev,struct net_device * netdev,int ifidx)43 void set_krn_netdev(struct NetDevice *hnetdev, struct net_device *netdev, int ifidx)
44 {
45     g_hdf_infmap[ifidx].hnetdev = hnetdev;
46     g_hdf_infmap[ifidx].netdev = netdev;
47 }
48 
get_hdf_netdev(int ifidx)49 struct NetDevice *get_hdf_netdev(int ifidx)
50 {
51     return g_hdf_infmap[ifidx].hnetdev;
52 }
53 
get_krn_netdev(int ifidx)54 struct net_device *get_krn_netdev(int ifidx)
55 {
56     return g_hdf_infmap[ifidx].netdev;
57 }
58 
get_krn_wiphy(void)59 struct wiphy *get_krn_wiphy(void)
60 {
61     return g_linux_wiphy;
62 }
63 
set_krn_wiphy(struct wiphy * pwiphy)64 void set_krn_wiphy(struct wiphy *pwiphy)
65 {
66     g_linux_wiphy = (struct wiphy *)pwiphy;
67 }
68 struct net_device *GetLinuxInfByNetDevice(const struct NetDevice *netDevice);
69 struct NetDeviceInterFace *wal_get_net_p2p_ops(void);
wal_get_dev_addr_idx(int type)70 static wal_addr_idx wal_get_dev_addr_idx(int type)
71 {
72     wal_addr_idx addr_idx = WAL_ADDR_IDX_BUTT;
73 
74     switch (type) {
75         case NL80211_IFTYPE_STATION:
76             addr_idx = WAL_ADDR_IDX_STA0;
77             break;
78         case NL80211_IFTYPE_AP:
79         case NL80211_IFTYPE_P2P_CLIENT:
80         case NL80211_IFTYPE_P2P_GO:
81         case NL80211_IFTYPE_MESH_POINT:
82             addr_idx = WAL_ADDR_IDX_AP0;
83             break;
84         case NL80211_IFTYPE_P2P_DEVICE:
85             addr_idx = WAL_ADDR_IDX_STA2;
86             break;
87         default:
88             HDF_LOGE("wal_get_dev_addr_idx:: dev type [%d] is not supported !", type);
89             break;
90     }
91 
92     return addr_idx;
93 }
94 
wal_get_dev_addr(unsigned char * pc_addr,unsigned char addr_len,int type)95 int wal_get_dev_addr(unsigned char *pc_addr, unsigned char addr_len, int type)
96 {
97     unsigned char us_addr[MAC_ADDR_SIZE];
98     unsigned int tmp;
99     wal_addr_idx addr_idx;
100     struct net_device *netdev = get_krn_netdev(0);
101 
102     if (pc_addr == NULL) {
103         HDF_LOGE("wal_get_dev_addr:: pc_addr is NULL!");
104         return -1;
105     }
106 
107     addr_idx = wal_get_dev_addr_idx(type);
108     if (addr_idx >= WAL_ADDR_IDX_BUTT) {
109         return -1;
110     }
111 
112     for (tmp = 0; tmp < MAC_ADDR_SIZE; tmp++) {
113         us_addr[tmp] = netdev->dev_addr[tmp];
114     }
115 
116     /* 1.低位自增 2.高位取其进位 3.低位将进位位置0 */
117     us_addr[5] += addr_idx;                      /* 5 地址第6位 */
118     us_addr[4] += ((us_addr[5] & (0x100)) >> 8); /* 4 地址第5位 5 地址第6位 8 右移8位 */
119     us_addr[5] = us_addr[5] & (0xff);            /* 5 地址第6位 */
120     /* 最低位运算完成,下面类似 */
121     us_addr[3] += ((us_addr[4] & (0x100)) >> 8); /* 3 地址第4位 4 地址第5位 8 右移8位 */
122     us_addr[4] = us_addr[4] & (0xff);            /* 4 地址第5位 */
123     us_addr[2] += ((us_addr[3] & (0x100)) >> 8); /* 2 地址第3位 3 地址第4位 8 右移8位 */
124     us_addr[3] = us_addr[3] & (0xff);            /* 3 地址第4位 */
125     us_addr[1] += ((us_addr[2] & (0x100)) >> 8); /* 1 地址第2位 2 地址第3位 8 右移8位 */
126     us_addr[2] = us_addr[2] & (0xff);            /* 2 地址第3位 */
127     us_addr[0] += ((us_addr[1] & (0x100)) >> 8); /* 8 右移8位 */
128     us_addr[1] = us_addr[1] & (0xff);
129     if (us_addr[0] > 0xff) {
130         us_addr[0] = 0;
131     }
132     us_addr[0] &= 0xFE;
133 
134     for (tmp = 0; tmp < addr_len; tmp++) {
135         pc_addr[tmp] = us_addr[tmp];
136     }
137 
138     return 0;
139 }
140 
P2pInitNetdev(struct NetDevice * netDevice,WifiIfAdd * ifAdd,int private_data_size,int ifidx)141 int P2pInitNetdev(struct NetDevice *netDevice, WifiIfAdd *ifAdd, int private_data_size, int ifidx)
142 {
143     struct NetDevice *hnetdev = NULL;
144     char ifName[IFNAMSIZ] = {0};
145     struct HdfWifiNetDeviceData *data = NULL;
146     struct net_device *netdev = NULL;
147     int ret = 0;
148     unsigned char ac_addr[MAC_ADDR_SIZE] = {0};
149 
150     if (netDevice == NULL) {
151         HDF_LOGE("%s:para is null!", __func__);
152         return -1;
153     }
154 
155     if (ifAdd == NULL) {
156         HDF_LOGE("%s:ifAdd is null!", __func__);
157         return -1;
158     }
159 
160     memcpy_s(ifName, IFNAMSIZ, ifAdd->ifName, IFNAMSIZ);
161 
162     hnetdev = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, FULL_OS);
163     if (hnetdev == NULL) {
164         HDF_LOGE("%s:netdev is null!", __func__);
165         return -1;
166     }
167     data = GetPlatformData(netDevice);
168     if (data == NULL) {
169         HDF_LOGE("%s:netdevice data null!", __func__);
170         return -1;
171     }
172     hnetdev->classDriverName = netDevice->classDriverName;
173     hnetdev->classDriverPriv = data;
174 
175     netdev = GetLinuxInfByNetDevice(hnetdev);
176     if (netdev == NULL) {
177         HDF_LOGE("%s net_device is null!", __func__);
178         return HDF_FAILURE;
179     }
180 
181     hdf_bdh6_netdev_init(hnetdev); // set net_dev_ops
182 
183     // create bdh6 private object
184     hnetdev->mlPriv = kzalloc(private_data_size, GFP_KERNEL);
185     if (hnetdev->mlPriv == NULL) {
186         HDF_LOGE("%s:kzalloc mlPriv failed", __func__);
187         return -1;
188     }
189 
190     // set mac address
191     ret = wal_get_dev_addr(ac_addr, MAC_ADDR_SIZE, ifAdd->type);
192     if (ret != 0) {
193         HDF_LOGE("generate macaddr for %s failed", hnetdev->name);
194     }
195     memcpy_s(hnetdev->macAddr, MAC_ADDR_SIZE, ac_addr, MAC_ADDR_SIZE);
196     g_hdf_ifidx = ifidx;
197     set_krn_netdev(hnetdev, netdev, ifidx);
198 
199     return ret;
200 }
201 
BDH_EnableEapol(struct NetDevice * netDev)202 static void BDH_EnableEapol(struct NetDevice *netDev)
203 {
204     WifiEnableEapol eapol;
205     const struct Eapol *eapolCB = EapolGetInstance();
206 
207     eapol.callback = HdfWifiEventEapolRecv;
208     eapol.context = NULL;
209 
210     eapolCB->eapolOp->enableEapol(netDev, (struct EapolEnable *)&eapol);
211 }
212 
hdf_bdh6_netdev_init(struct NetDevice * netDev)213 int32_t hdf_bdh6_netdev_init(struct NetDevice *netDev)
214 {
215     HDF_LOGI("%s: start %s...", __func__, netDev->name);
216     if (netDev == NULL) {
217         HDF_LOGE("%s: netDev null!", __func__);
218         return HDF_FAILURE;
219     }
220 
221     HDF_LOGI("%s: netDev->name:%s\n", __func__, netDev->name);
222     netDev->netDeviceIf = wal_get_net_dev_ops();
223     CreateEapolData(netDev);
224     if (bdh6_reset_driver_flag) {
225         BDH_EnableEapol(netDev);
226     }
227 
228     return HDF_SUCCESS;
229 }
230 
hdf_p2p_netdev_init(struct NetDevice * netDev)231 int32_t hdf_p2p_netdev_init(struct NetDevice *netDev)
232 {
233     HDF_LOGI("%s: start %s...", __func__, netDev->name);
234     if (netDev == NULL) {
235         HDF_LOGE("%s: netDev null!", __func__);
236         return HDF_FAILURE;
237     }
238 
239     HDF_LOGI("%s: netDev->name:%s\n", __func__, netDev->name);
240     netDev->netDeviceIf = wal_get_net_p2p_ops();
241     CreateEapolData(netDev);
242     if (bdh6_reset_driver_flag) {
243         BDH_EnableEapol(netDev);
244     }
245 
246     return HDF_SUCCESS;
247 }
248 
249 
hdf_bdh6_netdev_deinit(struct NetDevice * netDev)250 void hdf_bdh6_netdev_deinit(struct NetDevice *netDev)
251 {
252     HDF_LOGI("%s: start %s...", __func__, netDev->name);
253     (void)netDev;
254 }
255 
hdf_bdh6_netdev_open(struct NetDevice * netDev)256 int32_t hdf_bdh6_netdev_open(struct NetDevice *netDev)
257 {
258     int32_t retVal = 0;
259     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
260     HDF_LOGI("%s: start %s...", __func__, netDev->name);
261     if (netdev != get_krn_netdev(0)) {
262         // for virtual don't call open
263         return 0;
264     }
265 
266     if (netdev == NULL) {
267         HDF_LOGE("%s: netDev null!", __func__);
268         return HDF_FAILURE;
269     }
270 
271     rtnl_lock();
272     retVal = (int32_t)dhd_ops_pri.ndo_open(netdev);
273     if (retVal < 0) {
274         HDF_LOGE("%s: hdf net device open failed! ret = %d", __func__, retVal);
275     }
276 
277     netDev->ieee80211Ptr = netdev->ieee80211_ptr;
278     if (netDev->ieee80211Ptr == NULL) {
279         HDF_LOGE("%s: NULL == netDev->ieee80211Ptr", __func__);
280     }
281 
282     // update mac addr to NetDevice object
283     memcpy_s(netDev->macAddr, MAC_ADDR_SIZE, netdev->dev_addr, netdev->addr_len);
284     rtnl_unlock();
285     return retVal;
286 }
287 
hdf_p2p_netdev_open(struct NetDevice * netDev)288 int32_t hdf_p2p_netdev_open(struct NetDevice *netDev)
289 {
290     struct NetDevice *hnetDev = NULL;
291     HDF_LOGI("%s: start %s..., need open primary interface", __func__, netDev->name);
292     hnetDev = get_hdf_netdev(0);
293     hdf_bdh6_netdev_open(hnetDev);
294     return 0;
295 }
296 
297 
hdf_bdh6_netdev_stop(struct NetDevice * netDev)298 int32_t hdf_bdh6_netdev_stop(struct NetDevice *netDev)
299 {
300     int32_t retVal = 0;
301     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
302     HDF_LOGI("%s: start %s...", __func__, netDev->name);
303     if (netdev != get_krn_netdev(0)) {
304         return 0;
305     }
306     if (netdev == NULL) {
307         HDF_LOGE("%s: netDev null!", __func__);
308         return HDF_FAILURE;
309     }
310 
311     rtnl_lock();
312     retVal = (int32_t)dhd_ops_pri.ndo_stop(netdev);
313     rtnl_unlock();
314     if (retVal < 0) {
315         HDF_LOGE("%s: hdf net device stop failed! ret = %d", __func__, retVal);
316     }
317 
318     return retVal;
319 }
320 
hdf_p2p_netdev_stop(struct NetDevice * netDev)321 int32_t hdf_p2p_netdev_stop(struct NetDevice *netDev)
322 {
323     HDF_LOGI("%s: start %s...", __func__, netDev->name);
324     return 0;
325 }
326 
327 
hdf_bdh6_netdev_xmit(struct NetDevice * netDev,NetBuf * netBuff)328 int32_t hdf_bdh6_netdev_xmit(struct NetDevice *netDev, NetBuf *netBuff)
329 {
330     int32_t retVal = 0;
331     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
332 
333     if (netdev == NULL || netBuff == NULL) {
334         HDF_LOGE("%s: netdev or netBuff null!", __func__);
335         return HDF_FAILURE;
336     }
337 
338     retVal = (int32_t)dhd_ops_pri.ndo_start_xmit((struct sk_buff *)netBuff, netdev);
339     if (retVal < 0) {
340         HDF_LOGE("%s: hdf net device xmit failed! ret = %d", __func__, retVal);
341     }
342 
343     return retVal;
344 }
345 
hdf_p2p_netdev_xmit(struct NetDevice * netDev,NetBuf * netBuff)346 int32_t hdf_p2p_netdev_xmit(struct NetDevice *netDev, NetBuf *netBuff)
347 {
348     HDF_LOGI("%s: start %s...", __func__, netDev->name);
349     if (netBuff) {
350         dev_kfree_skb_any(netBuff);
351     }
352 
353     return 0;
354 }
355 
356 
hdf_bdh6_netdev_ioctl(struct NetDevice * netDev,IfReq * req,int32_t cmd)357 int32_t hdf_bdh6_netdev_ioctl(struct NetDevice *netDev, IfReq *req, int32_t cmd)
358 {
359     int32_t retVal = 0;
360     struct ifreq dhd_req = {0};
361     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
362 
363     HDF_LOGI("%s: start %s...", __func__, netDev->name);
364     if (netdev == NULL || req == NULL) {
365         HDF_LOGE("%s: netdev or req null!", __func__);
366         return HDF_FAILURE;
367     }
368 
369     dhd_req.ifr_ifru.ifru_data = req->ifrData;
370 
371     retVal = (int32_t)dhd_ops_pri.ndo_do_ioctl(netdev, &dhd_req, cmd);
372     if (retVal < 0) {
373         HDF_LOGE("%s: hdf net device ioctl failed! ret = %d", __func__, retVal);
374     }
375 
376     return retVal;
377 }
378 
hdf_p2p_netdev_ioctl(struct NetDevice * netDev,IfReq * req,int32_t cmd)379 int32_t hdf_p2p_netdev_ioctl(struct NetDevice *netDev, IfReq *req, int32_t cmd)
380 {
381     HDF_LOGI("%s: start %s...", __func__, netDev->name);
382     return 0;
383 }
384 
385 #define MC0 0
386 #define MC1 1
387 #define MC2 2
388 #define MC3 3
389 #define MC4 4
390 #define MC5 5
hdf_bdh6_netdev_setmacaddr(struct NetDevice * netDev,void * addr)391 int32_t hdf_bdh6_netdev_setmacaddr(struct NetDevice *netDev, void *addr)
392 {
393     int32_t retVal = 0;
394     struct sockaddr sa;
395     const uint8_t *mac = (uint8_t *)addr;
396     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
397 
398     HDF_LOGI("%s: start %s...", __func__, netDev->name);
399 
400     if (netdev == NULL || mac == NULL) {
401         HDF_LOGE("%s: netDev or addr null!", __func__);
402         return HDF_FAILURE;
403     }
404 
405     if (!is_valid_ether_addr(mac)) {
406         HDF_LOGE("%s: mac is invalid %02x:%02x:%02x:%02x:%02x:%02x", __func__,
407             mac[MC0], mac[MC1], mac[MC2], mac[MC3], mac[MC4], mac[MC5]);
408         return -1;
409     }
410     memcpy_s(sa.sa_data, ETH_ALEN, mac, ETH_ALEN);
411 
412     retVal = (int32_t)dhd_ops_pri.ndo_set_mac_address(netdev, (void *)&sa);
413     if (retVal < 0) {
414         HDF_LOGE("%s: hdf net device setmacaddr failed! ret = %d", __func__, retVal);
415     }
416 
417     return retVal;
418 }
419 
hdf_p2p_netdev_setmacaddr(struct NetDevice * netDev,void * addr)420 int32_t hdf_p2p_netdev_setmacaddr(struct NetDevice *netDev, void *addr)
421 {
422     int32_t retVal = 0;
423     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
424 
425     HDF_LOGI("%s: start %s...", __func__, netDev->name);
426 
427     if (netdev == NULL || addr == NULL) {
428         HDF_LOGE("%s: netDev or addr null!", __func__);
429         return HDF_FAILURE;
430     }
431 
432     memcpy_s(netdev->dev_addr, netdev->addr_len, (uint8_t *)addr, netdev->addr_len);
433     memcpy_s(netDev->macAddr, MAC_ADDR_SIZE, netdev->dev_addr, netdev->addr_len);
434     return retVal;
435 }
436 
437 
hdf_bdh6_netdev_getstats(struct NetDevice * netDev)438 struct NetDevStats *hdf_bdh6_netdev_getstats(struct NetDevice *netDev)
439 {
440     static struct NetDevStats devStat = {0};
441     struct net_device_stats *kdevStat = NULL;
442     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
443 
444     HDF_LOGI("%s: start %s...", __func__, netDev->name);
445 
446     if (netdev == NULL) {
447         HDF_LOGE("%s: netDev null!", __func__);
448         return NULL;
449     }
450 
451     kdevStat = dhd_ops_pri.ndo_get_stats(netdev);
452     if (kdevStat == NULL) {
453         HDF_LOGE("%s: ndo_get_stats return null!", __func__);
454         return NULL;
455     }
456 
457     devStat.rxPackets = kdevStat->rx_packets;
458     devStat.txPackets = kdevStat->tx_packets;
459     devStat.rxBytes = kdevStat->rx_bytes;
460     devStat.txBytes = kdevStat->tx_bytes;
461     devStat.rxErrors = kdevStat->rx_errors;
462     devStat.txErrors = kdevStat->tx_errors;
463     devStat.rxDropped = kdevStat->rx_dropped;
464     devStat.txDropped = kdevStat->tx_dropped;
465 
466     return &devStat;
467 }
468 
hdf_p2p_netdev_getstats(struct NetDevice * netDev)469 struct NetDevStats *hdf_p2p_netdev_getstats(struct NetDevice *netDev)
470 {
471     static struct NetDevStats devStat = {0};
472     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
473 
474     HDF_LOGI("%s: start %s...", __func__, netDev->name);
475 
476     if (netdev == NULL) {
477         HDF_LOGE("%s: netDev null!", __func__);
478         return NULL;
479     }
480 
481     return &devStat;
482 }
483 
484 
hdf_bdh6_netdev_setnetifstats(struct NetDevice * netDev,NetIfStatus status)485 void hdf_bdh6_netdev_setnetifstats(struct NetDevice *netDev, NetIfStatus status)
486 {
487     HDF_LOGI("%s: start...", __func__);
488     (void)netDev;
489     (void)status;
490 }
491 
hdf_bdh6_netdev_selectqueue(struct NetDevice * netDev,NetBuf * netBuff)492 uint16_t hdf_bdh6_netdev_selectqueue(struct NetDevice *netDev, NetBuf *netBuff)
493 {
494     HDF_LOGI("%s: start...", __func__);
495     (void)netDev;
496     (void)netBuff;
497     return HDF_SUCCESS;
498 }
499 
hdf_bdh6_netdev_netifnotify(struct NetDevice * netDev,NetDevNotify * notify)500 uint32_t hdf_bdh6_netdev_netifnotify(struct NetDevice *netDev, NetDevNotify *notify)
501 {
502     HDF_LOGI("%s: start...", __func__);
503     (void)netDev;
504     (void)notify;
505     return HDF_SUCCESS;
506 }
507 
hdf_bdh6_netdev_changemtu(struct NetDevice * netDev,int32_t mtu)508 int32_t hdf_bdh6_netdev_changemtu(struct NetDevice *netDev, int32_t mtu)
509 {
510     int32_t retVal = 0;
511     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
512     HDF_LOGI("%s: start %s...", __func__, netDev->name);
513     if (netdev == NULL) {
514         HDF_LOGE("%s: netdev null!", __func__);
515         return HDF_FAILURE;
516     }
517     HDF_LOGI("%s: change mtu to %d\n", __FUNCTION__, mtu);
518     retVal = (int32_t)dhd_netdev_changemtu_wrapper(netdev, mtu);
519     if (retVal < 0) {
520         HDF_LOGE("%s: hdf net device chg mtu failed! ret = %d", __func__, retVal);
521     }
522 
523     return retVal;
524 }
525 
hdf_p2p_netdev_changemtu(struct NetDevice * netDev,int32_t mtu)526 int32_t hdf_p2p_netdev_changemtu(struct NetDevice *netDev, int32_t mtu)
527 {
528     struct net_device *netdev = GetLinuxInfByNetDevice(netDev);
529     HDF_LOGI("%s: start %s...", __func__, netDev->name);
530     netdev->mtu = mtu;
531     return 0;
532 }
533 
hdf_bdh6_netdev_linkstatuschanged(struct NetDevice * netDev)534 void hdf_bdh6_netdev_linkstatuschanged(struct NetDevice *netDev)
535 {
536     HDF_LOGI("%s: start...", __func__);
537     (void)netDev;
538 }
539 
eapol_report_handler(struct work_struct * work_data)540 void eapol_report_handler(struct work_struct *work_data)
541 {
542     const struct Eapol *eapolInstance = NULL;
543     struct hdf_eapol_event_s *eapolEvent = NULL;
544     struct NetDevice *netDev = NULL;
545     int32_t idx = 0, ret = 0;
546     NetBuf *netBuff = NULL;
547     eapolEvent = container_of(work_data, struct hdf_eapol_event_s, eapol_report);
548     idx = eapolEvent->idx;
549     netDev = g_hdf_infmap[idx].hnetdev;
550     if (netDev == NULL) {
551         HDF_LOGE("%s: idx=%d, netDev is NULL", __func__, idx);
552         return;
553     }
554 
555     eapolInstance = EapolGetInstance();
556     while (1) {
557         netBuff = NetBufQueueDequeue(&eapolEvent->eapolQueue);
558         if (netBuff == NULL) {
559             return;
560         }
561 
562         ret = eapolInstance->eapolOp->writeEapolToQueue(netDev, netBuff);
563         if (ret != HDF_SUCCESS) {
564             HDF_LOGE("%s: writeEapolToQueue failed", __func__);
565             NetBufFree(netBuff);
566         }
567     }
568 }
569 
hdf_bdh6_send_eapol_data(const struct NetDevice * netDev,NetBuf * buff)570 static void hdf_bdh6_send_eapol_data(const struct NetDevice *netDev, NetBuf *buff)
571 {
572     int idx = 0;
573     struct hdf_eapol_event_s *eapolEvent = NULL;
574     idx = get_scan_ifidx(netDev->name);
575     eapolEvent = &g_hdf_infmap[idx].eapolEvent;
576     NetBufQueueEnqueue(&eapolEvent->eapolQueue, buff);
577     schedule_work(&eapolEvent->eapol_report);
578 }
579 
580 #define PEPROCESS1 12
581 #define PEPROCESS2 13
582 #define PEPROCESS3 8
hdf_bdh6_netdev_specialethertypeprocess(const struct NetDevice * netDev,NetBuf * buff)583 ProcessingResult hdf_bdh6_netdev_specialethertypeprocess(const struct NetDevice *netDev, NetBuf *buff)
584 {
585     struct EtherHeader *header = NULL;
586     uint16_t protocol;
587 
588     HDF_LOGI("%s: start %s...", __func__, netDev->name);
589 
590     if (netDev == NULL || buff == NULL) {
591         return PROCESSING_ERROR;
592     }
593 
594     header = (struct EtherHeader *)NetBufGetAddress(buff, E_DATA_BUF);
595 
596     protocol = (buff->data[PEPROCESS1] << PEPROCESS3) | buff->data[PEPROCESS2];
597     if (protocol != ETHER_TYPE_PAE) {
598         HDF_LOGE("%s: return PROCESSING_CONTINUE", __func__);
599         NetBufFree(buff);
600         return PROCESSING_CONTINUE;
601     }
602     if (netDev->specialProcPriv == NULL) {
603         HDF_LOGE("%s: return PROCESSING_ERROR", __func__);
604         NetBufFree(buff);
605         return PROCESSING_ERROR;
606     }
607 
608     hdf_bdh6_send_eapol_data(netDev, buff);
609     return PROCESSING_COMPLETE;
610 }
611 
612 
613 struct NetDeviceInterFace g_wal_bdh6_net_dev_ops = {
614     .init       = hdf_bdh6_netdev_init,
615     .deInit     = hdf_bdh6_netdev_deinit,
616     .open       = hdf_bdh6_netdev_open,
617     .stop       = hdf_bdh6_netdev_stop,
618     .xmit       = hdf_bdh6_netdev_xmit,
619     .ioctl      = hdf_bdh6_netdev_ioctl,
620     .setMacAddr = hdf_bdh6_netdev_setmacaddr,
621     .getStats   = hdf_bdh6_netdev_getstats,
622     .setNetIfStatus     = hdf_bdh6_netdev_setnetifstats,
623     .selectQueue        = hdf_bdh6_netdev_selectqueue,
624     .netifNotify        = hdf_bdh6_netdev_netifnotify,
625     .changeMtu          = hdf_bdh6_netdev_changemtu,
626     .linkStatusChanged  = hdf_bdh6_netdev_linkstatuschanged,
627     .specialEtherTypeProcess  = hdf_bdh6_netdev_specialethertypeprocess,
628 };
629 
wal_get_net_dev_ops(void)630 struct NetDeviceInterFace *wal_get_net_dev_ops(void)
631 {
632     return &g_wal_bdh6_net_dev_ops;
633 }
634 
635 
636 struct NetDeviceInterFace g_bdh6_p2p_net_dev_ops = {
637     .init       = hdf_p2p_netdev_init,
638     .deInit     = hdf_bdh6_netdev_deinit,
639     .open       = hdf_p2p_netdev_open,
640     .stop       = hdf_p2p_netdev_stop,
641     .xmit       = hdf_p2p_netdev_xmit,
642     .ioctl      = hdf_p2p_netdev_ioctl,
643     .setMacAddr = hdf_p2p_netdev_setmacaddr,
644     .getStats   = hdf_p2p_netdev_getstats,
645     .setNetIfStatus     = hdf_bdh6_netdev_setnetifstats,
646     .selectQueue        = hdf_bdh6_netdev_selectqueue,
647     .netifNotify        = hdf_bdh6_netdev_netifnotify,
648     .changeMtu          = hdf_p2p_netdev_changemtu,
649     .linkStatusChanged  = hdf_bdh6_netdev_linkstatuschanged,
650     .specialEtherTypeProcess  = hdf_bdh6_netdev_specialethertypeprocess,
651 };
652 
wal_get_net_p2p_ops(void)653 struct NetDeviceInterFace *wal_get_net_p2p_ops(void)
654 {
655     return &g_bdh6_p2p_net_dev_ops;
656 }
657 
get_real_netdev(NetDevice * netDev)658 struct NetDevice *get_real_netdev(NetDevice *netDev)
659 {
660     if (strcmp(netDev->name, "p2p0") == 0) {
661         return get_hdf_netdev(HDF_INF_WLAN0);
662     } else {
663         return netDev;
664     }
665 }
666 
667