Method for realizing open source gap soft bus communication based on TAP equipment
Through interactive management between open source Hongmeng terminal and server, cellular networks and virtual network devices are used to realize device communication across physical locations, the open source Hongmeng system's dependence on near-field communication is solved, and data transmission and collaborative work of cross-region devices is ensured.
Patent Information
- Application Number
- CN202510251020.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-04
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-03-04
AI Technical Summary
The distributed soft bus technology of the existing open source Hongmeng system relies on near-field communication, which makes it impossible for devices across physical locations to communicate effectively, limiting the application of cross-regional and long-distance device collaboration scenarios.
By starting a specific application on the open source Hongmeng terminal, using the cellular network to obtain the network address, the terminal establishes a connection with the server, the server manages terminal information and allocates a group code, the terminal configures a network card and builds a forwarding mapping, and realizes device communication across physical locations.
It breaks through the limitations of near-field communication and realizes device communication at different physical locations, ensuring the stability and reliability of data transmission and coordinated work of multiple devices.
Smart Images

Figure CN120281595A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of network communication, and in particular, to a method for implementing open-source HarmonyOS soft bus communication based on a TAP device. Background Art
[0002] With the popularization of intelligent devices, people's demand for device collaboration has been increasing. The distributed soft bus technology of the open-source HarmonyOS system emerged. It realizes unified communication management of "discovery, networking, and transmission" among nearby devices through a local area network formed by WLAN or Bluetooth.
[0003] However, there are obvious limitations in this technology at present. Device discovery requires being in the same second-layer local area network. For example, multiple open-source HarmonyOS mobile phones are often in different physical locations, making it difficult to meet this condition, resulting in the inability to communicate with each other through near-field communication. The multi-device collaboration function relying on it cannot be effectively carried out, greatly restricting the application of open-source HarmonyOS in scenarios of cross-region and long-distance device collaboration. Overcome the dependence on near-field communication.
[0004] As can be seen from the above, how to reduce the dependence on near-field communication while realizing device communication across physical locations still remains to be solved. Summary of the Invention
[0005] In order to reduce the dependence on near-field communication while realizing device communication across physical locations, this application provides a method for implementing open-source HarmonyOS soft bus communication based on a TAP device.
[0006] In a first aspect, this application provides a method for implementing open-source HarmonyOS soft bus communication based on a TAP device, adopting the following technical solution:
[0007] A method for implementing open-source HarmonyOS soft bus communication based on a TAP device, including: starting a specific application program on an open-source HarmonyOS terminal, generating a network identifier based on the device's unique identifier information by the specific application program, obtaining the corresponding network port listening permission and network address, establishing a connection with a server using the Transmission Control Protocol, and periodically sending information packets containing terminal key information to the server; the server receives the information packets, manages the terminal information records according to the terminal identifier after parsing the information packets, and in response to the terminal's request for a group code, the server returns an existing group code or generates a new unique group code to the terminal; after obtaining the group code confirmed by the user, the terminal sends a join request to the server, the server updates the terminal group information, the server allocates network address resources for the terminal and generates corresponding relevant network parameter information, and at the same time aggregates and sends the group terminal information to each terminal, and the terminal creates and configures a network card using a virtual network device based on the group terminal information; the terminal constructs a forwarding mapping based on the received group terminal information, and during the soft bus data transmission process, queries the mapping according to the soft bus data destination identifier for data packet forwarding, and at the same time performs legality verification and processing on the received data packets according to the mapping; determines whether the terminal status has changed, and if the terminal status changes, the server collects relevant information and updates the status of the terminals in the group, and each terminal updates the local status information according to the server feedback.
[0008] By adopting the above technical solution, by starting a specific application program on an open-source HarmonyOS terminal, the connection and information interaction between the terminal and the server are completed, the server manages the terminal information and allocates group codes, and after the terminal joins the group, it configures the network card and constructs a forwarding mapping to achieve accurate data forwarding and legality verification, and can also update relevant information according to the change of the terminal status. Therefore, in terms of reducing the dependence on near-field communication, it is no longer limited to near-field communication methods such as WLAN or Bluetooth in the same second-layer local area network, but uses the cellular network to obtain network addresses. Through the interaction management between the server and the terminal, with the help of virtual network devices and forwarding mapping mechanisms, cross-physical location device communication is achieved, enabling open-source HarmonyOS devices in different physical locations to break through the limitations of near-field communication and perform effective data transmission and multi-device collaborative work.
[0009] Optionally, the method further includes: during the initialization of the association between the terminal and the server, the device's unique identifier information is the device's unique serial number SN, the MAC address is generated by calculating the hash mapping, the network address is the dynamic IPv6 address allocated by the operator obtained through cellular network dialing, and the key information includes SN, MAC address, IPv6 address, UDP port, and heartbeat interval. The virtual local area network application program uses the TCP protocol to establish a connection with the server and send a "heartbeat packet".
[0010] By adopting the above technical solution, through a virtual local area network application program, a MAC address is generated using the unique serial number SN of the device, a dynamic IPv6 address is obtained through the cellular network, key information is integrated to form a "heartbeat message", and then a connection is established with the server using the TCP protocol and sent periodically. Its function is to achieve a stable association between the terminal and the server, providing basic support for subsequent real-time monitoring of the terminal status by the server, information management, and cross-physical location communication-related operations based on this, ensuring that in a non-proximity communication environment, the server can continuously obtain the terminal status and accurately identify the terminal, and guaranteeing the smooth progress of the communication process.
[0011] Optionally, in the server information management and group code processing step, the server performs the following operations: maintain a list of group code usage records; when receiving a "request for group code message" from a terminal and there is no group code for the corresponding terminal entry, generate a new group code, and during the generation process, check whether the new group code is in the usage record list. If it is, regenerate it until a unique and unused group code is obtained and returned to the terminal.
[0012] By adopting the above technical solution, in the server information management and group code processing link, the server maintains a list of group code usage records, and when processing a terminal's request for a group code, generates a new group code for a terminal without a group code and repeatedly checks its uniqueness. This operation ensures the uniqueness and effectiveness of the group code within the system, avoids group code conflicts, provides a reliable basis for the terminal to accurately join a specific group, thus guaranteeing the orderliness of group management and the accuracy of communication in the virtual local area network, enabling different terminals to achieve effective group communication based on a unique group code, and enhancing the stability and reliability of the cross-physical location device communication system.
[0013] Optionally, in the terminal group joining and network adaptation step, the server performs the following operations: after receiving a "request to join group message" from a terminal, search for the corresponding entry in the "terminal information data table" through the SN and update the group code; when allocating an idle IP address from the IP address pool within the group, use a conflict detection algorithm to detect each candidate IP address. If it is already occupied, select the next one until an unoccupied IP address is found; generate a "terminal network parameter information message" with the allocated IP address, subnet mask, and broadcast address and return it to the terminal; generate a "group terminal list message" with the information of multiple terminals having the same group code and send it to all terminals within the group.
[0014] By adopting the above technical solution, when the server receives a request from a terminal to join a group, it accurately updates the terminal group code, uses a conflict detection algorithm to assign a unique IP address to it, and generates key network parameters and a group terminal list to send to the relevant terminals. This series of operations constructs the network identity and communication environment of the terminal within the group, ensures that each terminal has a dedicated and non-conflicting network address, enables them to know each other based on the group terminal list, lays a solid foundation for smooth communication between devices across physical locations within the same virtual local area network, and guarantees the orderly progress of subsequent data transmission and interaction.
[0015] Optionally, in the step of data forwarding and communication control based on mapping, the terminal performs the following operations: After receiving the "Group Terminal List Message", it parses the SN, MAC, IPv6 address, and UDP port information of each terminal, and uses a hash table data structure to generate a "Local Forwarding Mapping Table"; when the distributed soft bus sends a message through the Linux kernel network protocol stack to the tap network card, it receives the "Soft Bus Data Message", encapsulates it into a UDP data packet, parses the Ethernet layer 2 header to obtain the destination MAC address, and queries the "Local Forwarding Mapping Table"; if there is a corresponding entry, it sends the UDP data packet to the IPv6 address and UDP port of this entry, if not, it broadcasts and sends it to the addresses and ports of other entries except the local machine; when receiving a message through the monitored UDP port, it obtains the IPv6 address and UDP port of the peer of the message, and queries the "Local Forwarding Mapping Table"; if there is no corresponding entry, it discards the message, if there is, it parses the Ethernet layer 2 message to obtain the source MAC address, compares it with the MAC address of the corresponding entry in the mapping table, if they are equal, it submits the UDP data message through the tap network card to the Linux kernel for processing by the network protocol stack and submits it to the distributed soft bus, if not equal, it discards the message.
[0016] By adopting the above technical solution, in the link of data forwarding and communication control based on mapping, the terminal generates a mapping table by parsing group terminal information, and makes accurate matching and decisions based on this when receiving and sending data. When sending data, it can accurately forward or broadcast according to the destination address; when receiving data, it strictly verifies the legitimacy of the source and only processes legitimate messages. This ensures the efficient, accurate and secure transmission of data between devices across physical locations, effectively avoids interference from illegal data, and guarantees the stable operation of the OpenHarmony soft bus communication system and the reliability of data interaction.
[0017] Optionally, in the terminal state management and system maintenance step, the server and the terminal perform the following operations: when the user closes the virtual local area network function on the terminal interface, the terminal application sends a "request to leave the group message" to the server carrying the SN and the group code; after receiving the "request to leave the group message", the server sorts the terminal information in the group and arranges it according to rules such as the alphabetical order of the SN or the time order of joining the group; the server generates a "group terminal list message" excluding the terminal information and sends it to all terminals in the group; after each terminal receives the "group terminal list message", it updates the "local forwarding mapping table"; the server presets N heartbeat cycles to monitor the "heartbeat messages" sent by the terminal. If the "heartbeat message" of a certain terminal is not received within the cycle, the server performs the operations of sorting the terminal information in the group, generating and sending the "group terminal list message" as described above, and each terminal also updates the "local forwarding mapping table".
[0018] By adopting the above technical solution, in the terminal state management and system maintenance process, the server and the terminal cooperate. The terminal actively reports the leave request, and the server re-organizes the terminal information in the group accordingly, generates an updated list and pushes it to each terminal. At the same time, the server actively discovers abnormal offline terminals through heartbeat monitoring and also performs update operations. This series of operations can timely sense the changes in the terminal state, dynamically adjust the group information, ensure that the local forwarding mapping table of each terminal always matches the actual member composition of the group, maintain the stable operation of the communication system of devices across physical locations, ensure that data transmission is always based on accurate terminal relationships, and improve the overall reliability and adaptability of the system.
[0019] In a second aspect, the present application provides a device for implementing open-source HarmonyOS soft bus communication based on a TAP device, adopting the following technical solution:
[0020] A device for implementing open-source HarmonyOS soft bus communication based on a TAP device, comprising:
[0021] A network identifier generation module, which starts a specific application program on an open-source HarmonyOS terminal. The specific application program generates a network identifier based on the device unique identifier information, obtains the corresponding network port listening permission and network address, establishes a connection with the server using the Transmission Control Protocol, and periodically sends an information message containing terminal key information to the server;
[0022] The server receives the information message. After parsing the information message, the server manages the terminal information record according to the terminal identifier, and responds to the terminal's request for the group code. The server returns the existing group code or generates a new unique group code to the terminal;
[0023] After the terminal obtains the group code confirmed by the user, it initiates a joining request to the server. The server updates the terminal group information, allocates network address resources to the terminal and generates corresponding related network parameter information. At the same time, the group terminal information is summarized and sent to each terminal. The terminal uses the virtual network device to create and configure the network card based on the group terminal information.
[0024] The terminal constructs a forwarding map based on the received group terminal information. During the soft bus data transmission process, the terminal queries the map according to the soft bus data destination identifier to forward the data packet, and at the same time verifies and processes the received data packet based on the map.
[0025] The terminal status judgment module is used to judge whether the terminal status has changed. If the terminal status has changed, the server collects relevant information and updates the terminal status in the group. Each terminal updates the local status information according to the server feedback.
[0026] In the third aspect, the present application provides a system for implementing open source Hongmeng soft bus communication based on TAP devices, adopting the following technical solutions:
[0027] A system for implementing open source Hongmeng soft bus communication based on a TAP device, comprising a processor, in which a program of any one of the above-mentioned methods for implementing open source Hongmeng soft bus communication based on a TAP device is running.
[0028] In a fourth aspect, the present application provides a storage medium, which adopts the following technical solution:
[0029] A storage medium storing a program of any one of the above methods for implementing open source Hongmeng soft bus communication based on a TAP device.
[0030] In summary, the present application includes at least one of the following beneficial technical effects:
[0031] First, by launching a specific application on the open source Hongmeng terminal and obtaining the network address through the cellular network, the terminal can establish a connection with the server and exchange information. The server manages the terminal information and assigns group codes. After the terminal joins the group, it configures the network card and builds a forwarding map to achieve device communication across physical locations. This breaks the limitation of the open source Hongmeng soft bus relying on near-field communication, allowing devices in different locations to effectively transmit data and work together.
[0032] Secondly, in the processes of terminal initialization and association with the server, server information management and group code processing, terminal group joining and network adaptation, data forwarding and communication control based on mapping, and terminal status management and system maintenance, through a series of orderly operations, from building a stable connection, ensuring the uniqueness of the group code, allocating network resources, ensuring accurate and secure data transmission to dynamically adjusting group information, a solid foundation is laid for cross-physical location device communication in all aspects, ensuring the stable, efficient, and reliable operation of the communication system. Description of the Drawings
[0033] Figure 1 is a flowchart of a method for implementing open-source HarmonyOS soft bus communication based on a TAP device shown according to an exemplary embodiment. Detailed Embodiments
[0034] The following describes in detail the embodiments of the present application, and the examples of the embodiments are shown in the drawings.
[0035] In the description of this specification, the description with reference to the terms "certain embodiments", "one embodiment", "some embodiments", "schematic embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples.
[0036] An embodiment of the present application discloses a method for implementing open-source HarmonyOS soft bus communication based on a TAP device, referring to Figure 1 , including:
[0037] S100, start a specific application program on the open-source HarmonyOS terminal. The specific application program generates a network identifier based on the device's unique identifier information, obtains the corresponding network port listening permission and network address, establishes a connection with the server using the Transmission Control Protocol, and periodically sends an information packet containing the terminal's key information to the server.
[0038] Among them, the user manually starts a specially developed virtual local area network application program on the terminal interface of the open-source HarmonyOS system. The virtual local area network application program is the key entry point for realizing cross-region device communication. The startup of the virtual local area network application program marks the start of the entire communication process. After the virtual local area network application program is started, using the unique serial number (SN) given during device production, through a specific hash mapping algorithm, the SN is converted into a MAC address. In a local area network environment, the MAC address is like the ID card of the device, and network devices identify and distinguish different terminals based on it to ensure that data is accurately sent to the target device.
[0039] To meet specific data reception requirements, the virtual local area network application randomly selects a UDP port for listening. Among them, the UDP protocol is simple and efficient, without the need for complex connection establishment and maintenance processes, and is suitable for scenarios with high requirements for real-time performance and little impact from small amounts of data loss. The subsequent data transmission will utilize its characteristics to achieve fast communication. Due to the sharp increase in the number of Internet of Things devices and the exhaustion of traditional IPv4 address resources, the virtual local area network application dials through the cellular network to obtain a dynamically allocated IPv6 address from the operator network. This dynamic allocation method enables devices to flexibly obtain available network addresses in different network environments, laying a foundation for device access to the Internet and the construction of a virtual local area network.
[0040] The virtual local area network application uses the TCP protocol to establish a stable and reliable communication link with the server. The TCP protocol ensures the accurate and complete transmission of data through a three-way handshake. After the connection is established, the application periodically sends a "heartbeat message" to the server. The message contains information such as the local SN, generated MAC address, obtained IPv6 address, listened UDP port, and set heartbeat interval. By continuously receiving the heartbeat message, the server can judge the online status of the device and obtain the latest network status information for subsequent management and coordination.
[0041] S110, the server receives the information message. After parsing the information message, the server manages the terminal information record according to the terminal identifier and responds to the terminal's request for the group code. The server returns the existing group code or generates a new unique group code to the terminal.
[0042] Among them, after the server receives the "heartbeat message" sent by the terminal, according to the pre-defined message format, it accurately extracts each field such as the SN, MAC address, IPv6 address, UDP port, and heartbeat interval. The server uses the extracted SN to search for the corresponding entry in the "terminal information data table". If not found, it indicates a newly connected terminal, and the server immediately creates a new entry, fills in the parsed MAC address, IPv6 address, UDP port, heartbeat interval, etc. information, and records the current time as the initial last heartbeat time. If the corresponding entry already exists, then update the MAC address (to prevent changes in the device's MAC address), IPv6 address (considering dynamic IP address changes), UDP port (if the port changes), heartbeat interval (if the terminal resets), and the last heartbeat time, so as to keep track of the latest status and network-related information of each connected terminal in real time, providing accurate data support for subsequent group management and communication coordination.
[0043] After the terminal's virtual LAN application completes the initialization and information reporting, it sends a "get group code message" to the server with the device SN to join a specific virtual LAN group. After receiving the request, the server searches for the corresponding entry in the "terminal information data table" according to the SN. If the entry already has a group code, it will be returned directly to the terminal; if the group code is not found, the server will randomly generate a group code that has not been used in the entire system from the available group code resource pool maintained internally and return it to the terminal to avoid group code conflicts.
[0044] After the terminal receives the group code returned by the server, it is displayed to the user on the terminal interface. The user can directly confirm the group code to join the group, or manually enter other group codes according to actual needs; multiple terminals join the same virtual LAN with the same group code to achieve mutual communication and collaborative work.
[0045] S120, after the terminal obtains the group code confirmed by the user, it initiates a joining request to the server. The server updates the terminal group information, allocates network address resources to the terminal and generates corresponding related network parameter information. At the same time, the group terminal information is summarized and sent to each terminal. The terminal creates and configures a network card using a virtual network device based on the group terminal information.
[0046] After the terminal user confirms or manually enters the group code, the terminal virtual local area network application combines the device SN and the determined group code into a "request to join the group message" and sends it to the server, indicating the terminal's willingness to join a specific group. After receiving the "request to join the group message", the server finds the corresponding terminal entry in the "terminal information data table" through the SN, updates the group code of the entry to the group code requested by the terminal, and records that the terminal has joined the specified group.
[0047] In order to enable the newly joined terminal to communicate normally within the group, the server calculates the hash through the SN and maps it to the free IP address in the IP address pool maintained for each group, and uses a specific algorithm and detection mechanism to ensure that the allocated IP address is free and not occupied by other terminals. After determining the free IP address, the corresponding subnet mask and broadcast address are generated according to the network configuration rules, and the allocated IP address, subnet mask, and broadcast address are combined into a "terminal network parameter information message" and returned to the terminal.
[0048] To enable all terminals in a group to be aware of the addition of a new member, the server collects information of multiple terminals with the same group code, including the SN, MAC address, IPv6 address, UDP port, etc. of the terminals, organizes and generates a "Group Terminal List Message" and sends it to all terminals in the group to prepare for subsequent data forwarding and communication interaction. After receiving the "Terminal Network Parameter Information Message" returned by the server, the terminal virtual local area network application uses the tun / tap device provided by the operating system and creates a virtual tap-type network card by calling the corresponding system interface to provide a basic network interface for the device to communicate within the virtual local area network.
[0049] After creating the tap-type network card, the application configures the network card in detail according to the IP address, subnet mask, broadcast address assigned by the server in the "Terminal Network Parameter Information Message", and the previously generated MAC address. The IP address determines the network location of the terminal within the virtual local area network, the subnet mask helps determine the network range, the broadcast address supports broadcast communication, and the MAC address ensures the unique identification of the network card in the network. After the configuration is completed, the distributed soft bus of OpenHarmony can use this network card to send and receive messages, realizing the functions of "discovery, networking, and transmission", laying a network foundation for multi-device collaborative communication.
[0050] S130, the terminal constructs a forwarding mapping based on the received group terminal information. During the soft bus data transmission process, it queries the mapping according to the soft bus data destination identifier to forward the data packet, and at the same time verifies and processes the received data packet according to the mapping for legality.
[0051] Among them, after receiving the "Group Terminal List Message" sent by the server, the terminal virtual local area network application extracts key information such as the SN, MAC address, IPv6 address, UDP port, etc. of all terminals in the group according to a specific format parsing rule. The application generates a "Local Forwarding Mapping Table" based on the extracted information of each terminal. The local forwarding mapping table plays a guiding role in the terminal data forwarding process, establishing the correspondence between terminal information and network addresses, facilitating the terminal to quickly find the IPv6 address and UDP port corresponding to the target terminal, improving the accuracy and efficiency of data transmission, and ensuring the orderly progress of communication within the group.
[0052] When the distributed soft bus of OpenHarmony sends a message and it is routed by the Linux kernel network protocol stack to the previously configured tap-type network card, the terminal virtual local area network application receives the "Soft Bus Data Message". Since subsequent data transmission needs to rely on the UDP feature, it encapsulates it into a UDP data packet to meet the real-time requirements of fast communication.
[0053] After encapsulation, the application parses the Ethernet layer 2 header information in the UDP packet, extracts the destination MAC address, and then queries the "local forwarding mapping table" to determine whether there is an entry with the MAC address being the destination MAC address. If a corresponding entry is found in the mapping table, the application sends the UDP packet to the IPv6 address and UDP port recorded in the entry, enabling the data to reach the target terminal accurately; if no matching entry is found, the application uses the broadcast method to send the UDP packet to the IPv6 addresses and UDP ports of all entries in the "local forwarding mapping table" except the local IPv6 address and UDP port, ensuring that the data can be widely spread within the group when the location of the target terminal is unknown and guaranteeing the reliability of communication.
[0054] When the terminal receives a message through the previously listened UDP port, it first obtains the IPv6 address and UDP port information of the message sender to identify the message source. After obtaining the source address information, the application immediately queries the "local forwarding mapping table" to determine whether there is an entry matching the IPv6 address and UDP port. For messages sent from addresses and ports not in the table, the application considers the source unreliable or invalid and directly discards them to ensure the security of the system and the accuracy of data transmission.
[0055] If a matching entry is found in the mapping table, the application takes the received UDP data as a "soft bus data message", further parses its Ethernet layer 2 message, extracts the source MAC address, and compares it with the MAC address of the corresponding entry in the mapping table. If the two are not equal, it indicates that the data source is abnormal and there may be tampering or spoofing, and the message is discarded; if they are equal, it indicates that the data source is reliable, and the application submits the UDP data message to the Linux kernel through a tap-type network card, and after being processed by its network protocol stack, it is submitted to the distributed soft bus to complete the data reception and processing process.
[0056] S140, determine whether the terminal status has changed. If the terminal status changes, the server collects relevant information and updates the terminal status within the group, and each terminal updates its local status information according to the server feedback.
[0057] When the user performs an operation to close the virtual local area network function on the open source HarmonyOS terminal interface, the terminal virtual local area network application combines the device SN and the current group code into a "request to leave the group message" and sends it to the server, informing the server that this terminal wants to leave the current virtual local area network group. After receiving the "request to leave the group message", the server sorts out the information of multiple terminals with the same group code, generates a "group terminal list message" containing the information of all terminals in the group except the terminal about to leave, and sends it to all terminals in the group. After receiving the message, each terminal updates its "local forwarding mapping table" according to the information therein to adjust the communication and data forwarding strategies to ensure stable and efficient communication within the group.
[0058] During the operation of the server, it continuously monitors the "heartbeat packets" sent by each terminal and sets N preset heartbeat cycles for each terminal. If the "heartbeat packet" of a certain terminal is not received within this cycle, the server considers that the terminal has gone offline, that is, left the group, because the heartbeat packet is an important sign for the terminal to maintain an online connection with the server. Once the server determines that a certain terminal has gone offline, the processing flow is similar to that when the terminal actively requests to leave the group. The server sorts out the information of multiple terminals with the same group code to generate a "group terminal list packet" excluding the information of the offline terminal and sends it to all terminals in the group. After receiving the packet, each terminal updates its "local forwarding mapping table" according to the information therein to ensure the accuracy of the communication status and data forwarding information within the group, promptly exclude the information of the offline terminal, and improve the communication efficiency and stability of the virtual local area network.
[0059] Suppose there is such a scenario: An enterprise has multiple office locations distributed in different cities, and enterprise employees use intelligent devices (such as mobile phones, tablets, etc.) with the open-source HarmonyOS system for multi-device collaborative work in daily work. In the traditional distributed soft bus technology of the open-source HarmonyOS system, since device discovery needs to be in the same second-layer local area network, devices in these different physical locations cannot communicate with each other through near-field communication (such as WLAN or Bluetooth), resulting in the inability to effectively carry out the multi-device collaborative function that relies on near-field communication. For example, Employee A located in City A wants to share data and perform collaborative operations with the device used by Employee B located in City B. According to the traditional technology, this cannot be achieved because their devices are not in the same second-layer local area network.
[0060] However, by adopting the method for implementing open-source HarmonyOS soft bus communication based on TAP devices in this application, this problem can be well solved. Employee A and Employee B manually start the virtual local area network application program on their respective open-source HarmonyOS terminals. The application program generates a MAC address using the device unique serial number (SN), obtains a dynamically assigned IPv6 address through cellular network dialing, randomly listens to a UDP port, and establishes a connection with the server using the TCP protocol, and periodically sends a "heartbeat packet" containing key device information. In this way, the server can real-time master the online status and network information of the devices of Employee A and Employee B.
[0061] The devices of Employee A and Employee B both request the server to obtain the group code, and the server assigns the same group code to them (assuming they both join the enterprise office group). Then, the devices of Employee A and Employee B send a group join request to the server. The server updates the group information, assigns unique network parameters such as IP addresses to them, and sends the information of all terminals in the group to them. Their devices create and configure a tap-type network card according to this information to prepare for communication.
[0062] When employee A wants to share a file with employee B, the open source Hongmeng distributed soft bus sends a message, which goes through the Linux kernel network protocol stack to the tap network card. The device encapsulates the message into a UDP data packet, queries the network address of employee B's device according to the "local forwarding mapping table", and accurately sends the data packet to employee B's device. After employee B's device receives the data packet, it passes the legitimacy verification and submits the data to the distributed soft bus for processing, thereby successfully receiving the file.
[0063] If employee A temporarily turns off the virtual LAN function, his device will send a "request to leave the group message" to the server, the server will update the group information and notify other terminals (including employee B's device), employee B's device will update the "local forwarding mapping table" to ensure that subsequent communications are not affected. Or if employee B's device is offline due to network failure or other reasons, the server will detect it by monitoring the "heartbeat message", and will also update the group information and notify employee A's device. Employee A's device will update the "local forwarding mapping table" to avoid sending data to offline devices.
[0064] Through the above operations, the solution of this application overcomes the open source Hongmeng system's dependence on near-field communication, realizes device communication across physical locations, and enables devices used by employees in different cities to effectively transmit data and multi-device collaborate, meeting the company's office needs in cross-regional scenarios and improving work efficiency and device collaboration capabilities.
[0065] A device for implementing open source Hongmeng soft bus communication based on TAP device, including:
[0066] The network identification generation module starts a specific application on the open source Hongmeng terminal. The specific application is used to generate a network identification based on the unique identification information of the device, obtain the corresponding network port listening permission and network address, establish a connection with the server using the transmission control protocol, and periodically send information messages containing key terminal information to the server;
[0067] The server receives the information message, parses the information message, manages the terminal information record according to the terminal identification, responds to the terminal's request for obtaining the group code, and returns the existing group code or generates a new unique group code to the terminal;
[0068] After the terminal obtains the group code confirmed by the user, it initiates a joining request to the server. The server updates the terminal group information, allocates network address resources to the terminal and generates corresponding related network parameter information. At the same time, the group terminal information is summarized and sent to each terminal. The terminal uses the virtual network device to create and configure the network card based on the group terminal information.
[0069] The terminal constructs a forwarding mapping based on the received group terminal information. During the soft bus data transmission process, it queries the mapping according to the destination identifier of the soft bus data to forward the data packet, and at the same time, validates and processes the received data packet according to the mapping for legality.
[0070] The terminal status judgment module is used to judge whether the terminal status has changed. If the terminal status changes, the server collects relevant information and updates the terminal status in the group, and each terminal updates the local status information according to the server feedback.
[0071] The embodiment of the present application also discloses a system for implementing open-source HarmonyOS soft bus communication based on a TAP device, including a processor, and a program of the method for implementing open-source HarmonyOS soft bus communication described in any one of the above is running in the processor.
[0072] The embodiment of the present application also discloses a storage medium storing a program of the method for implementing open-source HarmonyOS soft bus communication described in any one of the above.
[0073] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.
Claims
1. A method for implementing open-source HarmonyOS soft bus communication based on TAP devices, characterized in that, include: Launch a specific application on the open source Hongmeng terminal. The specific application generates a network identifier based on the unique identification information of the device, obtains the corresponding network port listening permission and network address, establishes a connection with the server using the transmission control protocol, and periodically sends information messages containing key terminal information to the server; The server receives the information message, parses the information message, manages the terminal information record according to the terminal identifier, responds to the terminal's request for obtaining the group code, and returns the existing group code or generates a new unique group code to the terminal; After the terminal obtains the group code confirmed by the user, it initiates a joining request to the server. The server updates the terminal group information, allocates network address resources to the terminal and generates corresponding related network parameter information. At the same time, the group terminal information is summarized and sent to each terminal. The terminal uses the virtual network device to create and configure the network card based on the group terminal information. The terminal constructs a forwarding map based on the received group terminal information. During the soft bus data transmission process, the terminal queries the map according to the soft bus data destination identifier to forward the data packet, and at the same time verifies and processes the received data packet based on the map. Determine whether the terminal status has changed. If the terminal status has changed, the server collects relevant information and updates the terminal status in the group. Each terminal updates the local status information based on the server feedback.
2. The method for implementing open-source HarmonyOS soft bus communication based on a TAP device according to claim 1, wherein The method also includes: When the terminal is initialized and associated with the server, the device's unique identification information is the device's unique serial number SN. The MAC address is generated by calculating the hash mapping. The network address is the dynamic IPv6 address assigned by the operator obtained by dialing the cellular network. The key information includes SN, MAC address, IPv6 address, UDP port and heartbeat interval. The virtual LAN application uses the TCP protocol to establish a connection with the server and send a "heartbeat message".
3. The method for implementing open-source HarmonyOS soft bus communication based on a TAP device according to claim 1, wherein, In the server information management and group code processing steps, the server performs the following operations: Maintain a group code usage record list; when receiving the "Get Group Code Message" from the terminal and the corresponding terminal entry has no group code, generate a new group code, and check whether the new group code is in the usage record list during the generation process. If so, regenerate it until a unique and unused group code is obtained and returned to the terminal.
4. The method for implementing open source HarmonyOS soft bus communication based on a TAP device according to claim 1, wherein In the terminal group joining and network adaptation steps, the server performs the following operations: After receiving the "Request to Join Group Message" from the terminal, the SN searches for the corresponding entry in the "Terminal Information Data Table" and updates the group code; When allocating free IP addresses from the IP address pool within the group, a conflict detection algorithm is used to detect each candidate IP address. If it is already occupied, the next one is selected until an unoccupied IP address is found; Generate a "terminal network parameter information message" with the assigned IP address, subnet mask, and broadcast address and return it to the terminal; The information of multiple terminals with the same group code is used to generate a "group terminal list message" and sent to all terminals in the group.
5. The method for implementing open-source HarmonyOS soft bus communication based on TAP device according to claim 1, characterized in that, The terminal does the following: After receiving the "group terminal list message", parse the SN, MAC, IPv6 address, and UDP port information of each terminal, and use the hash table data structure to generate the "local forwarding mapping table"; When the distributed soft bus sends a message to the tap network card via the Linux kernel network protocol stack, it receives the "soft bus data message", encapsulates it into a UDP data packet, parses the Ethernet layer 2 header to obtain the destination MAC address, and queries the "local forwarding mapping table"; If there is a corresponding entry, the UDP data packet is sent to the IPv6 address and UDP port of the entry. If not, it is broadcasted to the addresses and ports of other entries except the local machine. When a message is received through the monitored UDP port, the IPv6 address and UDP port of the other end of the message are obtained, and the "local forwarding mapping table" is queried; If there is no corresponding entry, the message is discarded. If there is, the Ethernet Layer 2 message is parsed to obtain the source MAC address, and compared with the MAC address of the corresponding entry in the mapping table. If they are equal, the UDP data message is submitted to the Linux kernel through the tap network card, which is processed by the network protocol stack and submitted to the distributed soft bus. If they are not equal, the message is discarded.
6. The method for implementing open-source HarmonyOS soft bus communication based on a TAP device according to claim 1, wherein In the terminal status management and system maintenance step, the server and the terminal perform the following operations: When the user turns off the virtual LAN function in the terminal interface, the terminal application sends a "request to leave the group message" to the server with the SN and group code; After receiving the "Request to Leave Group Message", the server sorts the information of the terminals in the group according to the alphabetical order of SN or the time order of joining the group; The server generates a "group terminal list message" that removes the terminal information and sends it to all terminals in the group; After receiving the "group terminal list message", each terminal updates the "local forwarding mapping table"; The server presets N heartbeat cycles to monitor the "heartbeat messages" sent by the terminal. If the "heartbeat message" from a terminal is not received within the cycle, the server executes the above-mentioned operations of sorting the terminal information in the group, generating and sending the "group terminal list message", and each terminal also updates the "local forwarding mapping table".
7. A device for implementing open-source HarmonyOS soft bus communication based on a TAP device, characterized in that include: The network identification generation module starts a specific application on the open source Hongmeng terminal. The specific application is used to generate a network identification based on the unique identification information of the device, obtain the corresponding network port listening permission and network address, establish a connection with the server using the transmission control protocol, and periodically send information messages containing key terminal information to the server; The server receives the information message, parses the information message, manages the terminal information record according to the terminal identifier, responds to the terminal's request for obtaining the group code, and returns the existing group code or generates a new unique group code to the terminal; After the terminal obtains the group code confirmed by the user, it initiates a joining request to the server. The server updates the terminal group information, allocates network address resources to the terminal and generates corresponding related network parameter information. At the same time, the group terminal information is summarized and sent to each terminal. The terminal uses the virtual network device to create and configure the network card based on the group terminal information. The terminal constructs a forwarding mapping based on the received group terminal information. During the soft bus data transmission process, it queries the mapping according to the soft bus data destination identifier for data packet forwarding, and at the same time verifies and processes the legality of the received data packets according to the mapping. The terminal status judgment module is used to judge whether the terminal status has changed. If the terminal status changes, the server collects relevant information and updates the terminal status in the group, and each terminal updates the local status information according to the server feedback.
8. A system for implementing open-source HarmonyOS soft bus communication based on a TAP device, characterized in that, It includes a processor, and a program of the method for implementing open-source HarmonyOS soft bus communication based on the TAP device as described in any one of claims 1-6 runs in the processor.
9. A storage medium, characterized in that, It stores a program of the method for implementing open-source HarmonyOS soft bus communication based on the TAP device as described in any one of claims 1-6.
Citation Information
Patent Citations
Data query method, electronic equipment, server, storage equipment and gateway equipment
CN112804377A
Redundant network communication method and device based on virtual network card and terminal equipment
CN113794618A
Protocol conversion apparatus and method between IPv4 terminal and IPv6 terminal or between application programs using mapping table, and method of generating mapping table of protocol conversion apparatus
US20080080519A1
Emulating Web Browser in a Dedicated Intermediary Box
US20230367833A1
Network identifier mapping method and system, terminal, and identification gateway
WO2019144826A1