• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 /**
10  * @addtogroup WLAN
11  * @{
12  *
13  * @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation.
14  *
15  * Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface
16  * (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips,
17  * network devices, and power, and applying for, releasing, and moving network data buffers.
18  *
19  * @since 1.0
20  * @version 1.0
21  */
22 
23 /**
24  * @file net_device.h
25  *
26  * @brief Defines WLAN network device interfaces.
27  *
28  * This module provides network device operations for driver development.
29  * The operations are as follows:
30  * <li> Initializes, adds, obtains, and deletes a network device. </li>
31  * <li> Reports network data, informs the network layer of the data link layer status, sets IP addresses,
32  * and starts or stops Dynamic Host Configuration Protocol (DHCP). </li>
33  *
34  * @since 1.0
35  * @version 1.0
36  */
37 
38 #ifndef HDF_NET_DEVICE_MODULE_H
39 #define HDF_NET_DEVICE_MODULE_H
40 #if defined(CONFIG_DRIVERS_HDF_IMX8MM_ETHERNET)
41 #include <linux/phy.h>
42 #endif
43 #include "hdf_base.h"
44 #include "hdf_netbuf.h"
45 #include "hdf_log.h"
46 #include "net_device_types_adapter.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /**
53  * @brief Indicates a 6-byte MAC address.
54  *
55  * @since 1.0
56  * @version 1.0
57  */
58 #define MAC_ADDR_SIZE 6
59 /**
60  * @brief Indicates that the network port is working.
61  *
62  * @since 1.0
63  * @version 1.0
64  */
65 #define NET_DEVICE_IFF_RUNNING IFF_RUNNING
66 /**
67  * @brief Indicates Reverse Address Resolution Protocol (RARP).
68  *
69  * @since 1.0
70  * @version 1.0
71  */
72 #define ETHER_TYPE_RARP 0x8035
73 /**
74  * @brief Indicates Port Access Entity (PAE).
75  *
76  * @since 1.0
77  * @version 1.0
78  */
79 #define ETHER_TYPE_PAE 0x888e
80 /**
81  * @brief Indicates Internet Protocol (IP).
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 #define ETHER_TYPE_IP 0x0800
87 /**
88  * @brief Indicates AppleTalk Address Resolution Protocol (AARP).
89  *
90  * @since 1.0
91  * @version 1.0
92  */
93 #define ETHER_TYPE_AARP 0x80f3
94 /**
95  * @brief Indicates Internetwork Packet Exchange (IPX).
96  *
97  * @since 1.0
98  * @version 1.0
99  */
100 #define ETHER_TYPE_IPX 0x8137
101 /**
102  * @brief Indicates Address Resolution Protocol (ARP).
103  *
104  * @since 1.0
105  * @version 1.0
106  */
107 #define ETHER_TYPE_ARP 0x0806
108 /**
109  * @brief Indicates Internet Protocol version 6 (IPv6).
110  *
111  * @since 1.0
112  * @version 1.0
113  */
114 #define ETHER_TYPE_IPV6 0x86dd
115 /**
116  * @brief Indicates Tunneled Direct Link Setup (TDLS).
117  *
118  * @since 1.0
119  * @version 1.0
120  */
121 #define ETHER_TYPE_TDLS 0x890d
122 /**
123  * @brief Indicates Virtual Local Area Network (VLAN).
124  *
125  * @since 1.0
126  * @version 1.0
127  */
128 #define ETHER_TYPE_VLAN 0x8100
129 /**
130  * @brief Indicates WLAN Authentication and Privacy Infrastructure (WAPI).
131  *
132  * @since 1.0
133  * @version 1.0
134  */
135 #define ETHER_TYPE_WAI 0x88b4
136 /**
137  * @brief Indicates Link Layer Topology Discovery (LLTD).
138  *
139  * @since 1.0
140  * @version 1.0
141  */
142 #define ETHER_LLTD_TYPE 0x88D9
143 /**
144  * @brief Indicates 802.1x network port authentication.
145  *
146  * @since 1.0
147  * @version 1.0
148  */
149 #define ETHER_ONE_X_TYPE 0x888E
150 /**
151  * @brief Indicates a tunnel protocol.
152  *
153  * @since 1.0
154  * @version 1.0
155  */
156 #define ETHER_TUNNEL_TYPE 0x88bd
157 /**
158  * @brief Indicates the point-to-point discovery type.
159  *
160  * @since 1.0
161  * @version 1.0
162  */
163 #define ETHER_TYPE_PPP_DISC 0x8863
164 /**
165  * @brief Indicates the point-to-point session discovery type.
166  *
167  * @since 1.0
168  * @version 1.0
169  */
170 #define ETHER_TYPE_PPP_SES 0x8864
171 /**
172  * @brief Indicates IPv6 over Low Power Wireless Personal Area Networks (6LoWPANs).
173  *
174  * @since 1.0
175  * @version 1.0
176  */
177 #define ETHER_TYPE_6LO 0xa0ed
178 
179 /**
180  * @brief Indicates the Transmission Control Protocol (TCP).
181  *
182  * @since 1.0
183  * @version 1.0
184  */
185 #define TCP_PROTOCOL       6
186 /**
187  * @brief Indicates the User Datagram Protocol (UDP).
188  *
189  * @since 1.0
190  * @version 1.0
191  */
192 #define UDP_PROTOCOL       17
193 /**
194  * @brief Indicates the shift in the priority for an IP address.
195  *
196  * @since 1.0
197  * @version 1.0
198  */
199 #define IP_PRI_SHIFT        5
200 
201 /**
202  * @brief Indicates the source port number of DHCP.
203  *
204  * @since 1.0
205  * @version 1.0
206  */
207 #define DHCP_UDP_SRC_PORT   68
208 /**
209  * @brief Indicates the destination port number of DHCP.
210  *
211  * @since 1.0
212  * @version 1.0
213  */
214 #define DHCP_UDP_DES_PORT   67
215 
216 /**
217  * @brief Indicates the default MTU value of the WLAN.
218  *
219  * @since 1.0
220  * @version 1.0
221  */
222 #define DEFAULT_MTU 1500
223 
224 /**
225  * @brief Indicates the maximum MTU value of the WLAN.
226  *
227  * @since 1.0
228  * @version 1.0
229  */
230 #define WLAN_MAX_MTU 1500
231 
232 /**
233  * @brief Indicates the minimum MTU value of the WLAN.
234  *
235  * @since 1.0
236  * @version 1.0
237  */
238 #define WLAN_MIN_MTU 576
239 
240 /**
241  * @brief Enumerates network interface categories, including lightweight OS and full OS.
242  *
243  * @since 1.0
244  * @version 1.0
245  */
246 typedef enum {
247     LITE_OS,   /**< Lightweight OS */
248     FULL_OS   /**< Full OS */
249 } NetIfCategory;
250 
251 /**
252  * @brief Enumerates network interface states, including online and offline.
253  *
254  * @since 1.0
255  * @version 1.0
256  */
257 typedef enum {
258     NETIF_DOWN,  /**< Network interface offline */
259     NETIF_UP     /**< Network interface online */
260 } NetIfStatus;
261 
262 /**
263  * @brief Enumerates network link layer states, including online and offline.
264  *
265  * @since 1.0
266  * @version 1.0
267  */
268 typedef enum {
269     NETIF_LINK_DOWN,  /**< Data link offline */
270     NETIF_LINK_UP     /**< Data link online */
271 } NetIfLinkStatus;
272 
273 /**
274  * @brief Enumerates data link types, including Ethernet and WLAN.
275  *
276  * @since 1.0
277  * @version 1.0
278  */
279 typedef enum {
280     ETHERNET_LINK = 1,  /**< Ethernet */
281     WIFI_LINK = 801     /**< WLAN */
282 } NetLinkType;
283 
284 /**
285  * @brief Enumerates data processing results, including continuing processing, processing completed, and error.
286  *
287  * @since 1.0
288  * @version 1.0
289  */
290 typedef enum {
291     PROCESSING_CONTINUE,  /**< Continuing processing */
292     PROCESSING_COMPLETE,  /**< Processing completed */
293     PROCESSING_ERROR      /**< Error */
294 } ProcessingResult;
295 
296 /**
297  * @brief Enumerates 802.11 network port types, including AP, STA, and P2P.
298  *
299  * @since 1.0
300  * @version 1.0
301  */
302 typedef enum {
303     PROTOCOL_80211_IFTYPE_UNSPECIFIED,                         /**< Unspecified */
304     PROTOCOL_80211_IFTYPE_ADHOC,                               /**< Ad hoc network */
305     PROTOCOL_80211_IFTYPE_STATION,                             /**< Workstation */
306     PROTOCOL_80211_IFTYPE_AP,                                  /**< Access point */
307     PROTOCOL_80211_IFTYPE_AP_VLAN,                             /**< Virtual access point */
308     PROTOCOL_80211_IFTYPE_WDS,                                 /**< Wireless distributed system */
309     PROTOCOL_80211_IFTYPE_MONITOR,                             /**< Listening */
310     PROTOCOL_80211_IFTYPE_MESH_POINT,                          /**< Mesh network */
311     PROTOCOL_80211_IFTYPE_P2P_CLIENT,                          /**< P2P client */
312     PROTOCOL_80211_IFTYPE_P2P_GO,                              /**< P2P group owner */
313     PROTOCOL_80211_IFTYPE_P2P_DEVICE,                          /**< P2P device */
314     PROTOCOL_80211_IFTYPE_NUM,                                 /**< Number of network ports */
315     PROTOCOL_80211_IFTYPE_MAX = PROTOCOL_80211_IFTYPE_NUM - 1  /**< Maximum number of 802.11 network port types */
316 } Protocol80211IfType;
317 
318 /**
319  * @brief Enumerates network device errors, including common errors and errors in adding network devices to LwIP.
320  *
321  * @since 1.0
322  * @version 1.0
323  */
324 typedef enum {
325     COMMON_ERROR = 1,  /**< Common errors */
326     ADD_LWIP_ERROR     /**< Errors in adding network devices to LwIP */
327 } NetdeviceError;
328 
329 /**
330  * @brief Defines the Ethernet header information of a data frame, including the destination address, source address,
331  * and Ethernet type.
332  *
333  * @since 1.0
334  * @version 1.0
335  */
336 struct EtherHeader {
337     uint8_t etherDhost[MAC_ADDR_SIZE];  /**< Destination address {@link MAC_ADDR_SIZE} */
338     uint8_t etherShost[MAC_ADDR_SIZE];  /**< Source address {@link MAC_ADDR_SIZE} */
339     uint16_t etherType;                 /**< Ethernet type, such as 0x8035 (RARP), 0x888e (EAPOL), PAE/802.1x,
340                                          * 0x0800 (IP), 0x86dd (IPV6), and 0x0806 (ARP)
341                                          */
342 };
343 
344 /**
345  * @brief Defines the IP header information of a data frame, including the version number, service type,
346  * and total length.
347  *
348  * @since 1.0
349  * @version 1.0
350  */
351 struct IpHeader {
352     uint8_t    versionAndHl;   /**< Version and header length */
353     uint8_t    tos;            /**< Service type
354                                 * bit7~bit5 | bit4  |  bit3 |  bit2 |   bit1  | bit0
355                                 * ----------|-------|-------|-------|---------|-----
356                                 * Priority | Delay | Throughput | Reliability | Transmission Cost | Reservation
357                                 */
358     uint16_t   totLen;         /**< Total length of an IP data packet */
359     uint16_t   id;             /**< Each data packet sent by the host */
360     uint16_t   fragInfo;       /**< Fragmentation information */
361     uint8_t    ttl;            /**< Generation time */
362     uint8_t    protocol;       /**< Protocol, such as 1 (ICMP), 2 (IGMP), 6 (TCP), 17 (UDP), and 89 (OSPF) */
363     uint16_t   check;          /**< Header check */
364     uint32_t   sAddr;          /**< Source address */
365     uint32_t   dAddr;          /**< Destination address */
366 };
367 
368 /**
369  * @brief Defines the UDP header information of a data frame, including the source port number and destination
370  * port number.
371  *
372  * @since 1.0
373  * @version 1.0
374  */
375 struct UdpHeader {
376     uint16_t source;  /**< Source port number */
377     uint16_t dest;    /**< Destination port number */
378     uint16_t len;     /**< Length of a data packet */
379     uint16_t check;   /**< Header check */
380 };
381 
382 /**
383  * @brief Defines the TCP header information of a data frame, including the source port number and destination
384  * port number.
385  *
386  * @since 1.0
387  * @version 1.0
388  */
389 struct TcpHeader {
390     uint16_t  sPort;   /**< Source port number */
391     uint16_t  dPort;   /**< Destination port number */
392     uint32_t  seqNum;  /**< Sequence number */
393     uint32_t  ackNum;  /**< Acknowledgment number */
394     uint8_t   offset;  /**< Header length */
395     uint8_t   flags;   /**< Flags */
396     uint16_t  window;  /**< Window size */
397     uint16_t  check;   /**< Checksum */
398     uint16_t  urgent;  /**< Urgent pointer */
399 };
400 
401 /**
402  * @brief Defines an IPv4 address.
403  *
404  * @since 1.0
405  * @version 1.0
406  */
407 typedef struct {
408     uint32_t addr;  /**< IPv4 address */
409 } IpV4Addr;
410 
411 /**
412  * @brief Defines a network device notification, including an IP address and the notification type.
413  *
414  * @since 1.0
415  * @version 1.0
416  */
417 typedef struct {
418     uint32_t ipAddr;      /**< IP address */
419     uint32_t notifyType;  /**< Notification type (reserved) */
420 } NetDevNotify;
421 
422 /**
423  * @brief Defines the network port type, for example, the WLAN network port.
424  *
425  * @since 1.0
426  * @version 1.0
427  */
428 typedef union {
429     Protocol80211IfType wlanType;  /**< WLAN network port type: AP or STA */
430 } IfType;
431 
432 /**
433  * @brief Describes the status of a network device.
434  *
435  * @since 1.0
436  * @version 1.0
437  */
438 struct NetDevStats {
439     uint32_t rxPackets; /**< Total number of received packets */
440     uint32_t txPackets; /**< Total number of transmitted packets */
441     uint32_t rxBytes;   /**< Total number of received bits */
442     uint32_t txBytes;   /**< Total number of transmitted bits */
443     uint32_t rxErrors;  /**< Number of received error packets */
444     uint32_t txErrors;  /**< Transmitted error packets */
445     uint32_t rxDropped; /**< Packets that are dropped after being received */
446     uint32_t txDropped; /**< Packets dropped before transmission */
447 };
448 
449 /**
450  * @brief Defines ioctrl data.
451  *
452  * @since 1.0
453  * @version 1.0
454  */
455 typedef struct {
456     uint32_t fake;     /**< magic field */
457     uint8_t *ifrData;  /**< Data pointer */
458 } IfReq;
459 
460 /**
461  * @brief Defines a network device, including the network interface category and name, and network port type.
462  *
463  * @since 1.0
464  * @version 1.0
465  */
466 typedef struct NetDevice {
467     NetIfCategory netifCateg;                 /**< Network interface category {@link NetIfCategory} */
468     char name[IFNAMSIZ];                      /**< Network device name {@link IFNAMSIZ} */
469     NetLinkType linkLayerType;                /**< Data link layer type */
470     IfType funType;                           /**< Network port type */
471     uint8_t macAddr[MAC_ADDR_SIZE];           /**< MAC address {@link MAC_ADDR_SIZE} */
472     uint32_t flags;                           /**< Network port status */
473     uint32_t mtu;                             /**< Maximum transmission unit */
474     int32_t watchdogTime;                     /**< Watchdog duration */
475     uint32_t lastRxTime;                      /**< Last time when data is received */
476     uint16_t hardHeaderLen;                   /**< Header length */
477     uint16_t neededHeadRoom;                  /**< Length reserved for the header in netbuff{@link NetBuf} */
478     uint16_t neededTailRoom;                  /**< Length reserved for the tail in netbuff{@link NetBuf} */
479     uint8_t addrLen;                          /**< MAC address length */
480     const char* classDriverName;              /**< driver name of class driver */
481     void *classDriverPriv;                    /**< Private structure for the platform */
482     void *mlPriv;                             /**< Private structure for the driver */
483     void *ieee80211Ptr;                       /**< Pointer to a wireless device */
484     void *specialProcPriv;                    /**< Private structure for data processing */
485     struct NetDeviceInterFace *netDeviceIf;   /**< Network device interface */
486     struct NetDevice *owner;                  /**< Network device */
487     struct NetDevStats stats;                 /**< Network statistics */
488 } NetDevice;
489 
490 /**
491  * @brief Defines interfaces that need to be implemented externally by network devices, including initializing,
492  * opening, and closing a network device.
493  *
494  * @since 1.0
495  * @version 1.0
496  */
497 struct NetDeviceInterFace {
498     int32_t (*init)(struct NetDevice *netDev);  /**< Initializes a network device to be added. */
499     void (*deInit)(struct NetDevice *netDev);   /**< Deinitializes a network device to be delete. */
500     int32_t (*open)(struct NetDevice *netDev);  /**< Opens the data link layer. */
501     int32_t (*stop)(struct NetDevice *netDev);  /**< Closes the data link layer. */
502     NetDevTxResult (*xmit)(struct NetDevice *netDev, NetBuf *netBuff);        /**< Sends data. */
503     int32_t (*ioctl)(struct NetDevice *netDev, IfReq *req, int32_t cmd);      /**< Used for the control command word. */
504     int32_t (*setMacAddr)(struct NetDevice *netDev, void *addr);              /**< Sets the MAC address. */
505     struct NetDevStats *(*getStats)(struct NetDevice *netDev);                /**< Obtains the statistics. */
506     void (*setNetIfStatus)(struct NetDevice *netDev, NetIfStatus status);     /**< Sets the network port status. */
507     uint16_t (*selectQueue)(struct NetDevice *netDev, NetBuf *netBuff);       /**< Selects a priority queue. */
508     uint32_t (*netifNotify)(struct NetDevice *netDev, NetDevNotify *notify);  /**< Notifies the network port status. */
509     int32_t (*changeMtu)(struct NetDevice *netDev, int32_t newMtu);           /**< Changes the maximum number of
510                                                                                * transmission units.
511                                                                                */
512     void (*linkStatusChanged)(struct NetDevice *netDev);    /**< Detects the change of
513                                                              * the Ethernet port connection status.
514                                                              */
515     ProcessingResult (*specialEtherTypeProcess)(const struct NetDevice *netDev, NetBuf *buff);
516                                                                               /**< Performs private processing without
517                                                                                * involving network-layer data.
518                                                                                */
519 };
520 
521 /**
522  * @brief Initializes a network device to obtain its instance.
523  *
524  * @param ifName Indicates the pointer to the network device name.
525  * @param len Indicates the length of the network device name.
526  * @param type Indicates the data link type.
527  * @param ifCategory Indicates the network port category.
528  *
529  * @return Returns the structure {@link NetDevice} for the initialized network device if the operation is successful;
530  * returns <b>NULL</b> if the operation fails.
531  *
532  * @since 1.0
533  * @version 1.0
534  */
535 struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetLinkType type, NetIfCategory ifCategory);
536 
537 /**
538  * @brief Deletes a network device.
539  *
540  * @param netDevice Indicates the pointer to the network device structure obtained during initialization.
541  *
542  * @return Returns <b>0</b> if the operation is successful; returns a negative value representing {@link HDF_STATUS}
543  * if the operation fails.
544  *
545  * @since 1.0
546  * @version 1.0
547  */
548 int32_t NetDeviceDeInit(struct NetDevice *netDevice);
549 
550 /**
551  * @brief Adds a network device to a protocol stack.
552  *
553  * @param netDevice Indicates the pointer to the network device structure obtained during initialization.
554  *
555  * @return Returns <b>0</b> if the operation is successful; returns a negative value representing {@link HDF_STATUS}
556  * if the operation fails.
557  *
558  * @since 1.0
559  * @version 1.0
560  */
561 int32_t NetDeviceAdd(struct NetDevice *netDevice);
562 
563 /**
564  * @brief Deletes a network device from a protocol stack.
565  *
566  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained during
567  * initialization.
568  *
569  * @return Returns <b>0</b> if the operation is successful; returns a negative value representing {@link HDF_STATUS}
570  * if the operation fails.
571  *
572  * @since 1.0
573  * @version 1.0
574  */
575 int32_t NetDeviceDelete(struct NetDevice *netDevice);
576 
577 /**
578  * @brief Obtains the initialized network device instance by a specified device name.
579  *
580  * @param name Indicates the pointer to the network device name.
581  *
582  * @return Returns the network device structure {@link NetDevice} matching the network device name if the operation is
583  * successful; returns <b>NULL</b> if the operation fails.
584  *
585  * @since 1.0
586  * @version 1.0
587  */
588 struct NetDevice *NetDeviceGetInstByName(const char *name);
589 
590 /**
591  * @brief Checks whether there are working devices among the added network devices.
592  *
593  * @return Returns <b>true</b> if the added network devices are working; returns <b>false</b> if none of the added
594  * network devices is working.
595  *
596  * @since 1.0
597  * @version 1.0 */
598 bool NetDeviceIsAnyInstRunning(void);
599 
600 /**
601  * @brief Checks whether a specified network device is working.
602  *
603  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained during
604  * initialization.
605  *
606  * @return Returns <b>true</b> if the specified network device is working; returns <b>false</b> otherwise.
607  *
608  * @since 1.0
609  * @version 1.0
610  */
611 bool NetDeviceIsInstRunning(const struct NetDevice *netDevice);
612 
613 /**
614  * @brief Obtains the number of added network devices.
615  *
616  * @return Returns the number of added network devices.
617  *
618  * @since 1.0
619  * @version 1.0
620  */
621 uint32_t NetDevGetRegisterCount(void);
622 
623 /**
624  * @brief Obtains the maximum number of network devices that can be registered with this system at the same time.
625  *
626  * @return Returns the maximum number of network devices.
627  *
628  * @since 1.0
629  * @version 1.0
630  */
631 uint32_t NetDeviceGetCap(void);
632 
633 /**
634  * @brief Obtains a network device instance based on the index number.
635  *
636  * @param index Indicates the index number.
637  *
638  * @return Returns the network device structure {@link NetDevice} if the operation is successful; returns <b>NULL</b>
639  * if the operation fails.
640  *
641  * @since 1.0
642  * @version 1.0
643  */
644 struct NetDevice *NetDeviceGetInstByIndex(uint32_t index);
645 
646 /**
647  * @brief Sets an IP address, mask, and gateway.
648  *
649  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained during
650  * initialization.
651  * @param ipAddr Indicates the IP address to set.
652  * @param netMask Indicates the mask to set.
653  * @param gw Indicates the gateway to set.
654  *
655  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
656  *
657  * @since 1.0
658  * @version 1.0
659  */
660 int32_t NetIfSetAddr(const struct NetDevice *netDevice, const IpV4Addr *ipAddr, const IpV4Addr *netMask,
661     const IpV4Addr *gw);
662 
663 /**
664  * @brief Notifies the network layer of the network port state.
665  *
666  * @param netDevice Indicates the pointer to the network device obtained during initialization.
667  * @param status Indicates the network port state, as enumerated in {@link NetIfSatus}.
668  * @param status Indicates the network port state, as enumerated in {@link NetIfSatus}.
669  *
670  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
671  *
672  * @since 1.0
673  * @version 1.0
674  */
675 int32_t NetIfSetStatus(const struct NetDevice *netDevice, NetIfStatus status);
676 
677 /**
678  * @brief Sets a specified MAC address for a given {@link NetDevice}.
679  *
680  * @param netDevice Indicates the pointer to the {@link NetDevice}.
681  * @param macAddr Indicates the pointer to the MAC address to set.
682  * @param length Indicates the length of the MAC address to set.
683  *
684  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
685  *
686  * @since 1.0
687  * @version 1.0
688  */
689 int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAddr, unsigned char length);
690 
691 /**
692  * @brief Notifies the network layer of the data link layer status.
693  *
694  * @param netDevice Indicates the pointer to the network device obtained during initialization.
695  * @param status status Indicates the data link layer status, as enumerated in {@link NetIfLinkSatus}.
696  *
697  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
698  *
699  * @since 1.0
700  * @version 1.0
701  */
702 int32_t NetIfSetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus status);
703 
704 /**
705  * @brief Get the netdevice data link layer status.
706  *
707  * @param netDevice Indicates the pointer to the network device obtained during initialization.
708  * @param status save link layer status, as enumerated in {@link NetIfLinkSatus}.
709  *
710  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
711  *
712  * @since 1.0
713  * @version 1.0
714  */
715 int32_t NetIfGetLinkStatus(const struct NetDevice *netDevice, NetIfLinkStatus *status);
716 
717 /**
718  * @brief Transfers data packets from the network side to a protocol stack in an interrupt processing thread.
719  *
720  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained
721  * during initialization.
722  * @param buff Indicates the network-side data, in Ether format.
723  *
724  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value {@link HDF_STATUS} if the
725  * operation fails.
726  *
727  * @since 1.0
728  * @version 1.0
729  */
730 int32_t NetIfRx(const struct NetDevice *netDevice, NetBuf *buff);
731 
732 /**
733  * @brief Transfers the input data packets from the network side to a protocol stack.
734  *
735  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained
736  * during initialization.
737  * @param buff Indicates the network-side data, in Ether format.
738  *
739  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value {@link HDF_STATUS} if the
740  * operation fails.
741  *
742  * @since 1.0
743  * @version 1.0
744  */
745 int32_t NetIfRxNi(const struct NetDevice *netDevice, NetBuf *buff);
746 
747 /**
748  * @brief Starts the DHCP server.
749  *
750  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained
751  * during initialization.
752  * @param ip Indicates the IP address to start.
753  * @param ipNum Indicates the number of IP addresses.
754  *
755  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
756  *
757  * @since 1.0
758  * @version 1.0
759  */
760 int32_t NetIfDhcpsStart(const struct NetDevice *netDevice, char *ip, uint16_t ipNum);
761 
762 /**
763  * @brief Stops the DHCP server.
764  *
765  * @param netDevice Indicates the pointer to the network device structure {@link netDevice} obtained
766  * during initialization.
767  *
768  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
769  *
770  * @since 1.0
771  * @version 1.0
772  */
773 int32_t NetIfDhcpsStop(const struct NetDevice *netDevice);
774 
775 /**
776  * @brief Starts the DHCP client of a specified network device.
777  *
778  * @param netDevice Indicates the pointer to the network device obtained during initialization.
779  *
780  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
781  *
782  * @since 1.0
783  * @version 1.0
784  */
785 int32_t NetIfDhcpStart(const struct NetDevice *netDevice);
786 
787 /**
788  * @brief Stops the DHCP client of a specified network device.
789  *
790  * @param netDevice Indicates the pointer to the network device obtained during initialization.
791  *
792  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
793  *
794  * @since 1.0
795  * @version 1.0
796  */
797 int32_t NetIfDhcpStop(const struct NetDevice *netDevice);
798 
799 /**
800  * @brief Obtains the DHCP negotiation status of a specified network device.
801  *
802  * @param netDevice Indicates the pointer to the network device obtained during initialization.
803  *
804  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
805  *
806  * @since 1.0
807  * @version 1.0
808  */
809 int32_t NetIfDhcpIsBound(const struct NetDevice *netDevice);
810 
811 #if defined(CONFIG_DRIVERS_HDF_IMX8MM_ETHERNET)
812 /**
813  * @brief Add napi of a specified network device.
814  *
815  * @param netDevice Indicates the pointer to the network device obtained during initialization.
816  * @param napi new napi struct.
817  * @param *poll poll pointer function
818  * @param weight int weight
819  *
820  * @return
821  *
822  * @since 1.0
823  * @version 1.0
824  */
825 void NetIfNapiAdd(struct NetDevice *netDevice, struct napi_struct *napi,
826     int (*poll)(struct napi_struct *, int), int weight);
827 
828 /**
829  * @brief Get Tx Queue of a specified network device.
830  *
831  * @param netDevice Indicates the pointer to the network device obtained during initialization.
832  * @param index the index of queue
833  *
834  * @return Returns the network queue structure {@link netdev_queue} if the operation is successful; returns <b>NULL</b>
835  * if the operation fails.
836  *
837  * @since 1.0
838  * @version 1.0
839  */
840 struct netdev_queue *NetIfGetTxQueue(struct NetDevice *netDevice, unsigned int index);
841 
842 /**
843  * @brief Netdevice Interface type trans
844  *
845  * @param netDevice Indicates the pointer to the network device obtained during initialization.
846  * @param skb skb buffer
847  *
848  * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
849  *
850  * @since 1.0
851  * @version 1.0
852  */
853 __be16 NetIfTypeTrans(struct NetDevice *netDevice, struct sk_buff *skb);
854 
855 /**
856  * @brief Netdevice allocate buffer
857  *
858  * @param netDevice Indicates the pointer to the network device obtained during initialization.
859  * @param length the size of buffer
860  *
861  * @return Returns the skb buffer structure {@link sk_buff} if the operation is successful; returns <b>NULL</b>
862  * if the operation fails.
863  *
864  * @since 1.0
865  * @version 1.0
866  */
867 struct sk_buff *NetIfEnteAllocBuf(struct NetDevice *netDevice, uint32_t length);
868 
869 /**
870  * @brief Netdevice start queue
871  *
872  * @param netDevice Indicates the pointer to the network device obtained during initialization.
873  *
874  * @return
875  *
876  * @since 1.0
877  * @version 1.0
878  */
879 void NetIfStartQueue(struct NetDevice *netDevice);
880 
881 /**
882  * @brief Netdevice disable transmit of netdevice
883  *
884  * @param netDevice Indicates the pointer to the network device obtained during initialization.
885  *
886  * @return
887  *
888  * @since 1.0
889  * @version 1.0
890  */
891 void NetIfDisableTx(struct NetDevice *netDevice);
892 
893 /**
894  * @brief Set parent device to netdevice
895  *
896  * @param netDevice Indicates the pointer to the network device obtained during initialization.
897  * @param dev parent device
898  *
899  * @return
900  *
901  * @since 1.0
902  * @version 1.0
903  */
904 void NetIfSetDev(struct NetDevice *netDevice, struct device *dev);
905 
906 /**
907  * @brief Netdevice wakeup queue
908  *
909  * @param netDevice Indicates the pointer to the network device obtained during initialization.
910  *
911  * @return
912  *
913  * @since 1.0
914  * @version 1.0
915  */
916 void NetIfWakeQueue(struct NetDevice *netDevice);
917 
918 /**
919  * @brief Netdevice phy connect
920  *
921  * @param netDevice Indicates the pointer to the network device obtained during initialization.
922  * @param phy_np phy node pointer of netDevice
923  * @param hndlr call handler after phy connect
924  * @param flags phy connnect flags
925  * @param iface phy interface
926  *
927  * @return  Returns the phy device structure {@link phy_device} if the operation is successful; returns <b>NULL</b>
928  * if the operation fails.
929  *
930  * @since 1.0
931  * @version 1.0
932  */
933 struct phy_device *NetIfOfPhyConnect(struct NetDevice *netDevice,
934                                      struct device_node *phy_np,
935                                      void (*hndlr)(struct net_device *),
936                                      u32 flags,
937                                      phy_interface_t iface);
938 #endif
939 
940 #define GET_NET_DEV_FLAGS(dev) ((dev)->flags)
941 #define GET_NET_DEV_HEAD_ROOM(dev) ((dev)->neededHeadRoom)
942 #define GET_NET_DEV_TAIL_ROOM(dev) ((dev)->neededTailRoom)
943 #define GET_NET_DEV_MTU(dev) ((dev)->mtu)
944 #define GET_NET_DEV_CFG80211_WIRELESS(dev) ((struct wireless_dev*)((dev)->ieee80211Ptr))
945 #define GET_NET_DEV_PRIV(dev) ((dev)->mlPriv)
946 #define GET_NET_DEV_MAC_ADDR(dev) ((dev)->macAddr)
947 #define GET_NET_DEV_IF(dev) ((dev)->netDeviceIf)
948 #define GET_NET_DEV_LAST_RX_TIME(dev) ((dev)->lastRxTime)
949 #define GET_NET_DEV_OWNER(dev) ((dev)->owner)
950 #define GET_NET_DEV_WATCHDOG_TIME(dev) ((dev)->watchdogTime)
951 #define GET_NET_DEV_SPECIAL_PROC_PRIV(dev) ((dev)->specialProcPriv)
952 #ifdef __cplusplus
953 }
954 #endif
955 
956 #endif /* HDF_NET_DEVICE_MODULE_H */
957 /** @} */
958