diff --git a/include/ethernet/eth_chip_driver.h b/include/ethernet/eth_chip_driver.h
new file mode 100755
index 0000000000000000000000000000000000000000..e1ddbd0815f2ce8ba5a429fc184d7589c069b150
--- /dev/null
+++ b/include/ethernet/eth_chip_driver.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef ETH_CHIP_DRIVER_H
+#define ETH_CHIP_DRIVER_H
+
+#include "eth_device.h"
+#include "net_device.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_CHIPDRIVER_COUNT 16
+
+struct EthMacOps {
+ void (*MacInit)(void);
+ int32_t (*PortReset)(struct EthDevice *ethDevice);
+ int32_t (*PortInit)(struct EthDevice *ethDevice);
+};
+
+struct HdfEthMacChipDriver {
+ struct EthMacOps *ethMacOps; /**< Ethernet Mac some basic methods */
+};
+
+struct HdfEthNetDeviceData {
+ struct HdfEthMacChipDriver *macChipDriver; /**< Mac ChipDriver */
+};
+
+struct HdfEthNetDeviceData *GetEthNetDeviceData(const struct NetDevice *netDev);
+
+struct HdfEthChipDriverFactory {
+ const char *driverName;
+ int32_t (*InitEthDriver)(struct EthDevice *ethDevice);
+ int32_t (*DeinitEthDriver)(struct EthDevice *ethDevice);
+ struct HdfEthMacChipDriver *(*BuildMac)(void);
+ void (*ReleaseMac)(struct HdfEthMacChipDriver *chipDriver);
+ void (*GetMacAddr)(unsigned char *addr, int len);
+};
+
+struct HdfEthChipDriverManager {
+ struct HdfEthChipDriverFactory **chipFactoryInsts;
+ int32_t (*RegChipDriver)(struct HdfEthChipDriverFactory *factoryInst);
+ struct HdfEthChipDriverFactory *(*GetEthChipDriverByName)(const char *name);
+};
+
+struct HdfEthChipDriverManager *HdfEthGetChipDriverMgr(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ETH_CHIP_DRIVER_H */
+/** @} */
\ No newline at end of file
diff --git a/include/net/hdf_netbuf.h b/include/net/hdf_netbuf.h
index f30466461862648b1a4156dbcad05efb5f8bbca9..d873c614a622787a0cdff096b0b43ecee701ed5e 100644
--- a/include/net/hdf_netbuf.h
+++ b/include/net/hdf_netbuf.h
@@ -259,6 +259,20 @@ void *NetBufPush(NetBuf *nb, uint32_t id, uint32_t len);
*/
void *NetBufPop(NetBuf *nb, uint32_t id, uint32_t len);
+/**
+ * @brief Adjusts the mem pointer to hide or reveal headers in the netbuf.
+ *
+ * @param nb Indicates the pointer to the network data buffer.
+ * @param len Number of bytes to increment header size.
+ *
+ * @return Returns the address of the specified buffer segment if the operation is successful;
+ * returns NULL if the buffer segment ID is invalid.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+void *NetBufHeader(NetBuf *nb, int32_t len);
+
/**
* @brief Obtains the address of a specified buffer segment in a network data buffer.
*
diff --git a/include/wifi/net_device.h b/include/net/net_device.h
old mode 100644
new mode 100755
similarity index 94%
rename from include/wifi/net_device.h
rename to include/net/net_device.h
index 9b1b5963422b43c009390b37597128e8a3a5867a..9e469e4578c6d9dc94af4980a702e12e7ea9161b
--- a/include/wifi/net_device.h
+++ b/include/net/net_device.h
@@ -506,6 +506,9 @@ struct NetDeviceInterFace {
int32_t (*changeMtu)(struct NetDevice *netDev, int32_t newMtu); /**< Changes the maximum number of
* transmission units.
*/
+ void (*linkStatusChanged)(struct NetDevice *netDev); /**< Detects the change of
+ * the Ethernet port connection status.
+ */
ProcessingResult (*specialEtherTypeProcess)(const struct NetDevice *netDev, NetBuf *buff);
/**< Performs private processing without
* involving network-layer data.
@@ -517,6 +520,7 @@ struct NetDeviceInterFace {
*
* @param ifName Indicates the pointer to the network device name.
* @param len Indicates the length of the network device name.
+ * @param type Indicates the data link type.
* @param ifCategory Indicates the network port category.
*
* @return Returns the structure {@link NetDevice} for the initialized network device if the operation is successful;
@@ -525,7 +529,7 @@ struct NetDeviceInterFace {
* @since 1.0
* @version 1.0
*/
-struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory ifCategory);
+struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetLinkType type, NetIfCategory ifCategory);
/**
* @brief Deletes a network device.
@@ -544,6 +548,19 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice);
* @brief Adds a network device to a protocol stack.
*
* @param netDevice Indicates the pointer to the network device structure obtained during initialization.
+ *
+ * @return Returns 0 if the operation is successful; returns a negative value representing {@link HDF_STATUS}
+ * if the operation fails.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+int32_t NetDeviceAdd(struct NetDevice *netDevice);
+
+/**
+ * @brief Process a special network device based on the type.
+ *
+ * @param netDevice Indicates the pointer to the network device structure obtained during initialization.
* @param ifType Indicates the network port type, as enumerated in {@link Protocol80211IfType}.
*
* @return Returns 0 if the operation is successful; returns a negative value representing {@link HDF_STATUS}
@@ -552,7 +569,7 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice);
* @since 1.0
* @version 1.0
*/
-int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType);
+int32_t NetDevSpecialProc(struct NetDevice *netDevice, Protocol80211IfType ifType);
/**
* @brief Deletes a network device from a protocol stack.
@@ -788,6 +805,30 @@ int32_t NetIfDhcpStop(const struct NetDevice *netDevice);
*/
int32_t NetIfDhcpIsBound(const struct NetDevice *netDevice);
+/**
+ * @brief Check whether the status of the Ethernet port is Up.
+ *
+ * @param netDevice Indicates the pointer to the network device obtained during initialization.
+ *
+ * @return Returns 1 if the status is up; returns a non-one value the status is down.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+int8_t NetIfIsLinkUp(const struct NetDevice *netDevice);
+
+/**
+ * @brief Set a network interface as the default network interface.
+ *
+ * @param netDevice Indicates the pointer to the network device obtained during initialization.
+ *
+ * @return Returns 0 if the operation is successful; returns a non-zero value otherwise.
+ *
+ * @since 1.0
+ * @version 1.0
+ */
+int32_t NetIfSetDefault(const struct NetDevice *netDevice);
+
#define GET_NET_DEV_FLAGS(dev) ((dev)->flags)
#define GET_NET_DEV_HEAD_ROOM(dev) ((dev)->neededHeadRoom)
#define GET_NET_DEV_TAIL_ROOM(dev) ((dev)->neededTailRoom)
diff --git a/model/network/common/netdevice/net_device.c b/model/network/common/netdevice/net_device.c
index 2a336b3048b5d5e132fe797450fe423718664d8d..3c74dd4879c4d12d7b0b607c00b975775944b10f 100644
--- a/model/network/common/netdevice/net_device.c
+++ b/model/network/common/netdevice/net_device.c
@@ -121,7 +121,7 @@ static struct NetDeviceImpl *GetImplByNetDevice(const struct NetDevice *netDevic
return ndImpl;
}
-struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory ifCategory)
+struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetLinkType type, NetIfCategory ifCategory)
{
NetDevice *netDevice = NULL;
struct NetDeviceImpl *ndImpl = NULL;
@@ -167,6 +167,7 @@ struct NetDevice *NetDeviceInit(const char *ifName, uint32_t len, NetIfCategory
DeInitNetDeviceImpl(ndImpl);
return NULL;
}
+ netDevice->LinkLayerType = type;
HDF_LOGI("Init Net Device success!");
return netDevice;
}
@@ -190,7 +191,7 @@ int32_t NetDeviceDeInit(struct NetDevice *netDevice)
return HDF_SUCCESS;
}
-int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType)
+int32_t NetDeviceAdd(struct NetDevice *netDevice)
{
struct NetDeviceImplOp *op = NULL;
struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice);
@@ -204,7 +205,25 @@ int32_t NetDeviceAdd(struct NetDevice *netDevice, Protocol80211IfType ifType)
HDF_LOGE("%s fail: Impl Add not exist.", __func__);
return HDF_ERR_INVALID_PARAM;
}
- return op->add(ndImpl, ifType);
+ return op->add(ndImpl);
+}
+
+int32_t NetDevSpecialProc(struct NetDevice *netDevice, Protocol80211IfType ifType)
+{
+ struct NetDeviceImplOp *op = NULL;
+ struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice);
+
+ if (ndImpl == NULL) {
+ HDF_LOGE("%s fail: netDevice not exist!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ op = ndImpl->interFace;
+ if (op == NULL || op->specialProc == NULL) {
+ HDF_LOGE("%s fail: Impl specialProc not exist.", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ op->specialProc(ndImpl, ifType);
+ return HDF_SUCCESS;
}
int32_t NetDeviceDelete(struct NetDevice *netDevice)
@@ -340,6 +359,7 @@ static int32_t NetIfRxImpl(const struct NetDevice *netDevice, NetBuf *buff, Rece
int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAddr, unsigned char length)
{
struct NetDeviceImpl *ndImpl = NULL;
+ HDF_STATUS ret;
if (macAddr == NULL || length != MAC_ADDR_SIZE) {
HDF_LOGE("%s fail: input param error!", __func__);
return HDF_ERR_INVALID_PARAM;
@@ -348,6 +368,15 @@ int32_t NetIfSetMacAddr(struct NetDevice *netDevice, const unsigned char *macAdd
HDF_LOGE("%s fail : memcpy_s fail!", __func__);
return HDF_FAILURE;
}
+
+ if (netDevice->netDeviceIf != NULL && netDevice->netDeviceIf->setMacAddr != NULL) {
+ ret = netDevice->netDeviceIf->setMacAddr(netDevice, (void*)macAddr);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s fail : setMacAddr fail!", __func__);
+ return ret;
+ }
+ }
+
ndImpl = GetImplByNetDevice(netDevice);
if (ndImpl != NULL && ndImpl->interFace != NULL && ndImpl->interFace->changeMacAddr != NULL) {
return ndImpl->interFace->changeMacAddr(ndImpl);
@@ -435,6 +464,27 @@ int32_t NetIfDhcpIsBound(const struct NetDevice *netDevice)
return HDF_ERR_INVALID_PARAM;
}
+int8_t NetIfIsLinkUp(const struct NetDevice *netDevice)
+{
+ struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice);
+ if (ndImpl != NULL && ndImpl->interFace != NULL && ndImpl->interFace->isLinkUp != NULL) {
+ return ndImpl->interFace->isLinkUp(ndImpl);
+ }
+ HDF_LOGE("%s: netDevice not init or already free.", __func__);
+ return HDF_ERR_INVALID_PARAM;
+}
+
+int32_t NetIfSetDefault(const struct NetDevice *netDevice)
+{
+ struct NetDeviceImpl *ndImpl = GetImplByNetDevice(netDevice);
+ if (ndImpl != NULL && ndImpl->interFace != NULL && ndImpl->interFace->setDefault != NULL) {
+ ndImpl->interFace->setDefault(ndImpl);
+ return HDF_SUCCESS;
+ }
+ HDF_LOGE("%s: netDevice not init or already free.", __func__);
+ return HDF_ERR_INVALID_PARAM;
+}
+
/*
* Alloc a net buffer for the net device and reserve headroom depended on net device setting
*
diff --git a/model/network/common/netdevice/net_device_impl.h b/model/network/common/netdevice/net_device_impl.h
index 22a627035b28117fbed43753e2611b9fa5b7ac1e..afe9f12b9ac1e0b08d7c3910cbf3e09664324605 100644
--- a/model/network/common/netdevice/net_device_impl.h
+++ b/model/network/common/netdevice/net_device_impl.h
@@ -27,7 +27,7 @@ typedef enum {
struct NetDeviceImplOp {
int32_t (*init)(struct NetDeviceImpl *netDevice);
int32_t (*deInit)(struct NetDeviceImpl *netDevice);
- int32_t (*add)(struct NetDeviceImpl *netDevice, Protocol80211IfType ifType);
+ int32_t (*add)(struct NetDeviceImpl *netDevice);
int32_t (*delete)(struct NetDeviceImpl *netDevice);
int32_t (*setStatus)(struct NetDeviceImpl *netDevice, NetIfStatus status);
int32_t (*setLinkStatus)(struct NetDeviceImpl *netDevice, NetIfLinkStatus status);
@@ -40,6 +40,9 @@ struct NetDeviceImplOp {
int32_t (*dhcpStop)(struct NetDeviceImpl *netDevice);
int32_t (*dhcpIsBound)(struct NetDeviceImpl *netDevice);
int32_t (*changeMacAddr)(struct NetDeviceImpl *netDevice);
+ int8_t (*isLinkUp)(struct NetDeviceImpl *netDevice);
+ void (*setDefault)(struct NetDeviceImpl *netDevice);
+ void (*specialProc)(struct NetDeviceImpl *netDevice, Protocol80211IfType ifType);
};
#endif /* HDF_NET_DEVICE_IMPL_MODULE_H */
\ No newline at end of file
diff --git a/model/network/ethernet/include/eth_device.h b/model/network/ethernet/include/eth_device.h
new file mode 100755
index 0000000000000000000000000000000000000000..777320159214471920fd1403018124da2535c6a1
--- /dev/null
+++ b/model/network/ethernet/include/eth_device.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef ETH_DEVICE_H
+#define ETH_DEVICE_H
+
+#include "net_device.h"
+#include "hdf_device_desc.h"
+
+#define MAX_NAME_LENGTH 16
+#define ETH_DEVICE_MAX 6
+
+#define DELAY_TIME_LONG 3000
+#define DELAY_TIME_MEDIUM 50
+#define DELAY_TIME_SHORT 5
+#define SLEEP_TIME_SHORT 20
+#define SLEEP_TIME_MEDIUM 30
+#define SLEEP_TIME_COMMON 60
+#define SLEEP_TIME_LONG 250
+
+#define MAC_ADDR_OFFSET_L8 8
+#define MAC_ADDR_OFFSET_L16 16
+#define MAC_ADDR_OFFSET_L24 24
+
+struct EthDevice {
+ struct NetDevice *netdev;
+ struct ConfigEthDevList *config;
+ const char *name;
+ void *priv;
+};
+
+struct HdfConfigEthMac {
+ uint32_t regBase;
+ uint32_t irqVector;
+ uint8_t mdioFrqDiv;
+ uint8_t txBusy;
+ uint32_t iobase;
+ uint32_t regOffSize;
+};
+
+struct HdfConfigEthPhy {
+ uint8_t phyMode;
+};
+
+struct ConfigEthDevList {
+ uint8_t deviceInstId;
+ uint8_t isSetDefault;
+ const char *driverName;
+ uint8_t hwXmitq;
+ uint8_t qSize;
+ struct HdfConfigEthMac ethMac;
+ struct HdfConfigEthPhy ethPhy;
+};
+
+struct EthConfig {
+ struct ConfigEthDevList deviceInst[ETH_DEVICE_MAX];
+ uint16_t deviceListSize;
+};
+
+struct EthDevice *CreateEthDevice(const struct ConfigEthDevList *configEthDevList);
+int32_t ReleaseEthDevice(struct EthDevice *ethDevice);
+int32_t GetEthIfName(const struct ConfigEthDevList *configEthDevList, char *ifName, uint32_t ifNameSize);
+struct EthConfig *GetEthConfig(const struct DeviceResourceNode *node);
+
+#endif /* ETH_DEVICE_H */
diff --git a/model/network/ethernet/src/eth_chip_driver.c b/model/network/ethernet/src/eth_chip_driver.c
new file mode 100755
index 0000000000000000000000000000000000000000..805f766f4eb2b3fe4848e08ce3fac52b20d49edf
--- /dev/null
+++ b/model/network/ethernet/src/eth_chip_driver.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "eth_chip_driver.h"
+#include "hdf_log.h"
+
+#define HDF_LOG_TAG HDF_ETH_CORE
+
+static struct HdfEthChipDriverFactory *g_ethChipDriverFactory[MAX_CHIPDRIVER_COUNT] = {NULL};
+
+struct HdfEthChipDriverFactory *HdfEthGetChipDriverByName(const char *driverName)
+{
+ int32_t i;
+ if (driverName == NULL) {
+ HDF_LOGE("%s fail: drivreName is NULL", __func__);
+ return NULL;
+ }
+
+ for (i = 0; i < MAX_CHIPDRIVER_COUNT; i++) {
+ if (g_ethChipDriverFactory[i] != NULL && g_ethChipDriverFactory[i]->driverName != NULL) {
+ struct HdfEthChipDriverFactory *factory = g_ethChipDriverFactory[i];
+ if (strcmp(factory->driverName, driverName) == 0) {
+ return factory;
+ }
+ }
+ }
+ return NULL;
+}
+
+int32_t HdfEthRegChipDriver(struct HdfEthChipDriverFactory *obj)
+{
+ int32_t index;
+ if (obj == NULL || obj->driverName == NULL) {
+ HDF_LOGE("%s: HdfEthChipDriverFactory obj is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (HdfEthGetChipDriverByName(obj->driverName) != NULL) {
+ HDF_LOGW("%s: chipDriver factory is already registed. name = %s", __func__, obj->driverName);
+ return HDF_FAILURE;
+ }
+ for (index = 0; index < MAX_CHIPDRIVER_COUNT; index++) {
+ if (g_ethChipDriverFactory[index] == NULL) {
+ g_ethChipDriverFactory[index] = obj;
+ HDF_LOGI("%s:Chip driver %s registed.", __func__, obj->driverName);
+ return HDF_SUCCESS;
+ }
+ }
+ HDF_LOGE("%s: Factory table is NULL", __func__);
+ return HDF_FAILURE;
+}
+
+static struct HdfEthChipDriverManager g_chipDriverManager = {
+ .chipFactoryInsts = g_ethChipDriverFactory,
+ .RegChipDriver = HdfEthRegChipDriver,
+ .GetEthChipDriverByName = HdfEthGetChipDriverByName,
+};
+
+struct HdfEthChipDriverManager *HdfEthGetChipDriverMgr(void)
+{
+ return &g_chipDriverManager;
+}
\ No newline at end of file
diff --git a/model/network/ethernet/src/eth_device.c b/model/network/ethernet/src/eth_device.c
new file mode 100755
index 0000000000000000000000000000000000000000..6ea177c9ffeaf21b337213015113b49c82b283b2
--- /dev/null
+++ b/model/network/ethernet/src/eth_device.c
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "eth_device.h"
+#include "eth_chip_driver.h"
+#include
+#include "device_resource_if.h"
+#include "hdf_log.h"
+#include "los_vm_zone.h"
+#include "osal_mem.h"
+
+#define HDF_LOG_TAG eth_device
+
+int32_t GetEthIfName(const struct ConfigEthDevList *configEthDevList, char *ifName, uint32_t ifNameSize)
+{
+ if (configEthDevList == NULL || ifName == NULL || ifNameSize == 0) {
+ HDF_LOGE("%s:para is null!", __func__);
+ return HDF_FAILURE;
+ }
+ if (snprintf_s(ifName, ifNameSize, ifNameSize - 1, "eth%d", configEthDevList->deviceInstId) < 0) {
+ HDF_LOGE("%s:format ifName failed!deviceInstId = %d.", __func__, configEthDevList->deviceInstId);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+struct EthDevice *CreateEthDevice(const struct ConfigEthDevList *configEthDevList)
+{
+ int32_t ret;
+ struct HdfEthNetDeviceData *data = NULL;
+ struct NetDevice *netDevice = NULL;
+ struct EthDevice *ethDevice = NULL;
+ char ethIfName[IFNAMSIZ] = {0};
+
+ if (configEthDevList == NULL) {
+ HDF_LOGE("%s input is NULL!", __func__);
+ return NULL;
+ }
+ data = (struct HdfEthNetDeviceData *)OsalMemCalloc(sizeof(struct HdfEthNetDeviceData));
+ if (data == NULL) {
+ HDF_LOGE("%s failed to OsalMemCalloc HdfEthNetDeviceData", __func__);
+ return NULL;
+ }
+ ret = GetEthIfName(configEthDevList, ethIfName, IFNAMSIZ);
+ if (ret != HDF_SUCCESS) {
+ OsalMemFree(data);
+ return NULL;
+ }
+ netDevice = NetDeviceInit(ethIfName, strlen(ethIfName), ETHERNET_LINK, LITE_OS);
+ if (netDevice == NULL) {
+ HDF_LOGE("%s failed to init netDevice", __func__);
+ OsalMemFree(data);
+ return NULL;
+ }
+ ethDevice = (struct EthDevice *)OsalMemCalloc(sizeof(struct EthDevice));
+ if (ethDevice == NULL) {
+ HDF_LOGE("%s failed to OsalMemCalloc ethDevice", __func__);
+ NetDeviceDeInit(netDevice);
+ OsalMemFree(data);
+ return NULL;
+ }
+ netDevice->mlPriv = ethDevice;
+ ethDevice->netdev = netDevice;
+ ethDevice->netdev->classDriverPriv = data;
+ ethDevice->name = configEthDevList->driverName;
+ return ethDevice;
+}
+
+static int32_t ParseEthMacConfig(const struct DeviceResourceNode *node, struct HdfConfigEthMac *ethMacConfig)
+{
+ struct DeviceResourceIface *drsOps = NULL;
+
+ if (node == NULL || ethMacConfig == NULL) {
+ HDF_LOGE("%s: invalid node or ethMacConfig!", __func__);
+ return HDF_FAILURE;
+ }
+
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetUint8 == NULL || drsOps->GetUint32 == NULL) {
+ HDF_LOGE("%s: at least one of the paras is NULL!", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint32(node, "regBase", ðMacConfig->regBase, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read regBase fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint32(node, "irqVector", ðMacConfig->irqVector, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read irqVector fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "mdioFrqDiv", ðMacConfig->mdioFrqDiv, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read mdioFrqDiv fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "txBusy", ðMacConfig->txBusy, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read txBusy fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint32(node, "iobase", ðMacConfig->iobase, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read iobase fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint32(node, "regOffSize", ðMacConfig->regOffSize, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read regOffSize fail", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseEthPhyConfig(const struct DeviceResourceNode *node, struct HdfConfigEthPhy *ethPhyConfig)
+{
+ struct DeviceResourceIface *drsOps = NULL;
+
+ if (node == NULL || ethPhyConfig == NULL) {
+ HDF_LOGE("%s: invalid node or ethPhyConfig!", __func__);
+ return HDF_FAILURE;
+ }
+
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetUint8 == NULL) {
+ HDF_LOGE("%s: at least one of the paras is NULL!", __func__);
+ return HDF_FAILURE;
+ }
+
+ if (drsOps->GetUint8(node, "phyMode", ðPhyConfig->phyMode, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read phyMode fail", __func__);
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseEthDevInstConfig(const struct DeviceResourceNode *node, struct ConfigEthDevList *devLstConfig)
+{
+ struct DeviceResourceIface *drsOps = NULL;
+ const struct DeviceResourceNode *ethMacNode = NULL;
+ const struct DeviceResourceNode *ethPhyNode = NULL;
+ if (node == NULL || devLstConfig == NULL) {
+ return HDF_FAILURE;
+ }
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetUint8 == NULL || drsOps->GetChildNode == NULL) {
+ HDF_LOGE("%s: at least one of the paras is NULL!", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "deviceInstId", &devLstConfig->deviceInstId, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: deviceInstId fail!", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "isSetDefault", &devLstConfig->isSetDefault, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: isSetDefault fail!", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetString(node, "driverName", &devLstConfig->driverName, NULL) != HDF_SUCCESS) {
+ HDF_LOGE("%s: driverName fail!", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "hwXmitq", &devLstConfig->hwXmitq, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read hwXmitq fail", __func__);
+ return HDF_FAILURE;
+ }
+ if (drsOps->GetUint8(node, "qSize", &devLstConfig->qSize, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s: read qSize fail", __func__);
+ return HDF_FAILURE;
+ }
+
+ ethMacNode = drsOps->GetChildNode(node, "MAC");
+ if (ethMacNode == NULL) {
+ HDF_LOGE("%s: GetChildNode fail!", __func__);
+ return HDF_FAILURE;
+ }
+ if (ParseEthMacConfig(ethMacNode, &devLstConfig->ethMac) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ ethPhyNode = drsOps->GetChildNode(node, "PHY");
+ if (ethPhyNode == NULL) {
+ HDF_LOGE("%s: GetChildNode fail!", __func__);
+ return HDF_FAILURE;
+ }
+ if (ParseEthPhyConfig(ethPhyNode, &devLstConfig->ethPhy) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseEthDevListNode(const struct DeviceResourceNode *node, struct EthConfig *ethConfig)
+{
+ struct DeviceResourceNode *childNode = NULL;
+ uint32_t index = 0;
+
+ if (node == NULL || ethConfig == NULL) {
+ HDF_LOGE("%s: invalid node or ethConfig!", __func__);
+ return HDF_FAILURE;
+ }
+ DEV_RES_NODE_FOR_EACH_CHILD_NODE(node, childNode)
+ {
+ if (ParseEthDevInstConfig(childNode, ðConfig->deviceInst[index]) != HDF_SUCCESS) {
+ return HDF_FAILURE;
+ }
+ index++;
+ ethConfig->deviceListSize++;
+ }
+ HDF_LOGD("%s: deviceListSize=%d", __func__, ethConfig->deviceListSize);
+ return HDF_SUCCESS;
+}
+
+static int32_t ParseConfigFromProperty(const struct DeviceResourceNode *node, struct EthConfig *config)
+{
+ struct DeviceResourceIface *drsOps = NULL;
+ const struct DeviceResourceNode *devListNode = NULL;
+
+ drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ if (drsOps == NULL || drsOps->GetChildNode == NULL) {
+ HDF_LOGE("%s: invalid drs ops fail!", __func__);
+ return HDF_FAILURE;
+ }
+ devListNode = drsOps->GetChildNode(node, "ethList");
+ if (devListNode == NULL) {
+ HDF_LOGE("%s: get child node fail!", __func__);
+ return HDF_FAILURE;
+ }
+ return ParseEthDevListNode(devListNode, config);
+}
+
+struct EthConfig *GetEthConfig(const struct DeviceResourceNode *node)
+{
+ if (node == NULL) {
+ HDF_LOGE("%s input is NULL", __func__);
+ return NULL;
+ }
+
+ struct EthConfig *config = NULL;
+
+ config = (struct EthConfig *)OsalMemCalloc(sizeof(*config));
+ if (config == NULL) {
+ HDF_LOGE("%s failed to OsalMemCalloc config", __func__);
+ return NULL;
+ }
+
+ if (ParseConfigFromProperty(node, config) != HDF_SUCCESS) {
+ HDF_LOGE("%s failed to parse config from property", __func__);
+ return NULL;
+ }
+ return config;
+}
+
+struct HdfEthNetDeviceData *GetEthNetDeviceData(const struct NetDevice *netDev)
+{
+ if (netDev == NULL) {
+ return NULL;
+ }
+ return (struct HdfEthNetDeviceData *)(netDev->classDriverPriv);
+}
+
+int32_t ReleaseEthDevice(struct EthDevice *ethDevice)
+{
+ int32_t ret;
+ struct HdfEthNetDeviceData *data = NULL;
+
+ if (ethDevice == NULL) {
+ HDF_LOGE("%s:NULL ptr!", __func__);
+ return HDF_FAILURE;
+ }
+
+ data = GetEthNetDeviceData(ethDevice->netdev);
+ if (data == NULL) {
+ HDF_LOGE("%s: GetEthNetDeviceData failed!", __func__);
+ return HDF_FAILURE;
+ }
+ struct HdfEthMacChipDriver *macChipDriver = data->macChipDriver;
+ if (macChipDriver != NULL) {
+ OsalMemFree(macChipDriver);
+ macChipDriver = NULL;
+ }
+ ret = NetDeviceDeInit(ethDevice->netdev);
+ if (ret != HDF_SUCCESS) {
+ return ret;
+ }
+
+ OsalMemFree(ethDevice);
+ OsalMemFree(data);
+ return HDF_SUCCESS;
+}
\ No newline at end of file
diff --git a/model/network/ethernet/src/hdf_eth_core.c b/model/network/ethernet/src/hdf_eth_core.c
new file mode 100755
index 0000000000000000000000000000000000000000..bb55cece96a770d6e52d42809446c96b45e209c5
--- /dev/null
+++ b/model/network/ethernet/src/hdf_eth_core.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "eth_chip_driver.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+
+#define HDF_LOG_TAG eth_core
+struct EthConfig *g_ethConfig = NULL;
+
+static struct HdfEthChipDriverFactory *HdfEthGetDriverFactory(const char *driverName)
+{
+ struct HdfEthChipDriverManager *initMgr = NULL;
+ if (driverName == NULL) {
+ HDF_LOGE("%s: driverName is ", __func__);
+ return NULL;
+ }
+ initMgr = HdfEthGetChipDriverMgr();
+ if (initMgr == NULL) {
+ HDF_LOGE("%s: initMgr is NULL", __func__);
+ return NULL;
+ }
+ return initMgr->GetEthChipDriverByName(driverName);
+}
+
+static int32_t DeinitEth(struct EthDevice *ethDevice)
+{
+ HDF_LOGD("%s enter", __func__);
+ struct HdfEthChipDriverFactory *ethChipDriverFact = NULL;
+
+ if (ethDevice == NULL) {
+ HDF_LOGE("%s the input ethDevice is NULL!", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+ ethChipDriverFact = HdfEthGetDriverFactory(ethDevice->name);
+ if (ethChipDriverFact == NULL) {
+ HDF_LOGE("%s: get ethChipDriverFact failed! driverName = %s", __func__, ethDevice->name);
+ return HDF_FAILURE;
+ }
+
+ if (ethChipDriverFact->DeinitEthDriver != NULL) {
+ return ethChipDriverFact->DeinitEthDriver(ethDevice);
+ }
+ return HDF_SUCCESS;
+}
+
+#if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
+static int32_t SetEthNetworkAddr(struct NetDevice *netDev)
+{
+ int32_t ret;
+ IpV4Addr ip;
+ IpV4Addr netmask;
+ IpV4Addr gw;
+
+ ip.addr = 0x6401a8c0UL; /* 192, 168, 1. 100 */
+ netmask.addr = 0x00ffffffUL; /* 255, 255, 255, 0 */
+ gw.addr = 0x0101a8c0UL; /* 192, 168, 12, 1 */
+
+ ret = NetIfSetAddr(netDev, &ip, &netmask, &gw);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s fail: NetIfSetAddr error!", __func__);
+ return ret;
+ }
+ return HDF_SUCCESS;
+}
+#endif
+
+static int32_t InitMacInterface(struct EthDevice *ethDevice, struct HdfEthMacChipDriver *macChipDriver)
+{
+ int32_t ret;
+
+ if (macChipDriver->ethMacOps == NULL) {
+ HDF_LOGE("%s:ethMacOps is NULL.", __func__);
+ return HDF_FAILURE;
+ }
+ if (macChipDriver->ethMacOps->MacInit == NULL) {
+ HDF_LOGE("%s:MacInit is not implement.", __func__);
+ return HDF_FAILURE;
+ }
+ macChipDriver->ethMacOps->MacInit();
+
+ if (macChipDriver->ethMacOps->PortReset == NULL) {
+ HDF_LOGE("%s:PortReset is not implement.", __func__);
+ return HDF_FAILURE;
+ }
+ ret = macChipDriver->ethMacOps->PortReset(ethDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s:PortReset failed! ret = %d.", __func__, ret);
+ return HDF_FAILURE;
+ }
+
+ if (macChipDriver->ethMacOps->PortInit == NULL) {
+ HDF_LOGE("%s:PortInit is not implement.", __func__);
+ return HDF_FAILURE;
+ }
+ ret = macChipDriver->ethMacOps->PortInit(ethDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s:PortInit failed! ret = %d.", __func__, ret);
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t InitEth(struct EthDevice *ethDevice, const uint8_t isSetDefault,
+ struct HdfEthChipDriverFactory *ethChipDriverFact)
+{
+ int32_t ret;
+ struct HdfEthNetDeviceData *data = NULL;
+ struct HdfEthMacChipDriver *macChipDriver = NULL;
+ unsigned char enaddr[MAC_ADDR_SIZE] = {0};
+
+ macChipDriver = ethChipDriverFact->BuildMac();
+ if (macChipDriver == NULL) {
+ HDF_LOGE("%s:mac chip driver build fail!", __func__);
+ return HDF_FAILURE;
+ }
+ data = GetEthNetDeviceData(ethDevice->netdev);
+ if (data == NULL) {
+ HDF_LOGE("%s: data is NULL!", __func__);
+ ethChipDriverFact->ReleaseMac(macChipDriver);
+ return HDF_FAILURE;
+ }
+ data->macChipDriver = macChipDriver;
+
+ ret = ethChipDriverFact->InitEthDriver(ethDevice);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: failed to init eth phy", __func__);
+ DeinitEth(ethDevice);
+ ReleaseEthDevice(ethDevice);
+ return ret;
+ }
+
+ ret = InitMacInterface(ethDevice, macChipDriver);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: InitMacInterface error!", __func__);
+ DeinitEth(ethDevice);
+ ReleaseEthDevice(ethDevice);
+ return HDF_FAILURE;
+ }
+ LOS_Msleep(DELAY_TIME_LONG);
+
+ ethChipDriverFact->GetMacAddr(enaddr, MAC_ADDR_SIZE);
+ NetIfSetMacAddr(ethDevice->netdev, enaddr, MAC_ADDR_SIZE);
+ if (isSetDefault) {
+ NetIfSetDefault(ethDevice->netdev);
+ }
+#if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
+ ret = SetEthNetworkAddr(ethDevice->netdev);
+ if (ret != HDF_SUCCESS) {
+ DeinitEth(ethDevice);
+ ReleaseEthDevice(ethDevice);
+ return ret;
+ }
+#endif
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfEthDriverInit(struct HdfDeviceObject *deviceObject)
+{
+ int32_t ret;
+ uint8_t i;
+
+ if (deviceObject == NULL) {
+ HDF_LOGE("%s deviceObject is NULL", __func__);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ g_ethConfig = GetEthConfig(deviceObject->property);
+ if (g_ethConfig == NULL) {
+ HDF_LOGE("%s failed to get g_ethConfig!", __func__);
+ return HDF_FAILURE;
+ }
+
+ for (i = 0; i < g_ethConfig->deviceListSize; i++) {
+ struct EthDevice *ethDevice = CreateEthDevice(&g_ethConfig->deviceInst[i]);
+ if (ethDevice == NULL) {
+ return HDF_FAILURE;
+ }
+ ethDevice->config = &g_ethConfig->deviceInst[i];
+
+ struct HdfEthChipDriverFactory *ethChipDriverFact = NULL;
+ ethChipDriverFact = HdfEthGetDriverFactory(ethDevice->name);
+ if (ethChipDriverFact == NULL) {
+ HDF_LOGE("%s: get ethChipDriverFact failed! driverName = %s", __func__, ethDevice->name);
+ return HDF_FAILURE;
+ }
+
+ ret = InitEth(ethDevice, g_ethConfig->deviceInst[i].isSetDefault, ethChipDriverFact);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s failed to init eth driver, ret: %d", __func__, ret);
+ return ret;
+ }
+ }
+ HDF_LOGD("%s success", __func__);
+ return ret;
+}
+
+static int32_t HdfEthDriverBind(struct HdfDeviceObject *deviceObject)
+{
+ (void)deviceObject;
+ return HDF_SUCCESS;
+}
+
+static void HdfEthDriverRelease(struct HdfDeviceObject *deviceObject)
+{
+ (void)deviceObject;
+}
+
+struct HdfDriverEntry g_ethEntry = {
+ .moduleVersion = 1,
+ .Bind = HdfEthDriverBind,
+ .Init = HdfEthDriverInit,
+ .Release = HdfEthDriverRelease,
+ .moduleName = "HDF_ETHERNET"
+};
+
+HDF_INIT(g_ethEntry);
\ No newline at end of file
diff --git a/model/network/wifi/platform/src/hdf_wlan_utils.c b/model/network/wifi/platform/src/hdf_wlan_utils.c
index cc92c61ee73cac69c60f17b9bb2cf8f7378a9da8..b7dc9ac2476f57d0d3bc60ca53e61b1b484bd3c5 100644
--- a/model/network/wifi/platform/src/hdf_wlan_utils.c
+++ b/model/network/wifi/platform/src/hdf_wlan_utils.c
@@ -96,9 +96,9 @@ int32_t RenewNetDevice(NetDevice **netDev)
}
*netDev = NULL;
#ifdef _PRE_HDF_LINUX
- result = NetDeviceInit(ifName, strlen(ifName), FULL_OS);
+ result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, FULL_OS);
#else
- result = NetDeviceInit(ifName, strlen(ifName), LITE_OS);
+ result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, LITE_OS);
#endif
if (result == NULL) {
HDF_LOGE("%s:alloc NetDevice return NULL!", __func__);
@@ -163,9 +163,9 @@ struct NetDevice *AllocPlatformNetDevice(struct HdfWlanDevice *device)
break;
}
#ifdef _PRE_HDF_LINUX
- result = NetDeviceInit(ifName, strlen(ifName), FULL_OS);
+ result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, FULL_OS);
#else
- result = NetDeviceInit(ifName, strlen(ifName), LITE_OS);
+ result = NetDeviceInit(ifName, strlen(ifName), WIFI_LINK, LITE_OS);
#endif
} while (false);
if (result == NULL) {
diff --git a/model/network/wifi/platform/src/qos/flow_control.c b/model/network/wifi/platform/src/qos/flow_control.c
index b4963f5cd8310244a3ac2e95780f06541de376cc..09c8faf905d81f1f55ae73c78a8ea7924f96018f 100644
--- a/model/network/wifi/platform/src/qos/flow_control.c
+++ b/model/network/wifi/platform/src/qos/flow_control.c
@@ -263,7 +263,7 @@ static FlowControlQueueID GetQueueIdByEtherBuff(const NetBuf *buff)
}
len = NetBufGetDataLen(buff);
if (len < sizeof(struct EtherHeader)) {
- HDF_LOGE("%s fail : buff->data_len not right!", __func__);
+ HDF_LOGE("%s fail : buff->dataLen not right!", __func__);
return QUEUE_ID_COUNT;
}
header = (struct EtherHeader *)NetBufGetAddress(buff, E_DATA_BUF);
diff --git a/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c b/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c
index 5d47a211d79946c398dfbf03af338f3195fb6477..4b6f169815fc2253a1fdb125ec95cb1a27d5b74d 100644
--- a/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c
+++ b/test/unittest/model/network/wifi/unittest/netdevice/net_device_test.c
@@ -25,7 +25,7 @@ static bool WiFiNetDeviceTestEnv(void)
HDF_LOGE("%s: strcpy_s fail", __func__);
return false;
}
- g_netDevice = NetDeviceInit(devName, strlen(devName), LITE_OS);
+ g_netDevice = NetDeviceInit(devName, strlen(devName), WIFI_LINK, LITE_OS);
if (g_netDevice == NULL) {
HDF_LOGE("%s fail ", __func__);
return false;
@@ -62,10 +62,14 @@ int32_t WiFiNetDviceTestAdd(void)
return HDF_FAILURE;
}
}
- if (NetDeviceAdd(g_netDevice, PROTOCOL_80211_IFTYPE_STATION) != HDF_SUCCESS) {
+ if (NetDeviceAdd(g_netDevice) != HDF_SUCCESS) {
HDF_LOGE("%s add fail!", __func__);
return HDF_FAILURE;
}
+ if (NetDevSpecialProc(g_netDevice, PROTOCOL_80211_IFTYPE_STATION) != HDF_SUCCESS) {
+ HDF_LOGE("%s specialProc fail!", __func__);
+ return HDF_FAILURE;
+ }
return HDF_SUCCESS;
}