A USB connection communication method and system

CN121387808BActive Publication Date: 2026-08-21NANJING QINHENG MICROELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511964242.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-08-21
Estimated Expiration
2045-12-24

AI Technical Summary

Technical Problem

[0006]发明目的:为了解决现有技术中USB设备在某些上位机操作系统下使用受限的问题,本发明提供一种USB连接通信方法及系统

Benefits of technology

[0029](1)通过将USB设备模拟成USB CDC-ECM/NCM等网卡,通过协商将上位机APP网络数据穿透到下位机,而后利用网络实现上位机应用APP与下位机之间通信。因网络权限要求比较低,无需单独申请,以解决不同操作系统带来的影响,使得不管上位机为何种操作系统,均可与下位机连接通信,兼容性高,降低了开发设计难度及成本;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387808B_ABST
    Figure CN121387808B_ABST
Patent Text Reader

Abstract

The application discloses a USB connection communication method and system, wherein a lower computer is connected to an upper computer through a USB interface and is recognized as a network card connected to a network by the upper computer; the method can realize communication between the upper computer and the lower computer in another form, has high compatibility and effectively reduces cost. The application solves the problem that USB peripheral operation interfaces and use restrictions opened by mobile operating systems such as Android, iOS and HarmonyOS are different, and different implementation mechanisms need to be adopted for peripheral communication of USB by application layer APP under different systems. The application makes the use of ordinary authorized USB devices more convenient on the operating system, has high compatibility and effectively reduces cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of USB communication technology, and particularly relates to a USB connection communication method and system. Background Technology

[0002] The ability of mobile devices (such as smartphones and tablets) to connect to external hardware has become one of the core competitive advantages of the modern smart device ecosystem. USB external device support, as a crucial component of this capability, exhibits distinctly different technical architectures, development paths, and ecosystem strategies across mobile operating system platforms such as Android, iOS, and HarmonyOS. USB external devices allow smartphones or tablets to act as hosts, connecting to and controlling external devices such as USB flash drives, keyboards, mice, or specialized peripherals, thereby expanding the productivity and application scenarios of mobile devices.

[0003] Starting with Android version 3.1, a complete USB Host API is provided at the application development level, including core classes such as UsbManager, UsbDevice, UsbInterface, UsbEndpoint, and UsbDeviceConnection. Developers can directly control device communication through these APIs, and users can access USB devices after authorization without additional authentication. HarmonyOS, as a newer system, is similar to Android, providing a rich set of USB interface operation APIs at the application layer, supporting operations on almost all USB device classes.

[0004] However, some operating systems are different. For example, the iOS platform has long maintained a closed MFi certification system. This closed nature is not only reflected in the control of hardware interfaces but also extends to all levels of software architecture and ecosystem strategy. In iOS, support for external USB devices relies on Apple's MFi certification system. Whether it's a Lightning or Type-C interface, uncertified accessories may not be recognized or may cause compatibility issues. While the closed nature of the Apple ecosystem ensures security, it limits the flexibility of peripheral selection.

[0005] Mobile operating systems such as Android, iOS, and HarmonyOS offer different USB peripheral operation interfaces and usage restrictions at the user application layer. This means that applications on different systems need to adopt different implementation mechanisms for communication with USB peripherals. iOS even requires MFi certification. This undoubtedly increases the difficulty and cost of developing a unified mechanism for systems such as Android / iOS, the time cost of the certification application process, and the cost of MFi certification chips. Summary of the Invention

[0006] Purpose of the invention: In order to solve the problem that USB devices are limited in use under certain host computer operating systems in the prior art, the present invention provides a USB connection communication method and system.

[0007] Technical solution: A USB connection communication method, comprising the following steps:

[0008] Connection access steps: The lower-level machine connects to the upper-level machine via a USB interface and is recognized by the upper-level machine system as a network card with a network connection. The upper-level machine application can find the network card through the system's built-in network interface. The lower-level machine waits to receive data packets containing specific content, which is the content agreed upon by the lower-level machine and the upper-level machine application.

[0009] Address negotiation steps: The host computer application generates a target address, which contains the specific content; the host computer application creates a network communication socket through the system interface and binds it to the network card; the host computer application initiates a first data packet, which contains the target address; the host computer system sends a first request, which contains the target address; the slave device receives the first request, identifies the specific content, uses the target address as the slave device's identity address, and replies with a valid response, which contains the slave device's media access control address.

