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