add get_connect_status api for rndis/cdc_ecm/asix

This commit is contained in:
sakumisu
2024-02-24 10:49:11 +08:00
parent b4e952b371
commit 762c3cbb2f
6 changed files with 31 additions and 29 deletions

View File

@@ -43,7 +43,7 @@ static int usbh_cdc_ecm_set_eth_packet_filter(struct usbh_cdc_ecm *cdc_ecm_class
return usbh_control_transfer(cdc_ecm_class->hport, setup, NULL);
}
int usbh_cdc_ecm_get_notification(struct usbh_cdc_ecm *cdc_ecm_class)
int usbh_cdc_ecm_get_connect_status(struct usbh_cdc_ecm *cdc_ecm_class)
{
int ret;
@@ -244,7 +244,7 @@ find_class:
}
while (g_cdc_ecm_class.connect_status == false) {
ret = usbh_cdc_ecm_get_notification(&g_cdc_ecm_class);
ret = usbh_cdc_ecm_get_connect_status(&g_cdc_ecm_class);
if (ret < 0) {
usb_osal_msleep(100);
goto find_class;

View File

@@ -38,6 +38,8 @@ struct usbh_cdc_ecm {
extern "C" {
#endif
int usbh_cdc_ecm_get_connect_status(struct usbh_cdc_ecm *cdc_ecm_class);
void usbh_cdc_ecm_run(struct usbh_cdc_ecm *cdc_ecm_class);
void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class);

View File

@@ -21,21 +21,21 @@ static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[CONFIG_US
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_inttx_buffer[16];
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_buf[32];
#define ETH_ALEN 6
#define ETH_ALEN 6
#define PHY_MODE_MARVELL 0x0000
#define MII_MARVELL_LED_CTRL 0x0018
#define MII_MARVELL_STATUS 0x001b
#define MII_MARVELL_CTRL 0x0014
#define PHY_MODE_MARVELL 0x0000
#define MII_MARVELL_LED_CTRL 0x0018
#define MII_MARVELL_STATUS 0x001b
#define MII_MARVELL_CTRL 0x0014
#define MARVELL_LED_MANUAL 0x0019
#define MARVELL_LED_MANUAL 0x0019
#define MARVELL_STATUS_HWCFG 0x0004
#define MARVELL_STATUS_HWCFG 0x0004
#define MARVELL_CTRL_TXDELAY 0x0002
#define MARVELL_CTRL_RXDELAY 0x0080
#define MARVELL_CTRL_TXDELAY 0x0002
#define MARVELL_CTRL_RXDELAY 0x0080
#define PHY_MODE_RTL8211CL 0x000C
#define PHY_MODE_RTL8211CL 0x000C
#define AX88772A_PHY14H 0x14
#define AX88772A_PHY14H_DEFAULT 0x442C
@@ -46,8 +46,8 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_buf[32];
#define AX88772A_PHY16H 0x16
#define AX88772A_PHY16H_DEFAULT 0x4044
#define SPEED_100 0
#define SPEED_10 1
#define SPEED_100 0
#define SPEED_10 1
static int usbh_asix_read_cmd(struct usbh_asix *asix_class,
uint8_t cmd,
@@ -576,7 +576,7 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_asix_mdio_write(asix_class, asix_class->phy_addr, 0, 0x3900);
usbh_asix_mdio_read(asix_class, asix_class->phy_addr, 0);
usbh_asix_mdio_write(asix_class, asix_class->phy_addr, 0, 0x3100);
usbh_asix_mdio_read(asix_class, asix_class->phy_addr, 4);
@@ -587,8 +587,6 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_asix_mdio_read(asix_class, asix_class->phy_addr, 0);
}
usbh_asix_set_multicast(asix_class);
USB_LOG_INFO("Init %s done\r\n", asix_class->name);
memcpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
@@ -628,7 +626,7 @@ static int usbh_asix_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
int usbh_asix_get_notification(struct usbh_asix *asix_class)
int usbh_asix_get_connect_status(struct usbh_asix *asix_class)
{
int ret;
@@ -642,6 +640,7 @@ int usbh_asix_get_notification(struct usbh_asix *asix_class)
if (g_asix_inttx_buffer[2] & 0x01) {
asix_class->connect_status = true;
usbh_ax88772_mac_link_up(asix_class, SPEED_100, 1, 1, 1);
usbh_asix_set_multicast(asix_class);
} else {
asix_class->connect_status = false;
usbh_ax88772_mac_link_down(asix_class);
@@ -670,7 +669,7 @@ find_class:
}
while (g_asix_class.connect_status == false) {
ret = usbh_asix_get_notification(&g_asix_class);
ret = usbh_asix_get_connect_status(&g_asix_class);
if (ret < 0) {
usb_osal_msleep(100);
goto find_class;

View File

@@ -165,7 +165,7 @@ struct usbh_asix {
extern "C" {
#endif
int usbh_asix_get_notification(struct usbh_asix *asix_class);
int usbh_asix_get_connect_status(struct usbh_asix *asix_class);
void usbh_asix_run(struct usbh_asix *asix_class);
void usbh_asix_stop(struct usbh_asix *asix_class);

View File

@@ -189,7 +189,7 @@ static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t
return ret;
}
static int usbh_rndis_get_connect_status(struct usbh_rndis *rndis_class)
int usbh_rndis_get_connect_status(struct usbh_rndis *rndis_class)
{
int ret;
uint8_t data[32];
@@ -200,9 +200,9 @@ static int usbh_rndis_get_connect_status(struct usbh_rndis *rndis_class)
return ret;
}
if (NDIS_MEDIA_STATE_CONNECTED == data[0]) {
rndis_class->link_status = true;
rndis_class->connect_status = true;
} else {
rndis_class->link_status = false;
rndis_class->connect_status = false;
}
return 0;
}
@@ -330,9 +330,9 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
goto query_errorout;
}
if (NDIS_MEDIA_STATE_CONNECTED == data[0]) {
rndis_class->link_status = true;
rndis_class->connect_status = true;
} else {
rndis_class->link_status = false;
rndis_class->connect_status = false;
}
break;
case OID_802_3_MAXIMUM_LIST_SIZE:
@@ -442,12 +442,12 @@ void usbh_rndis_rx_thread(void *argument)
// clang-format off
find_class:
// clang-format on
g_rndis_class.link_status = false;
g_rndis_class.connect_status = false;
if (usbh_find_class_instance("/dev/rndis") == NULL) {
goto delete;
}
while (g_rndis_class.link_status == false) {
while (g_rndis_class.connect_status == false) {
ret = usbh_rndis_get_connect_status(&g_rndis_class);
if (ret < 0) {
usb_osal_msleep(100);
@@ -517,7 +517,7 @@ err_t usbh_rndis_linkoutput(struct netif *netif, struct pbuf *p)
uint8_t *buffer;
rndis_data_packet_t *hdr;
if (g_rndis_class.link_status == false) {
if (g_rndis_class.connect_status == false) {
return ERR_BUF;
}

View File

@@ -27,7 +27,7 @@ struct usbh_rndis {
uint32_t request_id;
uint32_t link_speed;
bool link_status;
bool connect_status;
uint8_t mac[6];
ip_addr_t ipaddr;
@@ -39,6 +39,7 @@ struct usbh_rndis {
extern "C" {
#endif
int usbh_rndis_get_connect_status(struct usbh_rndis *rndis_class);
int usbh_rndis_keepalive(struct usbh_rndis *rndis_class);
void usbh_rndis_run(struct usbh_rndis *rndis_class);