[0010] Furthermore, in the connection access step, after the host computer identifies the network card, it initiates a request to obtain an IP address. If the request to obtain an IP address does not contain the specific content, the slave computer will not give a valid response.

[0011] Furthermore, the specific content is calculated based on the parameters and algorithms agreed upon by the lower-level machine and the upper-level machine application.

[0012] Furthermore, after the connection access step and before the address negotiation step, a probing step is also included: the host computer application initiates a second data packet, which is a broadcast packet or a multicast packet. If no valid response is received within a timeout, the address negotiation step is started.

[0013] Furthermore, in the address negotiation step, the first request is an address negotiation request or the first request is the same as the first data packet. When the first request is an address negotiation request, it also includes the host computer system allowing the first data packet to the slave computer after receiving a valid response.

[0014] Furthermore, it also includes a communication negotiation step for negotiating a communication port between the host computer and the slave computer. The communication port is obtained through allocation, randomly generated, or a fixed port is specified. When obtained through allocation, a dynamic allocation method is used, which specifically includes: randomly allocating a communication port from a port whitelist. The port whitelist consists of ports that have not been used by the host computer system or ports that have been used but have expired.

[0015] Furthermore, the communication negotiation step also includes setting a time-limited channel identifier by the lower-level machine; in the subsequent communication process, the data packets sent by the lower-level machine and the upper-level machine contain the time-limited channel identifier. After receiving the data packet, the upper-level machine checks whether the channel identifier has expired. If it is about to expire, it re-initiates the first data packet and re-negotiates the communication port.

[0016] Furthermore, the network card can be a standard USB Ethernet driver built into the system, or a USB network card customized by the USB manufacturer.

[0017] A USB-connected communication system includes: a host computer and a slave computer.

[0018] The host computer includes:

[0019] System network module: used to identify network cards that are connected to the network; used to send a first request, the first request containing the target address;

[0020] Network management module: It can locate the network card through the system's built-in network interface; create network communication sockets and bind them to the network card;

[0021] Address Management Module: Used to generate target addresses, which contain specific parts, and these specific parts are agreed upon by the lower-level machine and the upper-level application.

[0022] Negotiation unit: used to initiate a first data packet, the first data packet containing the target address;

[0023] The lower-level machine includes:

[0024] USB function module: used to connect to the host computer via USB interface;

[0025] Negotiation unit: used to wait to receive data packets containing specific content, including a first request; used to reply with a valid response to the first request, wherein the valid response contains the media access control address of the lower-level machine;

[0026] Address management module: Used to use the target address as the identity identifier address of the lower-level machine after identifying specific content.

[0027] Furthermore, the negotiation unit between the host computer and the slave computer is also used to allocate and negotiate communication ports; the address management module of the slave computer is also used to manage the port whitelist.

[0028] Compared with the prior art, the USB connection communication method and system provided by the present invention have the following advantages:

[0029] (1) By simulating a USB device as a USB CDC-ECM / NCM network card, network data from the host computer APP is transmitted to the slave computer through negotiation, and then communication between the host computer APP and the slave computer is realized through the network. Because the network permission requirements are relatively low and no separate application is required, the impact of different operating systems is solved, so that the host computer can connect and communicate with the slave computer regardless of the operating system, which has high compatibility and reduces the difficulty and cost of development and design.

[0030] (2) This approach breaks away from the conventional handshake negotiation method. The host computer generates a target address containing specific content, and the slave computer obtains and identifies the target address, using it as its own identity address to negotiate the addresses of both parties. In contrast, the conventional approach in existing technologies requires the slave computer to first have its own IP address and then confirm the connection object through the host computer. The advantages of this approach are: when the host computer initiates a request to obtain an IP address, the slave computer does not respond effectively, has no IP address, and will not obtain a network address from external routers or other devices. This will not affect the system's routing strategy, nor will it affect other apps on the host computer's network access, making it widely applicable.

[0031] (3) USB devices can be used in operating systems such as iOS that require special authorization without special certification, saving the time cost of certification cycle. At the same time, since Apple switched to Type-C interface starting with iPhone 15, it no longer needs to consider MFi certification issues, which also reduces chip costs. Attached Figure Description

[0032] Figure 1 This is a flowchart of the USB connection communication method in Example 1;

[0033] Figure 2 This is a structural block diagram of the USB connection communication system in Embodiment 1. Detailed Implementation

[0034] The present invention will be further explained and described below with reference to the accompanying drawings and specific embodiments.

[0035] Example 1:

[0036] A USB connection communication method, such as Figure 1 As shown, it includes the following steps:

[0037] Connection Access Steps: The lower-level device connects to the upper-level device via a USB interface and is recognized by the upper-level device as a network interface card (NIC) with a network connection. The upper-level application can locate the NIC through the system interface, such as a USB CDC-ECM mode NIC, a USB CDC-NCM mode NIC, or a manufacturer-customized NIC. The lower-level device waits to receive data packets containing specific content, which is agreed upon by the lower-level device and the upper-level application. When the received data packet does not contain the specific content, the lower-level device does not provide a valid response (it may not respond or may provide an invalid response). Only when the data packet contains the specific content will the lower-level device process a response. For example, after the access action occurs, the upper-level device will initiate an IP address acquisition request (such as a DHCP request or a DHCPv6 request) according to the normal procedure. The IP address acquisition request does not contain the specific content, so the lower-level device does not respond, the upper-level device cannot obtain an IP address, and the interface will not be in the system routing table rules. Therefore, the upper-level application's access to the network will not be affected.

[0038] The lower-level device can be recognized by the upper-level device as a network card that is connected to the network. In practical applications, this can be achieved in several ways. For example, the lower-level device can run and load firmware to simulate a USB CDC-ECM / NCM type network card, match the system's built-in standard USB Ethernet driver, or a USB manufacturer-customized network card, and report the connection status. The upper-level device can then recognize it as a network card that is connected to the network. For the manufacturer-customized network card, the manufacturer's driver needs to be installed on the upper-level device first to be recognized as a USB Ethernet device.

[0039] The specific content refers to the content calculated according to the parameters and algorithms agreed upon by the lower-level machine and the upper-level application. For example, the nth and mth bits of the target address are encrypted using algorithms, pseudo-random numbers, and checksums to generate specific content, which is then used as the xth bit (or multiple bits) of the target address. Only the lower-level machine and the upper-level application can encode / decode this specific content.

[0040] Address negotiation steps: The host computer generates a target address, which contains the specific content. This target address may be an IPv6 address or an IPv4 address. The host computer application uses the system interface to create a network communication socket and binds it to the network card. This step can be performed simultaneously with the target address generation, and the order is not important. The host computer initiates a first data packet, such as a connection handshake request packet or other data packets, to trigger the system to send a first request. For example, in this embodiment, the first request is an address negotiation request, and the first data packet contains the target address. The system sends an address negotiation request, such as a Neighbor Solicitation (NS) message or an ARP (Address Resolution Protocol) request, which contains the target address. The slave computer receives the address negotiation request, identifies the specific content, uses the target address as the slave computer's identity address, such as an IP address, and replies with a valid response, such as a Neighbor Advertisement (NA) message or an ARP response. The valid response contains the slave computer's Medium Access Control (MEC) information. Access Control (MAC) address; after the host computer system receives a valid response to the address negotiation, it updates the neighbor cache or ARP table. After the system network module queries the destination address in the neighbor cache, the host computer system allows the first data packet to be sent to the slave computer.

[0041] In addition to negotiating addresses, the host computer and the slave computer also need to negotiate communication ports. The communication port can be determined in various ways, such as through allocation, random generation, or designation of a fixed port. When the communication port is determined through allocation or random generation, a communication negotiation step should also be included. For example... Figure 1 As shown, after address negotiation is completed, a communication negotiation step is also included, which negotiates the communication port through an allocation method, specifically including:

[0042] When the lower-level machine receives the first data packet, it allocates a communication port. The allocation is preferably done dynamically, that is, it randomly allocates a communication port from a port whitelist. The port whitelist consists of ports that have not been used by the upper-level system or ports that have been used but have expired. The lower-level machine then replies with a valid response to the system authentication channel address, which is the source address and source port number of the connection request. When the upper-level machine receives the valid response, it sets the communication port and establishes a communication channel with the lower-level machine.

[0043] Preferably, the valid response from the lower-level machine in the communication negotiation step may also include a time-limited channel identifier; in subsequent communication processes, the data packets sent by the lower-level machine and the upper-level machine contain the time-limited channel identifier. After receiving the data packet, the upper-level machine checks whether the channel identifier has expired. If it is about to expire, it re-initiates the first data packet, and the lower-level machine reallocates the communication port. For example, a period of time can be set as a threshold. When the channel identifier is about to expire, it is considered to be about to expire.

[0044] Preferably, during subsequent communication, if the data packet received by the lower-level device does not contain the target address, it notifies the upper-level device to re-initiate the first data packet. The lower-level device can also transfer USB data to other interfaces, such as UART, SPI, etc., through the data interaction unit.

[0045] A USB connection communication system, such as Figure 2 As shown, it includes: a host computer and a slave computer.

[0046] 1. The host computer includes:

[0047] The system network module is used to identify network interface cards (NICs) that are already connected to the network; it is also used to issue address negotiation requests, which include the target address. This module provides stable Ethernet connectivity and supports complete communication services across the data link layer, network layer, transport layer, and application layer. All data packets are sent and received through this module.

[0048] The network management module can locate the network card through the system's built-in network interface; create a network communication socket and bind it to the network card;

[0049] The address management module is used to generate a target address, which contains a specific part, and the specific part is agreed upon by the lower-level machine and the upper-level application.

[0050] Negotiation unit: used to initiate a first data packet, the first data packet containing the target address; it can also be used to negotiate the communication port;

[0051] The data transceiver module provides an operation interface for external data communication and can also be used to detect and verify whether the channel identifier has expired.

[0052] 2. The lower-level machine includes:

[0053] The USB function module is used to connect to the host computer via the USB interface and is responsible for communicating with the host computer.

[0054] The negotiation unit is used to wait for data packets containing specific content, including address negotiation requests; to respond to address negotiation requests with a valid response, the valid response containing the MAC address of the lower-level machine; and to negotiate the communication port.

[0055] The address management module, after identifying specific content, uses the target address as the identity identifier address of the lower-level device; it can also be used to identify the target address and communication port in the received data packets during subsequent communication; and it can also be used to manage port whitelists.

[0056] It may also include a data interaction module for converting the USB interface into other interfaces besides USB, such as UART, SPI, etc.

[0057] The USB connection communication system also includes other necessary modules, such as USB HOST, which will not be described in detail here.

[0058] Example 2:

[0059] The difference between Example 2 and Example 1 is that, after the connection access step and before the address negotiation step, a probing step is included: the host computer application initiates a second data packet, which is either a broadcast packet or a multicast packet. If no valid response is received within a timeout, the address negotiation step continues. If a valid response is received within a set time, it indicates that the system has broadcast or multicast permissions, and the host computer application and the slave computer can connect and communicate via multicast. Of course, to further improve the security of broadcast or multicast communication, the address negotiation step can be continued; if security is not a concern, communication can be directly conducted via broadcast or multicast.

[0060] In the address negotiation step, address negotiation can be performed using broadcast or multicast methods, or as in Embodiment 1. It should be noted that when using broadcast or multicast for address negotiation, after the host application initiates the first data packet, the system directly sends the first data packet as the first request to the slave device. Upon receiving the first request, the slave device identifies the specific content, uses the target address as its identity address (e.g., IP address), and replies with a valid response. This valid response includes the slave device's Medium Access Control (MAC) address. Because the first request in this embodiment is the first data packet, there is no need for the host device to send the first data packet to the slave device again after receiving the valid response.

[0061] This method can further improve system security when the host computer application and the slave computer are connected and communicated via broadcast or multicast, and it is also beneficial for application scenarios with multiple slave computers.

Claims

1. A USB connection communication method, characterized in that, Includes the following steps: Connection access steps: The lower-level device connects to the upper-level device via a USB interface and is recognized as a network-connected NIC by the upper-level system. The upper-level application can find the NIC through the system's built-in network interface. The lower-level device is a USB device, and the NIC is compatible with the system's built-in standard USB Ethernet driver or a manufacturer-defined USB NIC. The lower-level device waits to receive data packets containing specific content, which is agreed upon by the lower-level device and the upper-level application. When the received data packet does not contain the specific content, the lower-level device does not respond effectively; it only responds when the specific content is included. After the access action occurs, the upper-level device recognizes the NIC and initiates an IP address acquisition request. If the IP address acquisition request does not contain the specific content, the lower-level device does not respond effectively, and the upper-level device cannot obtain an IP address. Address negotiation steps: The host computer application generates a target address, which contains the specific content; the host computer application creates a network communication socket through the system interface and binds it to the network card; the host computer application initiates a first data packet, which contains the target address, and the first data packet triggers the host computer system to send a first request, which is an address negotiation request and contains the target address; the slave device receives the first request, identifies the specific content, uses the target address as the slave device's identity address, which is an IP address, and replies with a valid response, which contains the slave device's media access control address; after receiving the valid response, the host computer system updates the neighbor cache or ARP table and allows the first data packet to pass to the slave device.

2. The USB connection communication method according to claim 1, characterized in that, The specific content is calculated based on the parameters and algorithms agreed upon by the lower-level machine and the upper-level machine application.

3. The USB connection communication method according to claim 1 or 2, characterized in that, After the connection access step and before the address negotiation step, a probing step is also included: the host computer application initiates a second data packet, which is a broadcast packet or a multicast packet. If no valid response is received within the timeout period, the address negotiation step is started.

4. The USB connection communication method according to claim 1 or 2, characterized in that, It also includes a communication negotiation step, which is used to negotiate the communication port between the host computer and the slave computer. The communication port is obtained by allocation, randomly generated, or a fixed port is specified. When it is obtained by allocation, a dynamic allocation method is used, which specifically includes: randomly allocating a communication port from a port whitelist. The port whitelist consists of ports that have not been used by the host computer system or ports that have been used but have expired.

5. The USB connection communication method according to claim 4, characterized in that, The communication negotiation step also includes setting a time-limited channel identifier on the lower-level machine; in subsequent communication processes, the data packets sent by the lower-level machine and the upper-level machine contain the time-limited channel identifier. After receiving the data packet, the upper-level machine checks whether the channel identifier has expired. If it is about to expire, it re-initiates the first data packet and renegotiates the communication port.

6. A USB connection communication system, characterized in that, include: A host computer and a slave computer, wherein the slave computer is a USB device. The host computer includes: The system network module is used to identify network interface cards (NICs) that are already connected to the network. After an access action occurs and the NIC is identified, it initiates an IP address acquisition request. If the IP address acquisition request does not contain specific content, the host computer will not be able to obtain an IP address. The NIC can be a standard USB Ethernet driver that is compatible with the system's built-in driver or a manufacturer-defined USB NIC. It is used to issue a first request, which is an address negotiation request containing a target address. After receiving a valid response, it is used to update the neighbor cache or ARP table and allow the first data packet to pass to the lower-level computer. Network management module: It can locate the network card through the system's built-in network interface; create network communication sockets and bind them to the network card; Address Management Module: Used to generate target addresses, which contain specific parts, and these specific parts are agreed upon by the lower-level machine and the upper-level application. Negotiation Unit: Used to initiate a first data packet, which triggers the system to send a first request. The first data packet contains a target address. The lower-level machine includes: USB function module: used to connect to the host computer via USB interface; Negotiation Unit: When the received data packet does not contain specific content, the lower-level device does not make a valid response; the lower-level device will only process the response when it contains specific content. It is used to wait for receiving data packets containing specific content, including the first request. For requests to obtain an IP address that do not contain specific content, it does not make a valid response. It is used to reply to the first request with a valid response, wherein the valid response contains the lower-level device's media access control address. Address management module: After identifying specific content, the target address is used as the identity identifier address of the lower-level machine, and the identity identifier address is an IP address.

7. The USB connection communication system according to claim 6, characterized in that, The negotiation unit between the host computer and the slave computer is also used to allocate and negotiate communication ports; the address management module of the slave computer is also used to manage the port whitelist.

Citation Information

Patent Citations

  • Communication method and system for external usb network card of CTID intelligent access control

    CN112968791A

  • Self-adaptive USB network sharing method and device and MIFI equipment

    CN119254717A