A communication method and apparatus
By establishing cross-segment bridges between devices on different network segments and using intermediate devices for packet forwarding, the problem of communication failures caused by device capacity limitations is solved, resulting in a better user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2025-01-24
- Publication Date
- 2026-07-24
AI Technical Summary
Due to device limitations, electronic devices may be unable to establish connections with other devices after a WiFi P2P connection has been established, resulting in a degraded user experience.
By establishing cross-network segment bridges between devices on different network segments and using intermediate devices for data packet forwarding, WiFi P2P communication between devices on different network segments can be achieved.
It supports communication with more devices, improves user experience, and meets user needs.
Smart Images

Figure CN122458232A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communications, and more particularly to a communication method and apparatus. Background Technology
[0002] To better serve users, various electronic devices can exchange data (information), enabling functions such as file sharing, multi-screen collaboration, and screen mirroring. For example, device A and device B can use WiFi Direct (also known as peer-to-peer, P2P) technology for data transmission. Compared to Bluetooth communication, WiFi P2P has a longer communication range and greater bandwidth, offering significant advantages.
[0003] However, if device A and device B have already established a WiFi P2P connection, due to device capability limitations (e.g., network card limit), device A may not be able to establish a WiFi P2P connection with other devices (e.g., device C), affecting the user experience. Summary of the Invention
[0004] This application provides a communication method and apparatus that can support electronic devices (e.g., device A) to communicate with more devices, thereby improving the user experience.
[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:
[0006] A first aspect provides a communication method applied to a communication system including a first electronic device, a second electronic device, and a third electronic device. The method includes: the first electronic device establishing a first WiFi P2P connection with the second electronic device; the second electronic device establishing a second WiFi P2P connection with the third electronic device; the first WiFi P2P connection and the second WiFi P2P connection corresponding to different network segments; the third electronic device receiving a first operation, the first operation being used to initiate a first service to the first electronic device; and the third electronic device sending first request information to the first electronic device, the first request information being used to request establishing a connection with the third electronic device, the first request information including relevant information about the device establishing the WiFi P2P connection with the third electronic device, and establishing a WiFi P2P connection with the third electronic device. The P2P connected devices include a second electronic device; after receiving a first request message, the first electronic device sends a second request message to the second electronic device, which instructs the second electronic device to forward data packets for both the first and third electronic devices; after receiving the second request message, the second electronic device configures forwarding rules, which instruct data packets with a source IP address of the first electronic device to be forwarded to the third electronic device, and / or forward data packets with a source IP address of the third electronic device to the first electronic device; the second electronic device sends a first response message to the first electronic device, which instructs the configuration result of the forwarding rules; after receiving the first response message, the first electronic device configures a first routing rule, which instructs data packets with a destination IP address of the third electronic device to be forwarded to the second electronic device; the first electronic device sends a second response message to the third electronic device, which instructs the first electronic device to establish a connection with the third electronic device through the second electronic device; after receiving the second response message, the third electronic device configures a second routing rule, which instructs data packets with a destination IP address of the first electronic device to be forwarded to the second electronic device.
[0007] Based on the method provided in this application, a first electronic device can establish a connection with a third electronic device through a second electronic device. The second electronic device can forward data packets for both the third and first electronic devices. Wherein, the first and third electronic devices are located on different network segments, and the second electronic device can establish WiFi P2P connections with devices on different network segments, providing network segment forwarding capabilities for these devices, thereby enabling cross-network segment bridging between devices on different network segments. In this application embodiment, cross-network segment bridging refers to devices on different network segments (e.g., the first and second electronic devices) establishing a connection through an intermediate device (e.g., the second electronic device). This supports communication between devices on different network segments using WiFi P2P technology, better meeting user needs and improving user experience.
[0008] In one possible implementation, after receiving the first request information, the first electronic device sends a second request information to the second electronic device. This includes: the first electronic device traversing devices that have established WiFi P2P connections with itself and devices that have established WiFi P2P connections with the third electronic device to determine if a common device exists, including the second electronic device; if a common device exists, it queries whether the network segments corresponding to the WiFi P2P connections established by the common device with both the first and third electronic devices are the same; if the network segments corresponding to the WiFi P2P connections established by the common device with both the first and third electronic devices are different, the first electronic device sends the second request information to the second electronic device. That is, if the first electronic device determines that a common device (e.g., the second electronic device) exists between itself and the third electronic device, and that the first and third electronic devices are on different network segments, the first electronic device can send the second request information to the second electronic device to request the second electronic device to forward data packets for both the third and first electronic devices. This enables communication between devices on different network segments, better meeting user needs and improving user experience.
[0009] In one possible implementation, the second electronic device includes a second application module, a second WiFi link module, and a second network module. Configuring forwarding rules for the second electronic device includes: the second application module sending a source IP and a destination IP to the second WiFi link module, where the source IP is the IP of the first electronic device and the destination IP is the IP of the third electronic device; or, the source IP is the IP of the third electronic device and the destination IP is the IP of the first electronic device; the second WiFi link module querying the first network interface card (NIC) used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the source IP, and the second NIC used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the destination IP; the second WiFi link module generating a forwarding rule configuration instruction, which instructs the second electronic device to receive data packets corresponding to the source IP through the first NIC and to send data packets corresponding to the source IP from the second NIC to the device indicated by the destination IP; the second WiFi link module sending the forwarding rule configuration instruction to the second network module; and the second network module adding the forwarding rule configuration instruction to the forwarding table. In this way, the second electronic device can forward data packets for both the third and first electronic devices, supporting communication between devices on different network segments (the third and first electronic devices), better meeting user needs, and improving user experience.
[0010] In one possible implementation, the second application module stores a first reference count, which indicates the number of services corresponding to a bridge, where a bridge is a connection established between a first electronic device and a third electronic device via a second electronic device. This allows the number of services corresponding to a bridge to be managed based on the first reference count, ensuring normal connection and secure disconnection of the bridge. When the first reference count is 0, the connection between the first and third electronic devices can be disconnected, saving overhead and storage space.
[0011] In one possible implementation, the first electronic device includes a first application module, a first WiFi link module, and a first network module. Configuring the first routing rule for the first electronic device includes: the first application module sending a first network segment and a first forwarding IP to the first WiFi link module. The first network segment is the network segment corresponding to the third electronic device, and the first forwarding IP is the IP corresponding to the first network interface card (NIC) of the second electronic device. The first NIC is the NIC used by the second electronic device to establish a WiFi P2P connection with the first electronic device. The first WiFi link module generates a first routing rule configuration instruction, which instructs data packets whose target IP belongs to the first network segment to be sent to the first NIC of the second electronic device. The first WiFi link module sends the first routing rule configuration instruction to the first network module. The first network module adds the first routing rule configuration instruction to a first routing table. In this way, the first electronic device can send data packets whose target IP belongs to the first network segment (the network segment corresponding to the third electronic device) to the second electronic device, so that the second electronic device can forward the data packets to the third electronic device. This enables communication between devices on different network segments (the third electronic device and the first electronic device), better meeting user needs and improving user experience.
[0012] In one possible implementation, the first application module stores a first reference count, which indicates the number of services corresponding to a bridging connection. A bridging connection refers to a connection established between a first electronic device and a third electronic device via a second electronic device. This allows the number of services corresponding to a bridging connection to be managed based on the first reference count, ensuring both normal connection and secure disconnection of the bridging.
[0013] In one possible implementation, the third electronic device includes a third application module, a third WiFi link module, and a third network module. Configuring the first routing rule for the third electronic device includes: the third application module sending a second network segment and a second forwarding IP corresponding to the routing rule to the third WiFi link module. The second network segment is the network segment corresponding to the first electronic device, and the second forwarding IP is the IP corresponding to the second network interface card (NIC) of the second electronic device. The second NIC is the NIC used by the second electronic device to establish a WiFi P2P connection with the third electronic device. The third WiFi link module generates a second routing rule configuration instruction, which instructs data packets whose target IP belongs to the second network segment to be sent to the second NIC of the second electronic device. The third WiFi link module sends the second routing rule configuration instruction to the third network module. The third network module adds the second routing rule configuration instruction to a second routing table. In this way, the third electronic device can send data packets whose target IP belongs to the second network segment (the network segment corresponding to the first electronic device) to the second electronic device, so that the second electronic device can forward the data packets to the first electronic device. This enables communication between devices on different network segments (the third electronic device and the first electronic device), better meeting user needs and improving user experience.
[0014] In one possible implementation, the third application module stores a first reference count, which indicates the number of services corresponding to a bridging connection. A bridging connection refers to a connection established between the first electronic device and the third electronic device through a second electronic device. This allows the number of services corresponding to a bridging connection to be managed based on the first reference count, ensuring both normal connection and secure disconnection of the bridging.
[0015] In one possible implementation, the method further includes: if the first WiFi P2P connection is disconnected, or the second WiFi P2P connection is disconnected, or the connection between the first electronic device and the third electronic device is disconnected, the second electronic device deletes the forwarding rule. This eliminates the need to maintain the forwarding rule, saving overhead and storage space, and improving the performance of the electronic device.
[0016] In one possible implementation, the method further includes: the second electronic device deleting the first reference count. This eliminates the need to maintain the first reference count, saving overhead and storage space, and improving the performance of the electronic device.
[0017] Secondly, a communication method is provided, applied to a first electronic device, the method comprising: establishing a WiFi P2P connection between the first electronic device and a second electronic device; receiving first request information from a third electronic device, the first request information being used to request establishing a connection with the third electronic device, the first request information including relevant information of the device establishing the WiFi P2P connection with the first electronic device, the device establishing the WiFi P2P connection with the first electronic device including the second electronic device; if the network segment corresponding to the first electronic device is different from the network segment corresponding to the third electronic device, the first electronic device sends second request information to the second electronic device, the second request information being used to instruct the second electronic device to forward data packets for both the third electronic device and the first electronic device; receiving first response information from the second electronic device, the first response information being used to indicate the configuration result of a forwarding rule, the forwarding rule being used to instruct data packets with a source IP of the first electronic device to be forwarded to the third electronic device, and / or, to forward data packets with a source IP of the third electronic device to the first electronic device; configuring a first routing rule, the first routing rule being used to instruct data packets with a destination IP of the third electronic device to be sent to the second electronic device; and sending second response information to the third electronic device, the second response information being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device.
[0018] Based on the method provided in this application, a first electronic device can send a second request message to a second electronic device to request the second electronic device to forward data packets for both the third and first electronic devices. This enables communication between devices on different network segments, better meeting user needs and improving user experience.
[0019] Thirdly, a communication method is provided for a second electronic device. The method includes: establishing a first WiFi P2P connection with a first electronic device and a second WiFi P2P connection with a third electronic device, wherein the first and second WiFi P2P connections correspond to different network segments; receiving second request information from the third electronic device, the second request information instructing the second electronic device to forward data packets for both the first and third electronic devices; configuring forwarding rules for the second electronic device to instruct data packets with a source IP address of the first electronic device to be forwarded to the third electronic device, and / or to forward data packets with a source IP address of the third electronic device to the first electronic device. Based on the method provided in this application, the second electronic device can forward data packets for both the third and first electronic devices. This enables communication between devices on different network segments, better meeting user needs and improving user experience.
[0020] Fourthly, a communication method is provided for a third electronic device. The method includes: establishing a WiFi P2P connection between the third electronic device and a second electronic device; the third electronic device receiving a first operation, the first operation being used to initiate a first service to the first electronic device; the third electronic device sending first request information to the first electronic device, the first request information being used to request establishing a connection with the third electronic device, the first request information including relevant information of the device establishing the WiFi P2P connection with the first electronic device, the device establishing the WiFi P2P connection with the first electronic device including the second electronic device; the third electronic device receiving second response information from the first electronic device, the second response information being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device, the network segment corresponding to the first electronic device being different from the network segment corresponding to the third electronic device; and the third electronic device configuring a second routing rule, the second routing rule being used to instruct data packets with a destination IP address of the first electronic device to be sent to the second electronic device. Based on the method provided in this application embodiment, the third electronic device can send first request information to the first electronic device to request establishing a connection with the third electronic device. The third electronic device can receive second response information from the first electronic device, the second response information being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device. Subsequently, the third electronic device can send data packets whose target IP belongs to the second network segment (the network segment corresponding to the first electronic device) to the second electronic device, so that the second electronic device can forward the data packets to the first electronic device. This enables communication between devices on different network segments (the third electronic device and the first electronic device), which can better meet user needs and improve user experience.
[0021] Fifthly, a communication system is provided, comprising a first electronic device, a second electronic device, and a third electronic device, wherein the first electronic device establishes a first WiFi P2P connection with the second electronic device, and the second electronic device establishes a second WiFi P2P connection with the third electronic device, wherein the first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments, and each electronic device in the communication system is used to perform a method as described in the first aspect and any possible design thereof.
[0022] In a sixth aspect, a first electronic device is provided, comprising: a wireless communication module, a memory, and one or more processors; the wireless communication module, the memory, and the processors are coupled; wherein the memory is used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed by the processor, the first electronic device performs the method as described in the second aspect.
[0023] In a seventh aspect, a second electronic device is provided, comprising: a wireless communication module, a memory, and one or more processors; the wireless communication module, the memory, and the processor are coupled; wherein the memory is used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed by the processor, the second electronic device performs the method as described in the third aspect.
[0024] Eighthly, a third electronic device is provided, comprising: a wireless communication module, a memory, and one or more processors; the wireless communication module, the memory, and the processor are coupled; wherein the memory is used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed by the processor, the third electronic device performs the method as described in the fourth aspect.
[0025] Ninthly, this application provides a chip system including one or more interface circuits and one or more processors. The interface circuits and processors are interconnected via lines. The chip system described above can be applied to electronic devices including communication modules and memory. The interface circuits are used to receive signals from the memory of the electronic device and send the received signals to the processor, the signals including computer instructions stored in the memory. When the processor executes the computer instructions, the electronic device (a first electronic device, a second electronic device, or a third electronic device) can perform methods as described in the second to fourth aspects and any possible design embodiments thereof.
[0026] Tenthly, this application provides a computer-readable storage medium including computer instructions. When the computer instructions are executed on an electronic device (a first electronic device, a second electronic device, or a third electronic device), they cause the electronic device to perform a method as described in the first aspect or the second aspect and any possible design thereof.
[0027] In the eleventh aspect, this application provides a computer program product that, when run on a computer, causes the computer to perform a method as described in the second to fourth aspects and any possible design of the present application.
[0028] Understandably, the beneficial effects achieved by the system of the fifth aspect, the first electronic device of the sixth aspect, the second electronic device of the seventh aspect, the third electronic device of the eighth aspect, the chip system of the ninth aspect, the computer-readable storage medium of the tenth aspect, and the computer program product of the eleventh aspect can be referred to the beneficial effects of the first to fourth aspects and any possible design embodiments thereof, which will not be repeated here. Attached Figure Description
[0029] Figure 1AA schematic diagram of device connection provided for an embodiment of this application;
[0030] Figure 1B This is a diagram illustrating a business failure scenario in related technologies.
[0031] Figure 1C This is a diagram illustrating another business failure scenario in related technologies;
[0032] Figure 1D This is yet another device connection diagram provided in an embodiment of this application;
[0033] Figure 1E This is yet another device connection diagram provided in an embodiment of this application;
[0034] Figure 2A A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0035] Figure 2B A schematic diagram of the software architecture of an electronic device provided in an embodiment of this application;
[0036] Figure 3A A flowchart is provided for an embodiment of this application;
[0037] Figure 3B A schematic diagram illustrating a connection method between devices provided in an embodiment of this application;
[0038] Figure 4A This application provides a schematic diagram of establishing a WiFi P2P connection according to an embodiment of the present application.
[0039] Figure 4B This is a schematic diagram illustrating another method for establishing a WiFi P2P connection, as provided in an embodiment of this application.
[0040] Figure 5A A schematic diagram provided for an embodiment of this application;
[0041] Figure 5B This is yet another display schematic diagram provided for an embodiment of this application;
[0042] Figure 6 A schematic diagram of a negotiation channel and an auxiliary channel provided for embodiments of this application;
[0043] Figure 7A A schematic diagram illustrating the establishment of a bridge according to an embodiment of this application;
[0044] Figure 7B A schematic diagram illustrating the disconnection of the bridging provided in an embodiment of this application;
[0045] Figure 8This is a schematic diagram illustrating a connection method determination method provided in an embodiment of this application;
[0046] Figure 9 A schematic diagram of leaf nodes and intermediate nodes provided in an embodiment of this application;
[0047] Figure 10 This is a schematic diagram of a chip system provided in an embodiment of this application. Detailed Implementation
[0048] To ensure clarity and conciseness in the description of the following embodiments, a brief introduction to the relevant concepts or technologies is given first:
[0049] WiFi P2P is a peer-to-peer connection technology that allows direct TCP / IP connections between any two devices (e.g., STAs) without the need for an access point (AP). One device acts as an access point (AP) and can be called the group owner (GO), while the other device is called a group client (GC). GCs can connect to the GO. In a P2P group, there is one GO and one or more GCs. Each GC can connect to a GO, meaning a GO can provide services to one or more GCs.
[0050] In smart living scenarios (such as smart office, sports and health, smart home, smart travel, and audio-visual entertainment), various electronic devices (such as mobile phones, tablets, computers, TVs, cameras, and smart cars) bring users a lot of convenience and unprecedented experiences. These electronic devices can transmit data (interact) with each other to enable functions such as file sharing, multi-screen collaboration, and screen mirroring, thereby better serving users.
[0051] Currently, electronic devices can use WiFi P2P technology for data transmission. For example, ... Figure 1A As shown, device A and device B can use WiFi P2P technology for data transmission. However, even if device A and device B have already established a WiFi P2P connection, due to device capability limitations (e.g., limited number of network cards, P2P role limitations (e.g., can only act as a GO or only as a GC)), device A may not be able to establish a WiFi P2P connection with other devices (e.g., device C), leading to service failure and impacting user experience. Devices A, B, and C can be in the same trust ring, or any two of them can be in the same trust ring. The following sections will illustrate this with two specific scenarios.
[0052] Scenario 1: such as Figure 1B As shown, after a foldable phone establishes a WiFi P2P connection with a candybar phone, it can perform multi-device usage. However, the foldable phone can no longer share its network with a PC. This is because the foldable phone only has one P2P capability (i.e., only one network card, which can only establish a WiFi P2P connection with one device directly), and due to the P2P role limitations of the PC's main chip (e.g., it can only act as a GO), the foldable phone and PC cannot establish a WiFi P2P connection that reuses the GO (foldable phone as GO, PC as GC). Therefore, if the foldable phone wants to share its network with the PC, it needs to disconnect from the multi-device usage service with the candybar phone and then re-establish a P2P network with the PC. This will cause the multi-device usage service to fail, affecting the user experience.
[0053] Scenario 2: such as Figure 1C As shown, after a foldable phone and tablet establish a WiFi P2P connection, call continuation services can be provided, such as connecting a call from the tablet to the foldable phone. However, in this scenario, the foldable phone cannot share keyboard and mouse with a PC (e.g., dragging files on the phone using the PC's mouse). This is because the foldable phone only has one P2P capability (i.e., only one network card, allowing direct WiFi P2P connection to only one device), and due to the P2P role limitations of the PC's main chip (e.g., it can only act as a GO), the foldable phone and PC cannot establish a WiFi P2P connection that reuses the GO (foldable phone as GO, PC as GC). Therefore, if the foldable phone wants to share keyboard and mouse with the PC, it needs to disconnect the call continuation service with the tablet and then re-establish a P2P network with the PC. This will cause the service (call continuation service) to fail, impacting the user experience.
[0054] In one possible implementation, multiple devices (e.g., mobile phone A and mobile phone C) located in the same network segment can be bridged through an intermediate device (e.g., tablet B).
[0055] Tablet B can support dual-path P2P capability (e.g., including at least two network cards, which can establish WiFi P2P connections with at least two devices respectively), and at least one of Device A and Device C supports single-path P2P capability (i.e., only one network card, which can only establish WiFi P2P connections with one device directly). Device A, Device B and Device C are located on different network segments.
[0056] For example, such as Figure 1DAs shown, network card 0 (P2P0) of mobile phone A can establish WiFi P2P connection 1 with network card 0 (P2P0) of tablet B, and mobile phone A can act as GO, while tablet B can act as GC. Network card 1 (P2P1) of tablet B can establish WiFi P2P connection 2 with network card 0 (P2P0) of mobile phone C, and mobile phone C can act as GC, while tablet B can act as GO. The network segment corresponding to WiFi P2P connection 1 is the same as the network segment corresponding to WiFi P2P connection 2, for example, it can be the 49 network segment. That is, mobile phone A, tablet B, and mobile phone C are on the same network segment. In this case, mobile phone A can establish a same-network-segment bridge with mobile phone C.
[0057] However, it is impossible to establish a bridge on the same network segment for multiple devices located on different network segments. For example, such as... Figure 1E As shown in (a), network interface card 0 (P2P0) of mobile phone A can establish WiFi P2P connection 1 with network interface card 0 (P2P0) of tablet computer B, and mobile phone A can act as GO, while tablet computer B can act as GC. Network interface card 1 (P2P1) of tablet computer B can establish WiFi P2P connection 2 with network interface card 0 (P2P0) of mobile phone C, and mobile phone C can act as GC, while tablet computer B can act as GO. The network segment corresponding to WiFi P2P connection 1 is different from the network segment corresponding to WiFi P2P connection 2. For example, the network segment corresponding to WiFi P2P connection 1 can be segment 49, while the network segment corresponding to WiFi P2P connection 2 can be a non-49 network segment (e.g., segment 50). That is, device A, device B, and device C are on different network segments. In this case, mobile phone C and mobile phone A cannot establish a bridge on the same network segment.
[0058] like Figure 1E As shown in (b), mobile phone A's network card 0 (P2P0) can establish WiFi P2P connection 1 with tablet B's network card 0 (P2P0), with mobile phone A acting as the GO and tablet B as the GC. Tablet B's network card 0 (P2P1) can establish WiFi P2P connection 2 with mobile phone C's network card 0 (P2P0), with mobile phone C acting as the GO and tablet B as the GC. The network segment corresponding to WiFi P2P connection 1 is different from the network segment corresponding to WiFi P2P connection 2. For example, the network segment corresponding to WiFi P2P connection 1 can be segment 49, while the network segment corresponding to WiFi P2P connection 2 can be a non-49 segment (e.g., segment 50). In this case, mobile phone C and mobile phone A cannot establish a bridge on the same network segment.
[0059] like Figure 1EAs shown in (c), mobile phone A's network card 0 (P2P0) can establish WiFi P2P connection 1 with tablet B's network card 0 (P2P0), with mobile phone A acting as the GC and tablet B as the GO. Furthermore, tablet B's network card 0 (P2P1) can establish WiFi P2P connection 2 with mobile phone C's network card 0 (P2P0), with mobile phone C acting as the GC and tablet B as the GO. The network segment corresponding to WiFi P2P connection 1 is different from that corresponding to WiFi P2P connection 2. For example, the network segment corresponding to WiFi P2P connection 1 could be segment 49, while the network segment corresponding to WiFi P2P connection 2 could be a non-49 segment (e.g., segment 50). In this case, mobile phone C and mobile phone A cannot establish a bridge on the same network segment.
[0060] like Figure 1E As shown in (d), network card 0 (P2P0) of mobile phone A can establish WiFi P2P connection 1 with network card 0 (P2P0) of tablet B, and mobile phone A can act as GC and tablet B can act as GO. Furthermore, network card 0 (P2P1) of tablet B can establish WiFi P2P connection 2 with network card 0 (P2P0) of mobile phone C, and mobile phone C can act as GO and tablet B can act as GC. The network segment corresponding to WiFi P2P connection 1 is different from the network segment corresponding to WiFi P2P connection 2. For example, the network segment corresponding to WiFi P2P connection 1 can be the 49 network segment, while the network segment corresponding to WiFi P2P connection 2 can be a non-49 network segment (e.g., the 50 network segment). In this case, mobile phone C and mobile phone A cannot establish a bridge on the same network segment.
[0061] This application provides a WiFi P2P connection method, which enables electronic devices in different network segments to establish cross-network segment bridging, supporting communication between devices in different network segments using WiFi P2P technology, thus better meeting user needs and improving user experience.
[0062] The method provided in this application can be applied to a first electronic device, a second electronic device, and a third electronic device. The first, second, or third electronic device can be, for example, a mobile phone (such as a candybar phone or a foldable phone), a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, as well as cellular phones, personal digital assistants (PDAs), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, in-vehicle devices, smart home devices, and / or smart city devices. This application does not impose any special limitations on the specific type of electronic device.
[0063] The following description uses the first electronic device, the second electronic device, and the third electronic device as examples to illustrate the hardware structure of electronic device 100. Figure 2A A schematic diagram of the hardware structure of the electronic device 100 is shown.
[0064] Electronic device 100 may include processor 110, external memory interface 120, internal memory 121, Universal Serial Bus (USB) interface 130, charging management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, camera 193, display screen 194, and Subscriber Identification Module (SIM) card interface 195, etc.
[0065] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0066] The processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). These different processing units may be independent devices or integrated into one or more processors.
[0067] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0068] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0069] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0070] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be reused to improve antenna utilization.
[0071] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low-noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1.
[0072] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including Wireless Local Area Networks (WLAN) (such as Wi-Fi), Bluetooth (BT), Global Navigation Satellite System (GNSS), Frequency Modulation (FM), NFC, and Infrared (IR). The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signal, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0073] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, so that electronic device 100 can communicate with networks and other devices through wireless communication technology.
[0074] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0075] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 may include one or N display screens 194, where N is a positive integer greater than 1.
[0076] In this embodiment of the application, the display screen can be a touch screen, which can receive user operations (e.g., first operation, second operation, etc.) to realize human-computer interaction.
[0077] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU performs mathematical and geometric calculations and is used for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0078] Electronic device 100 can acquire images through ISP, camera 193, video codec, GPU, display screen 194, and application processor.
[0079] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This embodiment of the invention uses the layered architecture of the Android system as an example to illustrate the software structure of electronic device 100. The layered architecture divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through interfaces.
[0080] In some embodiments, the technical architecture of the electronic device 100 includes: an application layer (application layer), a framework layer (application framework layer), a kernel layer, and a hardware layer. It should be understood that the embodiments in this application only describe some layers and components related to the solution in this application. In actual applications, the electronic device 100 may also include other layers and components, and this application does not impose specific limitations.
[0081] like Figure 2B As shown, the application layer can include smart interconnection applications and MagicLink application modules.
[0082] Among them, the smart interconnection application can be used to receive user operations (such as screen sharing initiated by the user) and call the MagicLink application module based on the user operations.
[0083] The MagicLink application module is responsible for managing business scenarios and networking between multiple devices, as well as managing the bridging and WiFi P2P connections corresponding to the business.
[0084] As an example, the MagicLink application module in the application layer may include a P2P connection control module, a P2P direct connection module, a P2P bridging module, a P2P dynamic networking module, a security authentication module, a P2P connection counting module, and a P2P connection information management module.
[0085] The P2P connection control module receives a connection call from the smart interconnection application (which is triggered by a screen sharing operation initiated by the user on the local machine (e.g., tablet B) to the destination device (e.g., mobile phone C). It can determine the connection method between the local machine and the destination device based on the local machine's capability information (e.g., the local machine's P2P role and idle network card information) and the destination device's capability information (e.g., the destination device's idle network card information).
[0086] In some embodiments, when the P2P role of the local device (e.g., tablet B) is GO and the local device has no idle network card, and the destination device (e.g., mobile phone C) has an idle network card, the P2P connection control module can call the P2P direct connection module, and the P2P direct connection module can reuse the GO to establish a WiFi P2P connection with the mobile phone C.
[0087] In other embodiments, when the local device (e.g., tablet B) has the P2P role of GC and both the local device and the destination device (e.g., mobile phone C) have idle network cards, the P2P connection control module can call the P2P direct connection module. The P2P direct connection module can establish a WiFi P2P connection with the destination device (e.g., mobile phone C) based on the local device's idle network card (e.g., WiFi network card 2).
[0088] In some other embodiments, when the local device (e.g., tablet B) has a P2P role of GC and the local device does not have a free network card, while the destination device (e.g., mobile phone C) has a free network card, the P2P connection control module can call the P2P bridging module, the P2P bridging module can call the P2P direct connection module, and the P2P direct connection module can establish a WiFi P2P connection on which the P2P bridging module depends.
[0089] In some other embodiments, the local device (e.g., tablet B) has the P2P role of GC, and neither the local device nor the destination device (e.g., mobile phone C) has a free network card. The P2P connection control module can call the P2P dynamic networking module, which can call the P2P direct connection module or the P2P bridging module to perform dynamic networking preemption (i.e., first disconnect the existing WiFi P2P connection established by the local device to release the occupied network card, and then establish a WiFi P2P connection with the destination device based on the released network card).
[0090] The security authentication module can be used for device security authentication and key exchange.
[0091] The P2P connection information management module is used to store and manage connection information for bridging and / or WiFi P2P connections corresponding to services. This connection information may include the identifiers of members in the WiFi P2P group, the network card name (the identifier of the network card that establishes the bridging and / or WiFi P2P connection), and the P2P role of the device (phone A stores the P2P role of phone A, and tablet B stores the P2P role of tablet B), etc.
[0092] The P2P connection counting module is used to store and manage the reference counts (e.g., ref) of the bridging and / or WiFi P2P connections corresponding to the service. For example, ref = 1 indicates that the service reference count is 1, that is, there is a service (e.g., screen sharing service) referencing WiFi P2P connection 1, which means that the service (e.g., screen sharing service) interacts with the peer device (e.g., tablet B) based on WiFi P2P connection 1.
[0093] The framework layer can include a WiFi link module and an Android WiFi management module.
[0094] The Android WiFi management module is a native Android module used to manage the establishment and disconnection of WiFi P2P connections between the primary network interface card (NIC) of an electronic device (e.g., WiFi NIC 1) and the peer device. The process of establishing a WiFi P2P connection includes activating (raising / lowering) WiFi NIC 1, setting its frequency, service set identifier (SSID), and password, and then establishing a WiFi P2P connection with the peer device using the SSID and password. Subsequently, the MagicLink application module can establish an encrypted TCP channel using IP and TCP ports based on the established WiFi P2P connection.
[0095] The WiFi link module can manage the WiFi P2P physical link established between two devices.
[0096] The WiFi link module can also be used to manage extended network cards (e.g., WiFi network card 2) of electronic devices. These extended WiFi network cards may include more network cards, such as WiFi network card 3, WiFi network card 4, etc., and this application does not limit the scope of such extensions.
[0097] The WiFi link module can also be used to collect WiFi capability information (including the number of WiFi network cards, available WiFi channels, etc.) from WiFi drivers (e.g., the drivers for WiFi network card 1 and WiFi network card 2). The WiFi link module is compatible with the WiFi capabilities of different hardware platforms (e.g., WiFi chips or WiFi network cards).
[0098] The WiFi link module may include a WiFi service module. This WiFi service module can obtain WiFi capability information from the WiFi driver and, based on this information, determine WiFi P2P connection configuration information. The WiFi service module is also used to establish a WiFi P2P physical link with the peer device by invoking the WiFi protocol stack, according to instructions from the P2P direct connection module.
[0099] In some implementations, the WiFi protocol stack can be integrated into the WiFi network card. The WiFi protocol stack can be a purely software module or a module combining software and hardware; this application does not specifically limit this.
[0100] The kernel layer is the layer between hardware and software. The kernel layer can contain WiFi drivers. WiFi drivers are the driver layer for WiFi network cards (e.g., WiFi card 1 and WiFi card 2), and are primarily responsible for interacting with the hardware. For example, a WiFi driver can include drivers for WiFi card 1 and WiFi card 2. The driver for WiFi card 1 is used to interact with WiFi card 1, and the driver for WiFi card 2 is used to interact with WiFi card 2.
[0101] In this embodiment, the kernel layer may further include a Netd (Network Daemon) module, which is responsible for network management and control. For example, the Netd module can be used to add / delete forwarding rules and / or routing rules.
[0102] In addition, the kernel layer may also include display drivers, camera drivers, audio drivers, sensor drivers, etc. (not shown in the figure).
[0103] The hardware layer may include a first network interface card (e.g., WiFi network interface card 1) and an extended network interface card (e.g., WiFi network interface card 2).
[0104] In this embodiment, WiFi P2P connections can be managed on a per-WiFi network card basis. Compared to managing WiFi P2P connections on a per-device basis, managing WiFi P2P connections on a per-WiFi network card basis can be compatible with more WiFi network cards on devices, and the management of WiFi P2P connections is more flexible and efficient.
[0105] This application provides a layered bridging scheme for WiFi service-based connectivity. The local device's MagicLink connection, linking the application layer and WiFi link layer, can negotiate with the peer device based on the WiFi capabilities of both devices (e.g., the number of available network cards, P2P roles, etc.). Different connection schemes are adopted according to different negotiation results. For example, when the local device (e.g., tablet B) has insufficient network card resources (e.g., no available network cards), a connection can be established with the destination device (e.g., mobile phone C) through bridging, or a WiFi P2P connection can be established with the destination device through multiplexing GO. This expands the connection methods between the local device and the destination device, enabling communication between the local device and more devices using WiFi P2P technology, better meeting user needs and improving user experience.
[0106] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. In the description of this application, unless otherwise stated, "at least one" refers to one or more, and "more than one" refers to two or more. Furthermore, to facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first," "second," etc., are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and that "first," "second," etc., do not necessarily imply differences.
[0107] For ease of understanding, the communication method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0108] like Figure 3A As shown, this application provides a communication method, including:
[0109] 301a. The first electronic device establishes a first WiFi P2P connection with the second electronic device, and the second electronic device establishes a second WiFi P2P connection with the third electronic device. The first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments.
[0110] 301b. The third electronic device receives the first operation, which is used to initiate a first service to the first electronic device.
[0111] 302. The third electronic device sends a first request message to the first electronic device. The first request message is used to request the establishment of a connection with the third electronic device. The first request message includes information about the device establishing the WiFi P2P connection with the third electronic device, and the device establishing the WiFi P2P connection with the third electronic device includes the second electronic device.
[0112] 303. After receiving the first request information, the first electronic device sends a second request information to the second electronic device. The second request information is used to instruct the second electronic device to forward data packets for the first electronic device and the third electronic device.
[0113] In some embodiments, after receiving the first request information, the first electronic device can traverse the devices that have established WiFi P2P connections with the first electronic device and the devices that have established WiFi P2P connections with the third electronic device to determine whether there is a common device, including the second electronic device; if there is a common device, it queries whether the network segments corresponding to the WiFi P2P connections established by the common device with the first electronic device and the third electronic device are the same; if the network segments corresponding to the WiFi P2P connections established by the common device with the first electronic device and the third electronic device are different, the first electronic device sends a second request information to the second electronic device.
[0114] 304. After receiving the second request information, the second electronic device configures forwarding rules. The forwarding rules are used to instruct data packets whose source IP is the IP of the first electronic device to be forwarded to the third electronic device, and / or to forward data packets whose source IP is the IP of the third electronic device to the first electronic device.
[0115] In some embodiments, the second electronic device includes a second application module, a second WiFi link module, and a second network module. Configuring forwarding rules for the second electronic device includes: the second application module sending a source IP and a destination IP to the second WiFi link module, where the source IP is the IP of the first electronic device and the destination IP is the IP of the third electronic device; or, the source IP is the IP of the third electronic device and the destination IP is the IP of the first electronic device; the second WiFi link module querying the first network interface card (NIC) used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the source IP, and the second NIC used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the destination IP; the second WiFi link module generating a forwarding rule configuration instruction, which instructs the second electronic device to receive data packets corresponding to the source IP through the first NIC and to send data packets corresponding to the source IP from the second NIC to the device indicated by the destination IP; the second WiFi link module sending the forwarding rule configuration instruction to the second network module; and the second network module adding the forwarding rule configuration instruction to the forwarding table.
[0116] In some embodiments, the second application module may also store a first reference count, which is used to indicate the number of services corresponding to the bridging, where bridging is a connection established between the first electronic device and the third electronic device through the second electronic device.
[0117] 305. The second electronic device sends a first response message to the first electronic device. The first response message is used to indicate the configuration result of the forwarding rule.
[0118] The configuration result of the forwarding rule can be success, meaning that the second electronic device agrees to forward data packets for the third electronic device and the first electronic device.
[0119] 306. After receiving the first response information, the first electronic device configures a first routing rule. The first routing rule is used to instruct data packets whose destination IP is the IP of the third electronic device to be forwarded to the second electronic device.
[0120] In some embodiments, the first electronic device includes a first application module, a first WiFi link module, and a first network module. Configuring a first routing rule for the first electronic device includes: the first application module sending a first network segment and a first forwarding IP to the first WiFi link module; the first network segment being the network segment corresponding to the third electronic device; the first forwarding IP being the IP corresponding to the first network interface card (NIC) of the second electronic device; the first NIC being the NIC used by the second electronic device to establish a WiFi P2P connection with the first electronic device; the first WiFi link module generating a first routing rule configuration instruction, which instructs data packets whose target IP belongs to the first network segment to be sent to the first NIC of the second electronic device; the first WiFi link module sending the first routing rule configuration instruction to the first network module; and the first network module adding the first routing rule configuration instruction to a first routing table.
[0121] In some embodiments, the first application module may also store a first reference count, which is used to indicate the number of services corresponding to the bridging connection. The bridging connection refers to the connection established between the first electronic device and the third electronic device through the second electronic device.
[0122] 307. The first electronic device sends a second response message to the third electronic device, the second response message being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device.
[0123] That is, the first electronic device allows the establishment of a connection with the third electronic device through the second electronic device. The second response information can also be used to indicate the configuration result of the first routing rule.
[0124] 308. After receiving the second response information, the third electronic device configures a second routing rule. The second routing rule is used to instruct data packets whose destination IP is the IP of the first electronic device to be forwarded to the second electronic device.
[0125] In some embodiments, the third application module sends the second network segment and the second forwarding IP corresponding to the routing rule to the third WiFi link module. The second network segment is the network segment corresponding to the first electronic device, and the second forwarding IP is the IP corresponding to the second network card of the second electronic device. The second network card is the network card that establishes a WiFi P2P connection between the second electronic device and the third electronic device. The third WiFi link module generates a second routing rule configuration instruction, which is used to instruct data packets whose target IP belongs to the second network segment to be sent to the second network card of the second electronic device. The third WiFi link module sends the second routing rule configuration instruction to the third network module. The third network module adds the second routing rule configuration instruction to the second routing table.
[0126] In some embodiments, the third application module may also store a first reference count, which is used to indicate the number of services corresponding to the bridging connection. The bridging connection refers to the connection established between the first electronic device and the third electronic device through the second electronic device.
[0127] In some embodiments, if the first WiFi P2P connection is disconnected, or the second WiFi P2P connection is disconnected, or the connection between the first electronic device and the third electronic device is disconnected, the second electronic device deletes the forwarding rule. Furthermore, the second electronic device may also delete the first reference count.
[0128] Based on the method provided in this application, a first electronic device can establish a connection with a third electronic device through a second electronic device. The second electronic device can forward data packets for both the third and first electronic devices. Wherein, the first and third electronic devices are located on different network segments, and the second electronic device can establish WiFi P2P connections with devices on different network segments, providing network segment forwarding capabilities for these devices, thereby enabling cross-network segment bridging between devices on different network segments. In this application embodiment, cross-network segment bridging refers to devices on different network segments (e.g., the first and second electronic devices) establishing a connection through an intermediate device (e.g., the second electronic device). This supports communication between devices on different network segments using WiFi P2P technology, better meeting user needs and improving user experience.
[0129] For example, such as Figure 3BAs shown, a first electronic device (e.g., mobile phone A) can establish a first WiFi P2P connection with a second electronic device (e.g., tablet B). The first electronic device can establish this connection with the second electronic device's network card P2P0 based on its own network card P2P0. The IP address of the first electronic device's network card P2P0 is 192.168.49.1, and the IP address of the second electronic device's network card P2P0 is 192.168.49.101. The second electronic device can establish a second WiFi P2P connection with a third electronic device (e.g., mobile phone C). The second electronic device can establish this connection with the third electronic device's network card P2P0 based on its own network card P2P1. The IP address of the second electronic device's network card P2P1 is 192.168.50.1, and the IP address of the third electronic device's network card P2P0 is 192.168.50.75.
[0130] The first and second WiFi P2P connections correspond to different network segments. In other words, the first and third electronic devices are on different network segments (the first electronic device can be on network segment 49, and the third electronic device can be on network segment 50). The second electronic device has two network cards, enabling it to establish WiFi P2P connections with devices on different network segments. It can provide network segment forwarding capabilities for devices on different network segments, thereby enabling cross-network segment bridging of devices on different network segments, better meeting user needs and improving user experience.
[0131] The following is combined Figures 4A-9The corresponding embodiments exemplify the detailed process of establishing WiFi P2P connections between electronic devices (e.g., between a first electronic device and a second electronic device, or between a second electronic device and a third electronic device), and performing cross-network segment bridging between electronic devices (e.g., between a first electronic device and a third electronic device). The first electronic device includes a first application module, a first WiFi link module, a first network module, and a first application. The second electronic device includes a second application module, a second WiFi link module, and a second network module. The third electronic device includes a third application module, a third WiFi link module, and a third network module. Taking mobile phone A as the first electronic device, tablet B as the second electronic device, and mobile phone C as the third electronic device, mobile phone A's MagicLink application module can be the first application module, mobile phone A's Netd module can be the first network module, and mobile phone A's WiFi link module can be the first WiFi link module; tablet B's MagicLink application module can be the second application module, tablet B's Netd module can be the second network module, and tablet B's WiFi link module can be the second WiFi link module; mobile phone C's MagicLink application module can be the third application module, mobile phone C's Netd module can be the third network module, and mobile phone C's WiFi link module can be the third WiFi link module. Mobile phone A, tablet B, and mobile phone C can install a first application, which could be a smart interconnection application. The first request information can be a P2P bridging request, the second request information can be a routing configuration request, the first response information can be a routing configuration response, and the second response information can be a P2P bridging response.
[0132] like Figure 4A As shown, this application embodiment provides a WiFi P2P connection method, taking the establishment of a WiFi P2P connection (first WiFi P2P connection) between mobile phone A (second electronic device) and tablet computer B (first electronic device) as an example, including:
[0133] 401. Turn on WiFi and Bluetooth on mobile phone A and tablet B.
[0134] Taking mobile phone A as an example, in response to the user from Figure 5A By swiping down from the top of interface 501, phone A can display interface 502. Interface 502 includes a WLAN switch 5021 and a Bluetooth switch 5022. Phone A can receive user input to switches 5021 and 5022 (e.g., tapping) to enable WiFi and Bluetooth.
[0135] For example, in response to user requests Figure 5AWhen the user clicks the application icon 5013 in the settings interface 501, phone A can display interface 503, which includes WLAN settings 5031 and Bluetooth settings 5032. Phone A can receive user actions on settings 5031 and 5032 to enable WiFi and Bluetooth.
[0136] The process of enabling WiFi and Bluetooth on tablet B can be referred to the above description, and will not be repeated in this application.
[0137] 402. The MagicLink application module of mobile phone A and the MagicLink application module of tablet B discover the other device via Bluetooth broadcast.
[0138] After Bluetooth is turned on on phone A, phone A can send Bluetooth broadcasts; similarly, after Bluetooth is turned on on tablet B, tablet B can send Bluetooth broadcasts. Phone A's MagicLink application module can discover tablet B based on the Bluetooth broadcasts sent by tablet B. Tablet B's MagicLink application module can discover phone A based on the Bluetooth broadcasts sent by phone A. In other words, phone A and tablet B can discover each other based on the Bluetooth broadcasts sent by the other device.
[0139] 403. The MagicLink application module of mobile phone A and the MagicLink application module of tablet computer B establish a Bluetooth connection.
[0140] The MagicLink application module of mobile phone A and the MagicLink application module of tablet B can establish a Bluetooth connection and communicate via the Bluetooth communication protocol.
[0141] The Bluetooth communication protocol can be the traditional Bluetooth protocol, or the Bluetooth Low Energy (BLE) protocol; of course, it can also be other new Bluetooth protocol types that will be launched in the future, which is not limited in this application.
[0142] 404. The MagicLink application module of mobile phone A and the MagicLink application module of tablet B perform device security authentication and exchange keys based on Bluetooth connection.
[0143] Mobile phone A and tablet B can perform device security authentication via Bluetooth to confirm that the other end is a trusted device. Then, mobile phone A and tablet B can exchange keys for secure communication.
[0144] 405a. The MagicLink application module of mobile phone A requests the WiFi link module of mobile phone A to obtain the basic WiFi parameters.
[0145] The basic WiFi parameters may include the version number of the WiFi link module, which indicates the number of WiFi network cards supported by the device, the number of supported WiFi P2P links, and the supported service scenarios (e.g., Trust Ring, Honor Share).
[0146] 406a. The WiFi link module of mobile phone A obtains the basic WiFi parameters of mobile phone A.
[0147] 407a. The WiFi link module of mobile phone A returns the basic WiFi parameters of mobile phone A to the MagicLink application module of mobile phone A.
[0148] 405b. The MagicLink application module of tablet B requests the WiFi basic parameters of tablet B from the WiFi link module of tablet B.
[0149] 406b. The WiFi link module of tablet B obtains the basic WiFi parameters of tablet B.
[0150] The basic WiFi parameters of tablet B can be found in the description of the basic WiFi parameters of phone A, and will not be repeated here.
[0151] 407b. The WiFi link module of tablet B returns the basic WiFi parameters of tablet B to the MagicLink application module of tablet B.
[0152] Steps 405a-407a and steps 405b-407b can be executed simultaneously.
[0153] 408. The MagicLink application module of mobile phone A and the MagicLink application module of tablet B exchange the basic WiFi parameters of the other end.
[0154] Optionally, after mobile phone A and tablet B establish a Bluetooth connection, the MagicLink application module of mobile phone A and the MagicLink application module of tablet B can exchange the basic WiFi parameters of the other end. This allows mobile phone A or tablet B to make a preliminary judgment based on its own and the other end's basic WiFi parameters after receiving a user-initiated service (e.g., screen sharing service). For details, please refer to the relevant description in step 417.
[0155] 409a. The MagicLink application module of mobile phone A reports the online status of the peer device (i.e. tablet B) to the smart interconnection application of mobile phone A.
[0156] That is, the MagicLink application module of mobile phone A reports the online status of tablet B to the smart interconnection application of mobile phone A.
[0157] 409b. The MagicLink application module of tablet B reports the online status of device (phone A) to the smart interconnection application of tablet B.
[0158] 410. The smart interconnection application of mobile phone A notifies the user that device (tablet B) is online.
[0159] For example, such as Figure 5B As shown in (b), the interface of mobile phone A can display the icon 44 of tablet B (hereinafter referred to as tablet B), prompting the user that "tablet B is online".
[0160] 411a. The smart interconnection application of mobile phone A receives the screen sharing operation initiated by the user.
[0161] Screen sharing refers to projecting the screen of a device (e.g., mobile phone A) onto the screen of a peer device (e.g., tablet B). This application uses WiFi P2P communication as an example for screen sharing, but WiFi P2P communication can also include other types of services, such as multi-screen collaboration and file sharing, which are not limited in this application.
[0162] For example, such as Figure 5B As shown in (a), in response to a user swiping down from the status bar of phone A to display the notification panel, phone A displays the notification panel, which may include the "Trust Ring Multi-Device Interconnection Center" option 41. In response to a user triggering an action on the "Trust Ring Multi-Device Interconnection Center" option 41 (e.g., a click), phone A may display as shown in (a). Figure 5B The control interface 42 shown in (b) is shown in the figure. The control interface 42 includes the device identifier 43 of the local device (i.e., mobile phone A) and the device identifier 44 of the tablet computer B (hereinafter referred to as tablet B) (that is, the local device (i.e., mobile phone A) and tablet computer B are both joined to the same trust ring).
[0163] In some implementations, the user can drag the device identifier 44 of tablet B towards the device identifier 43 of the device itself. When the drag operation ends near the device identifier 43 of the device itself, screen sharing can be achieved between the device (i.e., mobile phone A) and tablet B (i.e., the screen of mobile phone A can be projected onto the screen of tablet B). In other implementations, the user can drag the device identifier 43 of the device itself towards the identifier 44 of tablet B. When the drag operation ends near the identifier 44 of tablet B, screen sharing can be achieved between the device (i.e., mobile phone A) and tablet B.
[0164] 411b. The Smart Interconnection Application of Mobile Phone A identifies the Quality of Service (QoS) information of the screen sharing service.
[0165] The QoS information for a service (e.g., screen sharing) may include one or more of the following: expected bandwidth, latency, jitter, priority, etc. For example, a screen sharing service can be a high-bandwidth service. For instance, the expected bandwidth of a screen sharing service may be greater than a preset bandwidth (e.g., 40MB / s). Alternatively, a screen sharing service can be a low-latency service. For instance, the latency requirement for a screen sharing service is less than 20ms.
[0166] 412. The Smart Interconnection application of mobile phone A initiates a connection call to the MagicLink application module of mobile phone A.
[0167] The smart interconnection application on mobile phone A can call the device connection interface of the MagicLink application module to pass in the QoS information of the screen sharing service.
[0168] 413a. The MagicLink application module of mobile phone A and the MagicLink application module of tablet computer B establish a negotiation channel (channel 1).
[0169] When the MagicLink application module of mobile phone A receives a connection call from the smart interconnection application, it can save the QoS information of the screen sharing service. Furthermore, the MagicLink application module of mobile phone A can create a negotiation channel (channel 1) with the peer device (tablet B). For example, as shown... Figure 6 As shown, channel 1 is used for information exchange between MagicLink application modules of different devices (MagicLink application module of mobile phone A and MagicLink application module of tablet computer B).
[0170] The MagicLink application module on phone A can create Channel 1 based on the discovery and network type between phone A and tablet B, regardless of the network connection type. For example, if the discovery and network type between phone A and tablet B is a WiFi LAN, Channel 1 can be created based on the WiFi connection; if the discovery and network type between phone A and tablet B is a Bluetooth network, Channel 1 can be created based on the Bluetooth connection.
[0171] Furthermore, after Channel 1 is successfully created, the MagicLink application module of mobile phone A and the MagicLink application module of tablet B can perform device security authentication and key exchange based on Channel 1, thereby completing the creation of the encrypted negotiation channel (i.e., encrypted Channel 1).
[0172] It should be understood that a Bluetooth connection or a WiFi connection refers to a physical channel (also called a physical link) used for data transmission between two communicating parties (e.g., mobile phone A and tablet B). Multiple virtual channels (also called data links) can be created based on the same physical channel. Virtual channels have the function of exchanging information between specific modules using predefined data processing protocols. For example, channel 1 is a virtual channel that can be used for information exchange between MagicLink application modules on different devices.
[0173] For example, the data processing protocol of the negotiation channel (i.e., channel 1) can be a first data processing protocol, which can be used to process (encapsulate or parse) data packets in key+value format. That is, the data packets corresponding to the first data processing protocol are in key+value format. Key+value format data packets are easy to parse, but they carry redundant payload (key) when sending data, consuming additional bandwidth. Furthermore, key+value format data packets require complete parsing during forwarding (e.g., data needs to be parsed into key+value format), making data transmission inefficient.
[0174] For example, the format of the data packets for the negotiation channel (i.e., channel 1) can be as shown in Table 1:
[0175] Table 1
[0176] key IP TCP port value XX XX
[0177] Among them, IP and TCP ports refer to the IP and TCP ports used by the local device (phone A) to establish a WiFi P2P connection.
[0178] 413b. The MagicLink application module of mobile phone A and the MagicLink application module of tablet computer B create an auxiliary channel (channel 2).
[0179] The MagicLink application module on phone A can also create an auxiliary channel (channel 2) to the other device (tablet B). Channel 2 is a virtual channel. For example, ... Figure 6 As shown, channel 2 can be used for communication (information exchange) between WiFi link modules of different devices (WiFi link module of mobile phone A and WiFi link module of tablet B). When WiFi link modules of different devices exchange information based on channel 2, the information can be forwarded through the respective MagicLink application modules of each device.
[0180] The MagicLink application module on phone A can create Channel 2 based on the discovery and network type between phone A and tablet B, regardless of the network connection type. For example, if the discovery and network type between phone A and tablet B is a WiFi LAN, Channel 2 can be created based on the WiFi connection; if the discovery and network type between phone A and tablet B is a Bluetooth network, Channel 2 can be created based on the Bluetooth connection.
[0181] Furthermore, after channel 2 is successfully created, the MagicLink application module of mobile phone A and the MagicLink application module of tablet B can perform device security authentication and key exchange based on channel 2. Thus, the encrypted auxiliary channel (i.e., encrypted channel 2) is created.
[0182] For example, the data processing protocol for the auxiliary channel (i.e., channel 2) can be a second data processing protocol, which can be used to process (encapsulate or parse) TLV format data packets. That is, the data packets corresponding to the second data processing protocol are in TLV format. In TLV, T stands for dataType (or simply Type), indicating the type of the receiving module corresponding to the data; V represents the actual value carried in the data packet; and L represents the length of the actual value. The lengths of T and L can be fixed, for example, 2 bytes or 4 bytes, and the length of V is determined based on L.
[0183] It should be noted that when WiFi link modules of different devices exchange information via Channel 2, the data can be forwarded through the respective MagicLink application modules of each device. Since the data packets corresponding to the data processing protocol of Channel 2 are in TLV format, the MagicLink application module does not need to parse the WiFi link module's data (e.g., it does not need to parse the WiFi link module's data into a key+value structure) when forwarding it; it can directly transmit the WiFi link module's data, thus improving transmission efficiency. Furthermore, compared to the JSON protocol, using the TLV protocol to send data does not require carrying redundant and invalid payloads (e.g., key fields), resulting in better transmission efficiency and scalability.
[0184] For example, the format of data packets for the auxiliary channel (i.e., channel 2) can be as shown in Table 2:
[0185] Table 2
[0186] dataType length value 0 XX XXXXX
[0187] For example, a dataType field of 0 can indicate that the receiving module corresponding to the data (i.e., the value) is the WiFi link module of the other end.
[0188] Optionally, the data packets of the secondary channel (i.e., channel 2) may also include encryption / decryption fields (e.g., AuthDataHead) to indicate the encryption / decryption type of the data packets of the secondary channel (i.e., channel 2).
[0189] In one possible implementation, the auxiliary channel (i.e., channel 2) can simultaneously provide negotiation capabilities for the MagicLink application module and the WiFi link module of different devices, meaning it can be used simultaneously for data interaction between the MagicLink application module and the WiFi link module of different devices. Thus, a single transmission based on the auxiliary channel (i.e., channel 2) can simultaneously meet the data interaction needs of the MagicLink application module and the WiFi link module. For example, the data packet format of the auxiliary channel (i.e., channel 2) can be as shown in Table 3:
[0190] Table 3
[0191] dataType 1 Length 1 value 1 dataType 2 Length 2 value 2 1 XX XX 0 XX XX
[0192] In this context, the dataType 1 field being 1 indicates that the receiving module corresponding to the data (value 1) is the Magiclink application module of the other end, and Length 1 indicates the length of value 1; the dataType 2 field being 0 indicates that the receiving module corresponding to the data (i.e., value 2) is the WiFi link module of the other end, and Length 2 indicates the length of value 2.
[0193] 414a. The MagicLink application module of mobile phone A saves channel 1 and channel 2.
[0194] 414b. The MagicLink application module of tablet B saves channel 1 and channel 2.
[0195] 415a. The MagicLink application module of mobile phone A registers channel 2 with the WiFi link module of mobile phone A.
[0196] The MagicLink application module of mobile phone A can send a registration request to the WiFi link module. The registration request can include the configuration information of channel 2 (e.g., channel name, channel data processing protocol). The WiFi link module of mobile phone A can save the configuration information of channel 2 for later use.
[0197] 415b. The MagicLink application module of tablet B registers channel 2 with the WiFi link module of tablet B.
[0198] The MagicLink application module of tablet B can send a registration request to the WiFi link module. The registration request can include the configuration information of channel 2 (e.g., channel name, channel data processing protocol). The WiFi link module of tablet B can save the configuration information of channel 2 for later use.
[0199] 416. The MagicLink application module of mobile phone A initiates a connection call to the WiFi link module of mobile phone A.
[0200] That is, the MagicLink application module of mobile phone A can transmit the following information to the WiFi link module of mobile phone A: QoS information of screen sharing service and WiFi basic parameters of the peer device (tablet B).
[0201] 417. The WiFi link module of mobile phone A generates data packet 1.
[0202] In some embodiments, the WiFi link module of mobile phone A can receive information from the MagicLink application module of mobile phone A and perform the following processing: 1. Collect the latest WiFi capability information of the local device (for example, the WiFi link module of mobile phone A can call the query interface of the WiFi driver to query the WiFi capability information, and the WiFi driver can return the WiFi capability information based on the current hardware capabilities (number, model, etc. of WiFi network cards) and resource usage (usage status of WiFi network cards); 2. Generate data packet 1 based on the collected WiFi capability information and the QoS information of the screen sharing service. That is, data packet 1 includes the latest WiFi capability information of the local device and the QoS information of the screen sharing service. Data packet 1 is used to negotiate WiFi P2P connection configuration information with the peer.
[0203] The WiFi capability information can include static capability information (basically fixed information), which includes the number of WiFi network cards supported by the device, WiFi network card identifier, WiFi network card model, available WiFi channels, and other information.
[0204] Furthermore, WiFi capability information can also include dynamic capability information (dynamically changing information, also known as WiFi occupancy status information). Dynamic capability information can include information about WiFi connections that the device (or network card) has established (e.g., the number of established WiFi connections and the status of established WiFi connections (e.g., the P2P role of the two-end devices in the WiFi connection, network card information, etc.)).
[0205] In other embodiments, the WiFi link layer module can make a preliminary judgment based on the currently acquired information (the WiFi basic parameters of both devices and the QoS information of the service). If it is determined that the WiFi capabilities of the two devices (mainly the capabilities indicated by static capability information) cannot meet the service requirements, there is no need to establish a negotiation channel or initiate a negotiation process, avoiding unnecessary negotiation and saving negotiation resources. Furthermore, the WiFi link layer module can notify the smart interconnection application of screen sharing failure through the MagicLink application module, and the smart interconnection application can prompt the user that screen sharing has failed. If it is determined that the WiFi basic parameters of both devices can meet the service requirements, the latest WiFi capability information of the local device can be collected (mainly the latest dynamic capability information; static capability information is usually fixed and does not need to be collected repeatedly), and data packet 1 can be generated based on the collected WiFi capability information and the QoS information of the screen sharing service.
[0206] For example, after receiving a connection call initiated by the MagicLink application module, the WiFi link layer module can parse the bandwidth requirement of the service (e.g., screen sharing service) and determine the type of physical connection corresponding to the service based on the bandwidth requirement. For instance, if the bandwidth requirement of the service (e.g., screen sharing service) is high bandwidth (e.g., expected bandwidth greater than 40MB / s), the physical connection type can be a 5GHz WiFi P2P connection. If the bandwidth requirement of the service is medium bandwidth (e.g., expected bandwidth greater than 10MB / s and less than 40MB / s), the physical connection type can be a 2.4GHz WiFi P2P connection. If the bandwidth requirement of the service is low bandwidth (e.g., expected bandwidth less than 10MB / s), the physical connection type can be a Bluetooth connection.
[0207] If a service (e.g., screen sharing) requires high bandwidth, and the physical connection type can be a 5GHz WiFi P2P connection, but one end device does not support 5GHz WiFi P2P connections (meaning one end device's capabilities cannot meet the service requirements), then there is no need to establish a negotiation channel or initiate a negotiation process, avoiding unnecessary negotiation and saving negotiation resources. Furthermore, the WiFi link layer module can notify the smart interconnection application of screen sharing failure through the MagicLink application module, and the smart interconnection application can then notify the user of the screen sharing failure.
[0208] 418a. The WiFi link module of mobile phone A calls channel 2 and sends data packet 1.
[0209] That is, the WiFi link module of mobile phone A calls channel 2 registered by the MagicLink application module and sends data packet 1 to the MagicLink application module of mobile phone A.
[0210] 418b. The MagicLink application module of mobile phone A encapsulates data packet 1 into data packet 2 according to the communication protocol of channel 2.
[0211] The MagicLink application module of mobile phone A can add a MagicLink header to data packet 1 to obtain data packet 2.
[0212] The MagicLink header can include the data type and the data length.
[0213] For example, the format of data packet 2 can be as shown in Table 4:
[0214] Table 4
[0215] dataType length value 0 5 01 02 03 04 05
[0216] The dataType field is 0, which indicates that the receiving module corresponding to the data (value) is the WiFi link module of the other end. Length indicates the length of the value (e.g., 5 bytes). The value indicates the data packet 1 generated by the WiFi link module of mobile phone A (e.g., 01 02 03 04 05).
[0217] 418c. The MagicLink application module of mobile phone A sends data packet 2 through channel 2.
[0218] 419. The MagicLink application module of tablet B receives data packet 2 from channel 2 and parses data packet 2 to obtain data packet 1 according to the communication protocol of channel 2.
[0219] The MagicLink application module of tablet B can strip the MagicLink header from data packet 2 to obtain data packet 1.
[0220] 420. The MagicLink application module of tablet B sends data packet 1 to the WiFi link module of tablet B.
[0221] 421a. The WiFi link module of tablet B parses data packet 1 to obtain the WiFi capability information and QoS information of the initiating device (i.e., mobile phone A).
[0222] Furthermore, the WiFi link module of tablet B can obtain the WiFi capability information of the local device (i.e., tablet B).
[0223] like Figure 4B As shown, the method also includes:
[0224] 421b. The WiFi link module of tablet B makes a decision based on the information included in data packet 1 and the WiFi capability information of tablet B, and generates data packet 3 based on the decision result.
[0225] That is, the WiFi link module of tablet B can make decisions based on the WiFi capability information of both devices and the QoS information of services (e.g., screen sharing services), and then generate data packets 3 based on the decision results.
[0226] In some embodiments, when the QoS information of the service meets the first condition, if tablet B and mobile phone A support WiFi P2P connection on the 5G band, then tablet B and mobile phone A can establish a WiFi P2P connection on the 5G band. Tablet B can then generate corresponding WiFi P2P connection configuration information. Data packet 3 includes WiFi P2P connection configuration information. This WiFi P2P connection configuration information may include the roles (GO and GC) of P2P communication, the network card used for P2P communication, the channel (e.g., a 5G channel), antenna information, etc.
[0227] Optionally, it can be determined whether tablet B supports 5G band WiFi P2P connections based on the tablet B's WiFi capability information. For example, if tablet B includes an idle network card that supports the 5G band, then tablet B is considered to support 5G band WiFi P2P connections. Similarly, it can be determined whether mobile phone A supports 5G band WiFi P2P connections based on the mobile phone A's WiFi capability information. For example, if mobile phone A includes an idle network card that supports the 5G band, then mobile phone A is considered to support 5G band WiFi P2P connections.
[0228] In some embodiments, when tablet B's P2P role is GO (i.e., tablet B's P2P role is GO in an established WiFi P2P connection (e.g., tablet B and mobile phone C establish a WiFi P2P connection), and the network card used by tablet B to establish the WiFi P2P connection supports the 5G band; and mobile phone A has an idle network card, tablet B can reuse the GO to establish a WiFi P2P connection with mobile phone A. That is, tablet B continues to act as GO, connecting to mobile phone A, which acts as GC. In other words, as GO, tablet B can connect not only to mobile phone C, which acts as GC, but also to mobile phone A, which also acts as GC. In this way, tablet B's reuse of the GO to establish a WiFi P2P connection with mobile phone A expands the connected devices of tablet B and saves network card resources.
[0229] For example, the first condition may include: the QoS information of the service indicates that the expected bandwidth of the service is greater than a first threshold (e.g., 40 MB / s). Optionally, the first condition may also include: the expected latency of the service is less than a second threshold (e.g., 20 ms) and / or the jitter of the service is less than a third threshold (e.g., 5 ms).
[0230] In some embodiments, when the QoS information of the service meets the first condition, if tablet B or mobile phone A does not support WiFi P2P connection on the 5G band, tablet B can return a decision result to mobile phone A. The decision result is used to instruct the establishment of a bridge.
[0231] In some embodiments, when the QoS information of the service meets the second condition, if tablet B and mobile phone A support WiFi P2P connection on the 5G band, then tablet B and mobile phone A can establish a WiFi P2P connection on the 5G band. If tablet B and mobile phone A do not support WiFi P2P connection on the 5G band, but support WiFi P2P connection on the 2.4G band, then tablet B and mobile phone A can establish a WiFi P2P connection on the 2.4G band. Tablet B can generate corresponding WiFi P2P connection configuration information, which may include the P2P communication role (GO and GC), the network card used for P2P communication, the channel (5G channel / 2.4G channel), antenna, and other information.
[0232] For example, the second condition may include: the QoS information of the service indicates that the expected bandwidth of the service is less than or equal to a first threshold (e.g., 40 MB / s). Optionally, the first condition may also include: the expected latency of the service is greater than or equal to a second threshold (e.g., 20 ms) and / or the jitter of the service is greater than or equal to a third threshold (e.g., 5 ms).
[0233] In this embodiment, the connection method (WiFi P2P connection or bridging) between the local device and the peer device can be determined based on the QoS information of the service and the WiFi capability information of the device. This can better meet the service requirements and avoid problems such as stuttering and frame drops in the service (e.g., screen sharing service).
[0234] In some embodiments, the WiFi link module determines the P2P network card (the network card used for P2P communication) in the WiFi P2P connection configuration information by selecting an available, idle network card of the device (e.g., tablet B) to establish a WiFi P2P connection. For example, the WiFi link module can sequentially detect whether the first WiFi network card (e.g., WiFi network card 1) and the second WiFi network card (e.g., WiFi network card 2) are available. If the first WiFi network card is available, it directly uses the first WiFi network card to establish a WiFi P2P connection; if the first WiFi network card is unavailable, it then checks whether the second WiFi network card is available. If the second WiFi network card is available, it uses the second WiFi network card to establish a WiFi P2P connection. Of course, if the device (e.g., tablet B) also includes more WiFi network cards (e.g., a third WiFi network card), it can continue to detect until an available WiFi network card is found.
[0235] In some embodiments, the WiFi link module may decide on the P2P channel and antenna (the antenna used for P2P communication) in the WiFi P2P connection configuration information in the following ways: 1. When the service is high bandwidth (e.g., the expected bandwidth of the service is greater than the preset bandwidth (e.g., 40MB / s)), a 5G band channel is selected to establish a WiFi P2P connection, and the antenna is exclusively used (i.e., one WiFi P2P connection exclusively uses one or more antennas for data transmission); 2. When the service is medium to low bandwidth (e.g., the expected bandwidth of the service is less than the preset bandwidth), a 2.4G band channel is selected to establish a WiFi P2P connection, or a 5G band channel is selected to establish a WiFi P2P connection, and the antenna can be shared (e.g., two WiFi P2P connections can share one or more antennas for data transmission).
[0236] In some embodiments, the WiFi link module may determine the P2P role in the WiFi P2P connection configuration information by designating the device as the GO as having strong WiFi chip capabilities (e.g., WiFi chips can integrate WiFi network cards, and the more WiFi network cards integrated and the newer the WiFi network card model, the stronger the WiFi chip capabilities) and sufficient power (e.g., the device connected to a power source (e.g., a TV) has more power than the device being charged (e.g., a mobile phone or tablet)).
[0237] 422a. The WiFi link module of tablet B calls channel 2 and sends data packet 3.
[0238] The WiFi link module of tablet B can call channel 2 registered by the MagicLink application module of tablet B to send data packet 3 to the MagicLink application module of tablet B.
[0239] 422b. The MagicLink application module of tablet computer B encapsulates data packet 3 into data packet 4 according to the communication protocol of channel 2.
[0240] The MagicLink application module of tablet B adds a MagicLink header to data packet 3, resulting in data packet 4.
[0241] 422c. The MagicLink application module of tablet B sends data packet 4 through channel 2.
[0242] 423a. The MagicLink application module of mobile phone A receives data packet 4 through channel 2 and parses data packet 4 according to the communication protocol of channel 2 to obtain data packet 3.
[0243] The MagicLink application module of mobile phone A can strip the MagicLink header from data packet 4 to obtain data packet 3.
[0244] 423b. The MagicLink application module of mobile phone A sends data packet 3 to the WiFi link module of mobile phone A.
[0245] 424. The WiFi link module of mobile phone A parses data packet 3 to obtain the WiFi P2P connection configuration information decided by the peer device (tablet B), and creates GO based on the WiFi P2P connection configuration information.
[0246] Data packet 3 includes WiFi P2P connection configuration information decided by the peer device (tablet B). For example, the WiFi P2P connection configuration information could be: mobile phone A acts as the GO (Go), tablet B acts as the GC (GC), the P2P channel is established on a 5G channel (e.g., channel 161 at a frequency of 5805MHz), and tablet B's WiFi network card 2 acts as the P2P network card. Mobile phone A can create a GO based on the WiFi P2P connection configuration information.
[0247] Furthermore, after phone A creates the GO, phone A can also perform the following steps:
[0248] 425a. The WiFi link module of mobile phone A sends the IP address and network card name of the local device (GO device) to the MagicLink application module of mobile phone A.
[0249] The IP address and network interface name of the local device (GO device) refer to the IP address and network interface used to create the WiFi P2P connection.
[0250] 425b. After receiving the IP address and network card name, the MagicLink application module of mobile phone A starts listening on the TCP port and encapsulates the local IP address and TCP port into a data packet 5 according to the communication protocol of channel 1.
[0251] That is, the MagicLink application module of mobile phone A can listen to the IP and TCP ports used to establish WiFi P2P connections, and encapsulate the listened local IP and TCP ports into data packets.
[0252] Among them, data packet 5 is used as the transmission channel for establishing a subsequent WiFi P2P connection.
[0253] For example, the format of data packet 5 can be as shown in Table 1 above (step 413a).
[0254] 425c. The MagicLink application module of mobile phone A sends data packet 5 to the MagicLink application module of tablet computer B through channel 1.
[0255] 426a. After receiving data packet 5, the MagicLink application module of tablet computer B parses data packet 5 through the communication protocol of channel 1.
[0256] 426b. The MagicLink application module of tablet B stores the IP and TCP port of the peer (phone A).
[0257] The IP and TCP ports of the peer (phone A) are used to establish a negotiation channel on the P2P platform later.
[0258] 427a. The WiFi link module of mobile phone A encapsulates the connection information of the local device (GO device) into a data packet 6, calls channel 2, and passes in the data packet 6.
[0259] The connection information for the GO device (i.e., the connection information of the device acting as the GO) includes the frequency created by the GO, SSID, password, etc. Data packet 6 is used for the GC and GO to establish a WiFi P2P connection.
[0260] 427b. The MagicLink application module of mobile phone A encapsulates data packet 6 into data packet 7 according to the communication protocol of channel 2.
[0261] The MagicLink application module of mobile phone A adds a MagicLink header to data packet 6, resulting in data packet 7.
[0262] 427c. The MagicLink application module of mobile phone A sends data packet 7 to the MagicLink application module of tablet computer B through channel 2.
[0263] Steps 425a-425c and steps 427a-427c can be executed in parallel.
[0264] 428a. After receiving data packet 7, the MagicLink application module of tablet computer B parses data packet 7 through the communication protocol of channel 2 to obtain data packet 6.
[0265] 428b. The MagicLink application module of tablet B sends data packet 6 to the WiFi link module of tablet B.
[0266] Steps 427a-427b and steps 428a-428b can be executed in parallel.
[0267] In other words, the MagicLink application module of tablet B can receive different data packets through different channels and process them differently.
[0268] 429. The WiFi link module of tablet B parses data packet 6 to obtain the GO connection information of the other end (phone A).
[0269] 430. The WiFi link module of tablet B establishes a WiFi P2P link layer connection with the WiFi link module of mobile phone A based on the GO connection information of the peer (mobile phone A).
[0270] The WiFi link module of tablet B connects to mobile phone A, which acts as GO, based on the GO connection information of the peer (mobile phone A).
[0271] That is, tablet B acts as GC and connects to mobile phone A as GO.
[0272] 431a. The WiFi link module of tablet B sends a WiFi notification message to the MagicLink application module of tablet B. The WiFi notification message is used to notify that the WiFi P2P connection is successful.
[0273] The WiFi notification message includes information related to the WiFi P2P connection, such as the IP address of the local device (tablet B) and the peer device (phone A) used to establish the WiFi P2P connection, the network card name (e.g., phone A corresponds to network card 1, and tablet B corresponds to network card 2), the P2P role (e.g., phone A is GO, and tablet B is GC), and the ID (serviceid) of this WiFi P2P connection.
[0274] 431b. The MagicLink application module of tablet B stores WiFi P2P connections.
[0275] The MagicLink application module of tablet B receives the WiFi notification message sent by the WiFi link module of tablet B, obtains the relevant information of WiFi P2P connection from the WiFi notification message, and saves the relevant information (i.e., saves the WiFi P2P connection).
[0276] 432a. The WiFi link module of mobile phone A sends a WiFi notification message to the MagicLink application module of mobile phone A. The WiFi notification message is used to notify that the WiFi P2P connection is successful.
[0277] 432b. The MagicLink application module of mobile phone A saves WiFi P2P connections.
[0278] Steps 431a-431b and 432a-432b can be executed in parallel. That is, after a successful WiFi connection, the WiFi link modules of both devices A and B respectively notify their local MagicLink application modules that the P2P connection is successful. The MagicLink application modules of each device can save the WiFi P2P connection for subsequent communication based on that connection.
[0279] 433. The MagicLink application module of tablet B creates a TCP encrypted channel based on WiFi P2P connection to the MagicLink application module of mobile phone A.
[0280] The MagicLink application module of tablet B can make logical judgments based on its local P2P role to determine what kind of processing to perform. For example, when the P2P role of tablet B is GC, the MagicLink application module of tablet B can read the IP and port of the peer device (phone A) saved in step 427b, and create a TCP encrypted channel based on WiFi P2P connection to the peer device (phone A) based on the peer device (phone A)'s IP and port.
[0281] Among them, the TCP encrypted channel based on WiFi P2P connection can provide a more secure, stable, high-bandwidth, and low-latency negotiation channel for smart interconnection applications (such as screen sharing services) than the Bluetooth channel, providing a negotiation channel for subsequent link management negotiation of MagicLink application modules. That is, the MagicLink application modules of the two-end devices (e.g., mobile phone A and tablet B) can exchange service (e.g., screen sharing service) data (e.g., screen display information) based on the TCP encrypted channel of WiFi P2P connection.
[0282] Optionally, after the TCP encrypted channel based on the WiFi P2P connection is created, the devices (phone A and tablet B) can delete the previously created channel 1 and / or channel 2 to save storage space.
[0283] 434. The MagicLink application module of mobile phone A replies to the MagicLink application module of tablet computer B that the TCP encrypted channel based on WiFi P2P connection has been created.
[0284] 435a. The MagicLink application module of mobile phone A stores a TCP encrypted channel based on WiFi P2P connection.
[0285] That is, mobile phone A can save the TCP encrypted channel for subsequent interaction with the other end device (tablet B).
[0286] 435b. The MagicLink application module of tablet B stores a TCP encrypted channel based on WiFi P2P connection.
[0287] This means that tablet B can save the TCP encrypted channel for subsequent interaction with the peer device (phone A).
[0288] Steps 435a and 435b can be executed in parallel.
[0289] 436. The MagicLink application module of mobile phone A notifies the smart interconnection application of mobile phone A that the device connection is successful.
[0290] Once the encrypted TCP channel based on WiFi P2P connection is successfully established, the MagicLink application module of mobile phone A notifies the smart interconnection application of mobile phone A that the device connection is successful.
[0291] 437. The Smart Interconnection application on mobile phone A initiates a screen sharing service and notifies the user that the screen sharing service has been successfully established.
[0292] The smart connectivity application on mobile phone A can initiate screen sharing services over a TCP encrypted channel connected via WiFi P2P. This means sending screen sharing data (e.g., information related to mobile phone A's screen) to the other device (tablet B) via WiFi P2P connection.
[0293] Steps 436-437 can be performed after step 432a, step 432b, or step 434.
[0294] The solution provided in this application embodiment allows the WiFi link module to determine the WiFi P2P connection configuration information. Since the WiFi link module is capable of obtaining the local device's WiFi capability information in real time, it can more conveniently and efficiently determine the WiFi P2P connection configuration information based on the local device's WiFi capability information and the WiFi capability information from the peer, thereby improving the communication quality of WiFi P2P. This eliminates the need for the MagicLink application module to obtain and store the local device's WiFi capability information from the WiFi link module, saving communication overhead and storage space, and making the WiFi P2P connection process simpler and more efficient.
[0295] like Figure 7A As shown, this application provides a communication method. Taking mobile phone A (first electronic device), tablet computer B (second electronic device), and mobile phone C (third electronic device) as examples, the method describes the process of bridging mobile phone C and mobile phone A (i.e., mobile phone C and mobile phone A are connected through tablet computer B) when mobile phone A establishes a first WiFi P2P connection (WiFi P2P connection 1) and mobile phone C establishes a second WiFi P2P connection (WiFi P2P connection 2). The method includes:
[0296] 701. Mobile phone A and tablet B establish a WiFi P2P connection.
[0297] The process of establishing a WiFi P2P connection between mobile phone A and tablet B can be found in steps 401-437, and will not be repeated here.
[0298] For example, network card 0 (P2P0) of mobile phone A can establish WiFi P2P connection 1 with network card 0 (P2P0) of tablet computer B, and mobile phone A can act as GO and tablet computer B can act as GC.
[0299] 702. Mobile phone C and tablet B establish a WiFi P2P connection.
[0300] The process of establishing a WiFi P2P connection between mobile phone C and tablet B can be referred to in steps 401-437, and will not be repeated here.
[0301] For example, the network card 0 (P2P0) of mobile phone C can establish a WiFi P2P connection 2 with the network card 1 (P2P1) of tablet computer B, and mobile phone C can act as GC and tablet computer B can act as GO.
[0302] It should be noted that the network segment corresponding to WiFi P2P connection 1 is different from the network segment corresponding to WiFi P2P connection 2. For example, the network segment corresponding to WiFi P2P connection 1 can be the 49 network segment, while the network segment corresponding to WiFi P2P connection 2 can be a non-49 network segment (for example, the 50 network segment).
[0303] In steps 701-702, the P2P roles of mobile phone A, tablet B, and mobile phone C in WiFi P2P connection 1 and WiFi P2P connection 2, respectively, can be referenced. Figure 1E The details of (a)-(d) in this application will not be elaborated upon here. The embodiments of this application use... Figure 1E The following example (a) (i.e., in WiFi P2P connection 1, mobile phone A is the GO and tablet B is the GC, and in WiFi P2P connection 2, mobile phone C is the GC and tablet B is the GO) will be used for illustration.
[0304] 703. The MagicLink application module of mobile phone C receives the first operation (e.g., screen sharing operation) initiated by the user to mobile phone A.
[0305] The MagicLink application module of mobile phone C can receive a first operation (e.g., screen sharing operation) initiated by the user through the smart interconnection application (first application) of mobile phone C. The first operation (e.g., screen sharing operation) is used to trigger mobile phone C to initiate a first service (e.g., screen sharing service) to mobile phone A.
[0306] This application uses screen sharing as the first operation and screen sharing as the first service as an example for illustration. In practical applications, the first service may also include other types of services, such as screen sharing, multi-screen collaboration, and file sharing, etc., which are not limited in this application.
[0307] In some embodiments, after receiving a screen sharing operation initiated by the user, the MagicLink application module of mobile phone C can query the WiFi capability information of mobile phone C from the WiFi link module of mobile phone C (e.g., query whether mobile phone C has an available network card). If the WiFi capability information of mobile phone C (e.g., mobile phone C has an available network card) supports WiFi P2P direct connection (i.e., directly establishing a WiFi P2P connection with the peer device without the need for intermediate devices to forward), the WiFi link module of mobile phone C can notify the MagicLink application module of mobile phone C that WiFi P2P direct connection is available, and then the MagicLink application module of mobile phone C can execute step 704. If the WiFi capability information of mobile phone C does not support WiFi P2P direct connection (e.g., mobile phone C does not have an available network card), the WiFi link module of mobile phone C can notify the MagicLink application module of mobile phone C that WiFi P2P direct connection is unavailable, and then step 706 can be executed.
[0308] 704. The MagicLink application module of mobile phone C sends a P2P direct connection request to the MagicLink application module of mobile phone A.
[0309] For example, the P2P direct connection request information may include device information of mobile phone C, such as device ID, MAC address, IP address, and subnet mask. Optionally, the P2P direct connection request information may also include other information, such as the MagicLink protocol version and connection type of mobile phone C, which is not specifically limited in this application.
[0310] 705. The MagicLink application module of mobile phone A sends a P2P direct connection response message to the MagicLink application module of mobile phone C. The P2P direct connection response message indicates that the P2P direct connection failed.
[0311] If the WiFi capability information of mobile phone A does not support WiFi P2P direct connection (for example, mobile phone A has no available network card), the MagicLink application module of mobile phone A sends a P2P direct connection response message to the MagicLink application module of mobile phone C. The P2P direct connection response message indicates that the P2P direct connection has failed. If mobile phone C receives the P2P direct connection response message and determines that the P2P direct connection has failed, it can proceed to step 706.
[0312] 706. The MagicLink application module of mobile phone C sends a P2P bridging request to the MagicLink application module of mobile phone A.
[0313] When mobile phone C supports single-path P2P capability (e.g., has one network card) and is in the GO role, it can send information about all GC devices it is connected to (e.g., device ID, P2P role, IP, P2P network card, MAC port, etc.) to mobile phone A in the P2P bridging request information.
[0314] When mobile phone C supports single-path P2P capability and is a GC, it can include information about all connected GO devices (e.g., device ID, P2P role, IP, P2P network card, MAC port, etc.) in the P2P bridging request information and send it to mobile phone A.
[0315] When mobile phone C supports dual-path P2P capability (e.g., has two network cards), it can send information about all GO devices it is connected to (mobile phone C with a network card is GC) and information about all GC devices it is connected to (mobile phone C with a network card is GO) to mobile phone A in the P2P bridging request message.
[0316] Furthermore, the P2P bridging request information may also include the device information of mobile phone C itself, such as the device ID, P2P role (GO or GC), MAC address, IP address, IP mask, etc. Optionally, the P2P bridging request information may also include other information, such as the MagicLink protocol version and connection type of mobile phone C; this application does not impose specific limitations on this.
[0317] 707a. The MagicLink application module of mobile phone A queries whether mobile phone A and mobile phone C have a common device (i.e., whether mobile phone A and mobile phone C are connected to the same device).
[0318] The MagicLink application module of mobile phone A can check whether there is a device that also has a P2P connection with mobile phone A from the device information sent by mobile phone C (the P2P bridging request information includes the device information of the GO device and / or GC device connected to mobile phone C). If there is a device (i.e. mobile phone A and mobile phone C have a common device), the device can be recorded in the device list ListA.
[0319] 707b. When mobile phone A and mobile phone C share a common device (e.g., tablet B), the MagicLink application module of mobile phone A queries whether mobile phone A, mobile phone C and the common device are in the same network segment.
[0320] That is, the MagicLink application module of mobile phone A can query whether the P2P connection between mobile phone A and the shared device (e.g., tablet B) and the P2P connection between mobile phone C and the shared device are established on the same network segment.
[0321] If the device list ListA is not empty, the MagicLink application module of mobile phone A can iterate through the devices in the device list ListA and compare their network segments with those of mobile phone A and mobile phone C respectively. If a device on a different network segment is found (e.g., tablet B), a cross-network segment bridging scheme can be executed (i.e., steps 708-715).
[0322] Additionally, if the device list ListA is empty, there are no shared devices, and mobile phone A can execute a dynamic networking scheme (i.e., first disconnect the existing WiFi P2P connection to release the occupied network card, and then establish a WiFi P2P connection with the target device based on the released network card; existing technologies can be referenced, and will not be elaborated here).
[0323] like Figure 8 The diagram illustrates a connection method determination method, which can be used in different scenarios (P2P direct connection, cross-segment bridging, dynamic networking, etc.). For example, if phone A is GO and phone C is GC, or if phone A is GC and phone C is GO, and phone A and phone C are on the same network segment and in the same subnet, phone A can initiate a direct P2P connection to phone C (i.e., directly establish a WiFi P2P connection without needing an intermediate device for forwarding). If phone A and phone C are on the same network segment but in different subnets, phone A can execute a dynamic networking scheme (i.e., first disconnect the existing WiFi P2P connection to release the occupied network card, and then establish a WiFi P2P connection with the target device based on the released network card; existing technologies can be referenced and will not be elaborated here). The scenario where phone A and phone C are on different network segments but in the same subnet does not exist. If phone A and phone C are on different network segments and in different subnets, and phone A and phone C have a common device, a cross-network segment bridging scheme can be executed (i.e., steps 708-715). If phone A and phone C do not have a common device, phone A can execute a dynamic networking scheme.
[0324] When both mobile phone A and mobile phone C are GO, the scenario where mobile phone A and mobile phone C belong to the same network segment and the same subnet does not exist; if mobile phone A and mobile phone C belong to the same network segment but different subnets, mobile phone A can execute the dynamic networking scheme; the scenario where mobile phone A and mobile phone C belong to different network segments but the same subnet does not exist; if mobile phone A and mobile phone C belong to different network segments and different subnets, and mobile phone A and mobile phone C have common devices, a cross-network segment bridging scheme can be executed (i.e., steps 708-715); if mobile phone A and mobile phone C do not have common devices, mobile phone A can execute the dynamic networking scheme.
[0325] When both mobile phone A and mobile phone C are GC, if mobile phone A and mobile phone C belong to the same network segment and the same subnet, mobile phone A can establish a same-network segment bridge with mobile phone C (no forwarding rules and routing rules need to be configured); if mobile phone A and mobile phone C belong to the same network segment but different subnets, mobile phone A can execute a dynamic networking scheme; the scenario where mobile phone A and mobile phone C belong to different network segments but the same subnet does not exist; if mobile phone A and mobile phone C belong to different network segments and different subnets, if mobile phone A and mobile phone C have common devices, a cross-network segment bridging scheme can be executed (i.e., steps 708-715); if mobile phone A and mobile phone C do not have common devices, mobile phone A can execute a dynamic networking scheme.
[0326] In a cross-segment bridging scheme, leaf nodes and intermediate nodes can be included. Multiple leaf nodes can be connected through intermediate nodes (i.e., leaf nodes can be bridged), and data packets can be forwarded through intermediate nodes. Routing rules can be configured on leaf nodes, and forwarding rules can be configured on intermediate nodes, allowing intermediate nodes to forward data packets for leaf nodes.
[0327] For example, such as Figure 9 As shown, devices with dual network cards, such as mobile phones and tablets, can act as leaf nodes (configuring routing rules) or intermediate nodes (configuring forwarding rules); devices with a single network card, such as PCs, can act as leaf nodes (configuring routing rules). This embodiment uses mobile phones A and C as leaf nodes and tablet B as an intermediate node for illustration.
[0328] 708. The MagicLink application module of mobile phone A sends a routing configuration request to the MagicLink application module of tablet computer B.
[0329] The routing configuration request information may include bridging device information (e.g., device information for mobile phone C). Mobile phone C's device information may include its device ID, P2P role (GO or GC), MAC address, and IP address.
[0330] Furthermore, the routing configuration request information may also include device information of mobile phone A itself, such as mobile phone A's device ID, MAC address, and IP address. Optionally, the routing configuration request information may also include other information, such as the MagicLink protocol version and connection type, etc., which are not specifically limited in this application.
[0331] After receiving the routing configuration request information, tablet B can configure forwarding rules. The relevant process is described in steps 709a-709f below.
[0332] 709a. The MagicLink application module of tablet B sends the source IP and destination IP to the WiFi link module of tablet B.
[0333] For example, the source IP could be the IP address of phone A, and the destination IP could be the IP address of phone C. Alternatively, the source IP could be the IP address of phone C, and the destination IP could be the IP address of phone A.
[0334] 709b. The WiFi link module of tablet B determines the network card corresponding to the source IP and destination IP.
[0335] That is, the WiFi link module of tablet B can query the network card (e.g., network card P2P0) used by the local device to establish a WiFi P2P connection with the device corresponding to the source IP (e.g., mobile phone A), and the network card (e.g., network card P2P1) used by the local device to establish a WiFi P2P connection with the device corresponding to the destination IP (e.g., mobile phone C).
[0336] The WiFi link module of tablet B generates forwarding rule configuration instructions based on the source IP, destination IP, and the network cards corresponding to the source IP and destination IP.
[0337] The WiFi link module of tablet B can be configured with one or more forwarding rules.
[0338] For example, the forwarding rule configuration directive can include two lines, as follows:
[0339] Command 1. iptables -I FORWARD -s 192.168.49.1 -d 192.168.50.75 -i P2P0 -o P2P1 -j ACCEPT;
[0340] Command 2. iptables -I FORWARD -s 192.168.50.75 -d 192.168.49.1 -i P2P1 -o P2P0 -j ACCEPT;
[0341] Instruction 1 adds a rule to the FORWARD chain of the filter table. The matching conditions for this rule are: the source IP address in the data packet is 192.168.49.1 (the IP address of phone A), the destination IP address is 192.168.50.75 (the IP address of phone C), the data packet enters from network card P2P0 and exits from network card P2P1; the action is ACCEPT. That is, it allows the local (tablet B) network card P2P0 to receive data packets with a source IP address of 192.168.49.1 (the IP address of phone A), and allows it to send these data packets from the local network card P2P1 to phone C with a destination IP address of 192.168.50.75.
[0342] Command 2 adds a rule to the FORWARD chain of the filter table. The matching conditions for this rule are: the source IP of the data packet is 192.168.50.75 (the IP of mobile phone C), the destination IP is 192.168.49.1 (the IP of mobile phone A), the data packet enters from network card P2P1 and exits from network card P2P0; the action is ACCEPT. That is, it allows the local tablet B's network card P2P1 to receive data packets with a source IP of 192.168.50.75 (the IP of mobile phone C), and allows it to send these data packets from the local network card P2P0 to mobile phone A with a destination IP of 192.168.49.1.
[0343] 709d. The WiFi link module of tablet B sends a forwarding rule configuration command to the Netd module of tablet B.
[0344] The Netd module of tablet B can configure forwarding rules to the forwarding table (e.g., the filter table (of the FORWARD chain)).
[0345] 709e. The Netd module of tablet B returns the forwarding rule configuration result to the WiFi link module of tablet B.
[0346] The forwarding rule configuration result can be either success or failure. If the forwarding rule configuration result is failure, it can be retried once, i.e., the forwarding rule will be reconfigured. If the forwarding rule configuration result is success, the Netd module of tablet B can directly return the forwarding rule configuration result to the WiFi link module of tablet B.
[0347] 709f. The WiFi link module of tablet B returns the forwarding rule configuration result (success) to the MagicLink application module of tablet B.
[0348] Configure cross-segment bridging reference counting for the MagicLink application module of 709g and Tablet B.
[0349] After configuring the forwarding rules on tablet B, cross-network segment bridging information can be configured. This cross-network segment bridging information may include bridging identifier, initiating device ID (e.g., device ID of mobile phone C), intermediate device ID (e.g., device ID of tablet B), receiving device ID (e.g., device ID of mobile phone A), cross-network segment bridging reference count (first reference count), etc.
[0350] The cross-segment bridging reference count indicates the number of services corresponding to cross-segment bridging. Cross-segment bridging refers to a connection between two devices (the initiating device and the receiving device) via an intermediate device, where the two devices and the intermediate device are located in different network segments (or, the WiFi P2P connections established by the two devices and the intermediate device are in different network segments). For example, consider a connection established between mobile phone A and mobile phone C via tablet B. Mobile phone A, tablet B, and mobile phone C are in different network segments (i.e., the network segment corresponding to the WiFi P2P connection established by mobile phone A and tablet B is different from the network segment corresponding to the WiFi P2P connection established by mobile phone C and tablet B). The connection between mobile phone A and mobile phone C is established based on the cross-segment forwarding capability of tablet B.
[0351] In addition, tablet B can manage other types of reference counts, such as direct connection reference counts and intra-segment bridging reference counts. Direct connection reference counts indicate the number of services corresponding to a direct WiFi P2P connection between two devices. Intra-segment bridging reference counts indicate the number of services corresponding to intra-segment bridging. Intra-segment bridging refers to a connection between two devices via an intermediary device, where both devices and the intermediary device are on the same network segment (or, the WiFi P2P connections established by the two devices and the intermediary device are on the same network segment).
[0352] It should be noted that different types of reference counts are maintained independently, that is, direct-connection reference counts, cross-network segment bridging reference counts, and same-network segment bridging reference counts are maintained independently and do not interfere with each other.
[0353] 710. The MagicLink application module of tablet B sends routing configuration response information to the MagicLink application module of mobile phone A. The routing configuration response information is used to indicate the forwarding rule configuration result.
[0354] After receiving the forwarding rule configuration result (success) sent by tablet B, mobile phone A can configure the first routing rule. The relevant process is described in steps 711a-711e below.
[0355] 711a. The MagicLink application module of mobile phone A sends the first network segment and the first forwarding IP to the WiFi link module of mobile phone A.
[0356] The first network segment can be the network segment corresponding to mobile phone C, the first forwarding IP is the IP corresponding to the first network card of tablet B, and the first network card is the network card that tablet B uses to establish a WiFi P2P connection with mobile phone A.
[0357] For example, the first network segment can be 192.168.50.0 / 24 (referred to as the 50 network segment), and the first forwarding IP can be 192.168.49.101.
[0358] 711b. The WiFi link module of mobile phone A generates the first routing rule configuration instruction based on the first network segment and the first forwarding IP.
[0359] For example, the first routing rule configuration command is: ip route add 192.168.50.0 / 24via192.168.49.101.
[0360] The first routing rule configuration directive instructs all data packets destined for the 192.168.50.0 / 24 network segment to be forwarded through the network interface card with IP address 192.168.49.101. In other words, all data packets destined for the 192.168.50.0 / 24 network segment are sent to the network interface card with IP address 192.168.49.101.
[0361] 711c. The WiFi link module of mobile phone A sends the first routing rule configuration command to the Netd module of mobile phone A.
[0362] The Netd module of mobile phone A can add the routing rule (first routing rule) indicated by the first routing rule configuration command to the routing table.
[0363] 711d. The Netd module of mobile phone A returns the first routing rule configuration result to the WiFi link module of mobile phone A.
[0364] The first routing rule configuration result is used to indicate whether the routing rule indicated by the first routing rule configuration instruction has been configured successfully.
[0365] If the initial routing rule configuration fails, you can retry once, i.e., reconfigure the routing rule indicated by the initial routing rule configuration command. If the initial routing rule configuration succeeds, the Netd module of phone A can directly return the initial routing rule configuration result to the WiFi link module of phone A.
[0366] 711e. The WiFi link module of mobile phone A sends the first routing rule configuration result (success) to the MagicLink application module of mobile phone A.
[0367] 712. Configure cross-network segment bridging reference counting for the MagicLink application module of mobile phone A.
[0368] After configuring routing rules on mobile phone A, cross-network segment bridging information can be configured. This information may include a bridging identifier, the initiating device ID (e.g., the device ID of mobile phone C), the intermediate device ID (e.g., the device ID of tablet B), the receiving device ID (e.g., the device ID of mobile phone A), and the cross-network segment bridging reference count (first reference count). A description of the cross-network segment bridging reference count can be found in step 709g.
[0369] 713. The MagicLink application module of mobile phone A sends a P2P bridging response message to the MagicLink application module of mobile phone C.
[0370] After successfully configuring routing rules, mobile phone A can send P2P bridging response information to mobile phone C. This P2P bridging response information may include device information from mobile phone A, such as its device ID, MAC address, IP address, and MAC port.
[0371] The P2P bridging response information may also include device information of mobile phone A itself, such as mobile phone A's device ID, P2P role (GO or GC), MAC address, IP address, IP mask, etc. Optionally, the P2P bridging response information may also include other information, such as mobile phone A's MagicLink protocol version, connection type, etc., which are not specifically limited in this application.
[0372] In addition, after receiving the forwarding rule configuration result (failure) sent by tablet B, mobile phone A can return a bridging failure message to mobile phone C without configuring routing rules.
[0373] After receiving the P2P bridging response information (success) sent by mobile phone A, mobile phone C can configure the second routing rule. The relevant process is described in steps 714a-714e below.
[0374] 714a. The MagicLink application module of mobile phone C sends the second network segment and the second forwarding IP to the WiFi link module of mobile phone C.
[0375] Among them, the second network segment is the network segment corresponding to mobile phone A, the second forwarding IP is the IP corresponding to the second network card of tablet B, and the second network card is the network card that tablet B uses to establish a WiFi P2P connection with mobile phone C.
[0376] For example, the second network segment can be 192.168.49.0 / 24 (referred to as the 49 network segment), and the second forwarding IP can be 192.168.50.1.
[0377] 714b. The WiFi link module of mobile phone C generates a second routing rule configuration instruction.
[0378] For example, the second routing rule configuration command is: ip route add 192.168.49.0 / 24via192.168.50.1.
[0379] The second routing rule configuration command indicates that all data packets destined for the 192.168.49.0 / 24 network segment (referred to as the 49 network segment) should be forwarded through the network card with the IP address 192.168.50.1.
[0380] 714c, The WiFi link module of mobile phone C sends a second routing rule configuration command to the Netd module of mobile phone C.
[0381] The Netd module on mobile phone C can add the routing rule (second routing rule) indicated by the second routing rule configuration command to the routing table.
[0382] 714d, the Netd module of mobile phone C returns the second routing rule configuration result to the WiFi link module of mobile phone C.
[0383] The second routing rule configuration result is used to indicate whether the routing rule indicated by the second routing rule configuration command has been configured successfully.
[0384] If the second routing rule configuration fails, you can retry once, i.e., reconfigure the routing rule indicated by the second routing rule configuration command. If the second routing rule configuration succeeds, the Netd module of mobile phone C can directly return the second routing rule configuration result to the WiFi link module of mobile phone C.
[0385] 714e. The WiFi link module of mobile phone C sends the second routing rule configuration result to the MagicLink application module of mobile phone C (successfully).
[0386] 715. Configure cross-network segment bridging reference counting for the MagicLink application module of mobile phone A.
[0387] After configuring routing rules on mobile phone C, cross-network segment bridging information can be configured. This information may include a bridging identifier, the initiating device ID (e.g., the device ID of mobile phone C), the intermediate device ID (e.g., the device ID of tablet B), the receiving device ID (e.g., the device ID of mobile phone A), and the cross-network segment bridging reference count (first reference count). A description of the cross-network segment bridging reference count can be found in step 709g.
[0388] At this point, mobile phone C and mobile phone A have successfully completed cross-network segment bridging, and mobile phone C and mobile phone A can forward data based on the forwarding function of tablet computer B.
[0389] Based on the method provided in this application, mobile phone A and mobile phone C can achieve cross-network segment bridging through an intermediate device / public device (e.g., tablet B). Tablet B supports dual-path P2P capability (e.g., including at least two network cards, capable of establishing WiFi P2P connections with devices in different network segments (e.g., mobile phone A and mobile phone C) respectively), and can provide network segment forwarding capability for devices in different network segments, thereby enabling cross-network segment bridging between devices in different network segments. This allows communication between devices in different network segments using WiFi P2P technology, better meeting user needs and improving user experience.
[0390] In some embodiments, when the bridging between mobile phone A and mobile phone C is disconnected, tablet computer B can delete the forwarding rules and release the cross-segment bridging reference count, eliminating the need to maintain related information (forwarding rules and cross-segment bridging reference count), thus saving overhead and storage space and improving the performance of electronic devices.
[0391] like Figure 7B As shown, the method provided in this application embodiment may further include the following steps:
[0392] 720a. Mobile phone C sends a P2P bridge disconnection request message to mobile phone A.
[0393] The P2P bridge disconnection request message is used to request the disconnection of the bridge between mobile phone A and mobile phone C.
[0394] 720b. Mobile phone C can send a P2P bridge disconnection request message to tablet computer B.
[0395] For example, after the first service (e.g., screen sharing service) is completed, mobile phone C can actively release the WiFi P2P connection. Mobile phone C can send bridging disconnection request information to mobile phone A and tablet B respectively, in order to release the bridging between mobile phone A and mobile phone C (i.e., release the connection established between mobile phone A and mobile phone C through tablet B).
[0396] Alternatively, the bridging between phone A and phone C may be disrupted due to a network anomaly causing the WiFi P2P connection between tablet B and phone A to break, and / or the network anomaly causing the WiFi P2P connection between tablet B and phone C to break, which in turn leads to the bridging between phone A and phone C breaking.
[0397] In other embodiments, if the WiFi P2P connection between tablet B and mobile phone A is lost, or the WiFi P2P connection between tablet B and mobile phone C is lost, or the bridging between mobile phone A and mobile phone C is lost, tablet B can delete the forwarding rule and release the cross-network segment bridging reference count. The loss of the WiFi P2P connection between tablet B and mobile phone A can be due to a network anomaly, or it can be due to mobile phone A or tablet B actively releasing the WiFi P2P connection. Similarly, the loss of the WiFi P2P connection between tablet B and mobile phone C can be due to a network anomaly, or it can be due to mobile phone C or tablet B actively releasing the WiFi P2P connection.
[0398] 721a. The MagicLink application module of mobile phone A releases the cross-network segment bridging reference count.
[0399] After receiving the bridge disconnection request from mobile phone C, the MagicLink application module of mobile phone A can decrement the cross-network segment bridge reference count by one. When the cross-network segment bridge reference count is 0, step 721b can be executed.
[0400] 721b, Deletion of forwarding rules in the MagicLink application module of tablet B.
[0401] If tablet B detects (senses) that the WiFi P2P connection between tablet B and mobile phone A is broken, or the WiFi P2P connection between tablet B and mobile phone C is broken, or the bridging between mobile phone A and mobile phone C is broken (for example, receiving a bridging disconnection request message sent by mobile phone C), it can delete the forwarding rule.
[0402] Specifically, the WiFi link module of tablet B can assemble one or more forwarding rule deletion commands.
[0403] For example, a forwarding rule deletion command can include two lines, as follows:
[0404] Command 1: `iptables -D FORWARD -s 192.168.50.75 -d 192.168.49.1 -i P2P1 -o P2P0 -j ACCEPT` Command 2: `iptables -D FORWARD -s 192.168.49.1 -d 192.168.50.75 -i P2P0 -o P2P1 -j ACCEPT`
[0405] In this case, instruction 1 indicates that a rule is deleted from the FORWARD chain of the filter table. The matching conditions for this rule are that the source IP of the data packet is 192.168.49.1 (the IP of mobile phone A), the destination IP is 192.168.50.75 (the IP of mobile phone C), and the data packet is input from network card P2P0 and output from network card P2P1; the action is to allow (ACCEPT).
[0406] Command 2 indicates that a rule is deleted from the FORWARD chain of the filter table. The matching conditions for this rule are that the source IP of the packet is 192.168.50.75 (the IP of mobile phone C), the destination IP is 192.168.49.1 (the IP of mobile phone A), and the packet is input from network card P2P1 and output from network card P2P0; the action is to allow (ACCEPT).
[0407] The WiFi link module of tablet B can send a forwarding rule deletion command to the Netd module of tablet B. The Netd module of tablet B can then delete the corresponding forwarding rule from the forwarding table (e.g., the filter table (of the FORWARD chain)) based on the forwarding rule deletion command.
[0408] Optionally, the method may further include the following steps (steps 722a-724b):
[0409] 722a. The MagicLink application module of mobile phone A will decrement the cross-network segment bridging reference count by one.
[0410] After receiving the bridge disconnection request from mobile phone C, the MagicLink application module of mobile phone A can decrement the cross-network segment bridge reference count by one. When the cross-network segment bridge reference count is 0, step 722b can be executed.
[0411] 722b. The MagicLink application module of mobile phone A deletes the first routing rule.
[0412] After deleting the first routing rule in the MagicLink application module of mobile phone A, the cross-segment bridging reference count can be further released (cleared). In this way, mobile phone A no longer needs to maintain relevant information (forwarding rules and cross-segment bridging reference counts), which can save overhead and storage space and improve the performance of electronic devices.
[0413] 723. Mobile phone A can send a bridge disconnection response message to mobile phone C.
[0414] The bridging disconnection response message is used to indicate that mobile phone A agrees to disconnect the bridging with mobile phone C.
[0415] 724a. Mobile phone C will decrement the cross-network segment bridging reference count by one.
[0416] After receiving the bridging disconnection response information sent by mobile phone A, the MagicLink application module of mobile phone C can decrement the cross-network segment bridging reference count by one. When the cross-network segment bridging reference count is 0, step 724b can be executed.
[0417] 724b. The MagicLink application module of mobile phone A deletes the second routing rule.
[0418] Based on the method provided in this application embodiment, when the WiFi P2P connection between tablet B and mobile phone A is disconnected, or the WiFi P2P connection between tablet B and mobile phone C is disconnected, or the bridging between mobile phone A and mobile phone C is disconnected, tablet B can delete the forwarding rules and release the cross-network segment bridging reference count, eliminating the need to maintain related information (forwarding rules and cross-network segment bridging reference count), thus saving overhead and storage space and improving the performance of electronic devices.
[0419] One embodiment of this application provides a chip system, such as... Figure 10 As shown, the chip system includes at least one processor 1001 and at least one interface circuit 1002. The processor 1001 and the interface circuit 1002 are interconnected via lines. For example, the interface circuit 1002 can be used to receive signals from other devices (e.g., the memory of a first electronic device (e.g., mobile phone A), or the memory of a second electronic device (e.g., tablet computer B), or the memory of a third electronic device (e.g., mobile phone C)). As another example, the interface circuit 1002 can be used to send signals to other devices (e.g., the processor 1001).
[0420] For example, interface circuit 1002 can read instructions stored in the memory of the device and send the instructions to processor 1001. When the instructions are executed by processor 1001, a first electronic device (e.g., mobile phone A), a second electronic device (e.g., tablet B), or a third electronic device (e.g., mobile phone C) can perform the steps in the above embodiments.
[0421] Of course, the chip system may also include other discrete components, and this application does not specifically limit this.
[0422] Some embodiments of this application provide a communication system including a first electronic device, a second electronic device, and a third electronic device. The first electronic device establishes a first WiFi P2P connection with the second electronic device, and the second electronic device establishes a second WiFi P2P connection with the third electronic device. The first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments. The first electronic device, the second electronic device, and the third electronic device in this communication system can be used to perform the above-described functions. Figures 4A-9 The method.
[0423] Some embodiments of this application provide a first electronic device, which may include a communication module, a memory, and one or more processors. The communication module and the memory are coupled to the processors. The memory is used to store computer program code, which includes computer instructions.
[0424] Some embodiments of this application provide a second electronic device, which may include a communication module, a memory, and one or more processors. The communication module and the memory are coupled to the processors. The memory is used to store computer program code, which includes computer instructions.
[0425] Some embodiments of this application provide a third electronic device, which may include a communication module, a memory, and one or more processors. The communication module and the memory are coupled to the processors. The memory is used to store computer program code, which includes computer instructions.
[0426] This application also provides a computer-readable storage medium, which includes computer instructions, and the computer instructions are used in a first electronic device (such as...) Figure 2A When the computer instructions are executed on the second electronic device (e.g., mobile phone A), the electronic device 100 performs the various functions or steps performed by the first electronic device (e.g., mobile phone A) in the above method embodiment. Figure 2A When the computer instructions are executed on the electronic device 100 shown, the electronic device 100 performs the various functions or steps performed by the second electronic device (e.g., tablet B) in the above method embodiment. When the computer instructions are executed on the third electronic device (e.g.,...) Figure 2A When the electronic device 100 shown is run, it causes the electronic device 100 to perform the various functions or steps performed by the third electronic device (e.g., mobile phone C) in the above method embodiment.
[0427] This application also provides a computer program product that, when run on a computer, causes the computer to perform various functions or steps performed by the first electronic device (e.g., mobile phone A), the second electronic device (e.g., tablet computer B), or the third electronic device (e.g., mobile phone C) in the above method embodiments.
[0428] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0429] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0430] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0431] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0432] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0433] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A communication method, characterized in that, The method, applied to a communication system including a first electronic device, a second electronic device, and a third electronic device, comprises: The first electronic device establishes a first WiFi P2P connection with the second electronic device, and the second electronic device establishes a second WiFi P2P connection with the third electronic device. The first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments. The third electronic device receives a first operation, the first operation being used to initiate a first service to the first electronic device; The third electronic device sends a first request message to the first electronic device. The first request message is used to request to establish a connection with the third electronic device. The first request message includes relevant information about the device that establishes a WiFi P2P connection with the third electronic device. The device that establishes a WiFi P2P connection with the third electronic device includes the second electronic device. After receiving the first request information, the first electronic device sends a second request information to the second electronic device. The second request information is used to instruct the second electronic device to forward data packets for the first electronic device and the third electronic device. After receiving the second request information, the second electronic device configures a forwarding rule, which is used to instruct data packets whose source IP is the IP of the first electronic device to be forwarded to the third electronic device, and / or to forward data packets whose source IP is the IP of the third electronic device to the first electronic device; The second electronic device sends a first response message to the first electronic device, the first response message being used to indicate the configuration result of the forwarding rule; After receiving the first response information, the first electronic device configures a first routing rule, which is used to instruct data packets whose target IP is the IP of the third electronic device to be forwarded to the second electronic device; The first electronic device sends a second response message to the third electronic device, the second response message being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device; After receiving the second response information, the third electronic device configures a second routing rule, which is used to instruct data packets whose target IP is the IP of the first electronic device to be forwarded to the second electronic device.
2. The method according to claim 1, characterized in that, After receiving the first request information, the first electronic device sends a second request information to the second electronic device, including: The first electronic device traverses the devices that have established WiFi P2P connections with the first electronic device and the devices that have established WiFi P2P connections with the third electronic device to determine whether there are any public devices, including the second electronic device; In the presence of public devices, query whether the network segments corresponding to the WiFi P2P connections established by the public devices with the first electronic device and the third electronic device are the same; If the network segments corresponding to the WiFi P2P connections established by the public device with the first electronic device and the third electronic device are different, the first electronic device sends the second request information to the second electronic device.
3. The method according to claim 1 or 2, characterized in that, The second electronic device includes a second application module, a second WiFi link module, and a second network module. The forwarding rules configured in the second electronic device include: The second application module sends a source IP and a destination IP to the second WiFi link module, wherein the source IP is the IP of the first electronic device and the destination IP is the IP of the third electronic device; or, the source IP is the IP of the third electronic device and the destination IP is the IP of the first electronic device. The second WiFi link module queries the first network card used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the source IP, and the second network card used by the second electronic device to establish a WiFi P2P connection with the device corresponding to the destination IP; The second WiFi link module generates a forwarding rule configuration instruction, which is used to instruct the second electronic device to receive the data packet corresponding to the source IP through the first network card, and to send the data packet corresponding to the source IP from the second network card to the device indicated by the destination IP. The second WiFi link module sends the forwarding rule configuration command to the second network module; The second network module adds the forwarding rule configuration instruction to the forwarding table.
4. The method according to claim 3, characterized in that, The second application module stores a first reference count, which is used to indicate the number of services corresponding to the bridge. The bridge is a connection established between the first electronic device and the third electronic device through the second electronic device.
5. The method according to any one of claims 1-4, characterized in that, The first electronic device includes a first application module, a first WiFi link module, and a first network module. The first routing rule configured in the first electronic device includes: The first application module sends a first network segment and a first forwarding IP to the first WiFi link module. The first network segment is the network segment corresponding to the third electronic device, and the first forwarding IP is the IP corresponding to the first network card of the second electronic device. The first network card is the network card that establishes a WiFi P2P connection between the second electronic device and the first electronic device. The first WiFi link module generates a first routing rule configuration instruction, which is used to instruct data packets whose target IP belongs to the first network segment to be sent to the first network card of the second electronic device; The first WiFi link module sends the first routing rule configuration instruction to the first network module; The first network module adds the first routing rule configuration instruction to the first routing table.
6. The method according to claim 5, characterized in that, The first application module stores a first reference count, which is used to indicate the number of services corresponding to the bridging connection. The bridging connection refers to the connection established between the first electronic device and the third electronic device through the second electronic device.
7. The method according to any one of claims 1-6, characterized in that, The third electronic device includes a third application module, a third WiFi link module, and a third network module. The configuration of the first routing rule for the third electronic device includes: The third application module sends the second network segment and the second forwarding IP corresponding to the routing rule to the third WiFi link module. The second network segment is the network segment corresponding to the first electronic device, and the second forwarding IP is the IP corresponding to the second network card of the second electronic device. The second network card is the network card that establishes a WiFi P2P connection between the second electronic device and the third electronic device. The third WiFi link module generates a second routing rule configuration instruction, which is used to instruct data packets whose target IP belongs to the second network segment to be sent to the second network card of the second electronic device; The third WiFi link module sends the second routing rule configuration instruction to the third network module; The third network module adds the second routing rule configuration instruction to the second routing table.
8. The method according to claim 7, characterized in that, The third application module stores a first reference count, which is used to indicate the number of services corresponding to the bridging connection. The bridging connection refers to the connection established between the first electronic device and the third electronic device through the second electronic device.
9. The method according to any one of claims 1-8, characterized in that, The method further includes: If the first WiFi P2P connection is disconnected, or the second WiFi P2P connection is disconnected, or the connection between the first electronic device and the third electronic device is disconnected, the second electronic device deletes the forwarding rule.
10. The method according to claim 9, characterized in that, The method further includes: The second electronic device deletes the first reference count.
11. A communication method, characterized in that, Applied to a first electronic device, the method includes: The first electronic device establishes a WiFi P2P connection with the second electronic device; The first electronic device receives a first request information from the third electronic device. The first request information is used to request to establish a connection with the third electronic device. The first request information includes relevant information about the device that establishes a WiFi P2P connection with the first electronic device. The device that establishes a WiFi P2P connection with the first electronic device includes the second electronic device. If the network segment corresponding to the first electronic device is different from the network segment corresponding to the third electronic device, the first electronic device sends a second request message to the second electronic device. The second request message is used to instruct the second electronic device to forward data packets for the third electronic device and the first electronic device. The first electronic device receives first response information from the second electronic device. The first response information is used to indicate the configuration result of the forwarding rule. The forwarding rule is used to indicate that data packets with the source IP of the first electronic device are forwarded to the third electronic device, and / or that data packets with the source IP of the third electronic device are forwarded to the first electronic device. The first electronic device is configured with a first routing rule, which is used to instruct data packets whose destination IP is the IP of the third electronic device to be sent to the second electronic device; The first electronic device sends a second response message to the third electronic device, the second response message being used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device.
12. A communication method, characterized in that, Applied to a second electronic device, the method includes: The second electronic device establishes a first WiFi P2P connection with the first electronic device and a second WiFi P2P connection with the third electronic device. The first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments. The second electronic device receives a second request message from the third electronic device, the second request message being used to instruct the second electronic device to forward data packets for the first electronic device and the third electronic device; The second electronic device is configured with forwarding rules, which are used to instruct data packets whose source IP is the IP of the first electronic device to be forwarded to the third electronic device, and / or to forward data packets whose source IP is the IP of the third electronic device to the first electronic device.
13. A communication method, characterized in that, Applied to a third electronic device, the method includes: The third electronic device establishes a WiFi P2P connection with the second electronic device; The third electronic device receives a first operation, which is used to initiate a first service to the first electronic device; The third electronic device sends a first request message to the first electronic device. The first request message is used to request to establish a connection with the third electronic device. The first request message includes relevant information about the device that establishes a WiFi P2P connection with the first electronic device. The device that establishes a WiFi P2P connection with the first electronic device includes the second electronic device. The third electronic device receives a second response information from the first electronic device. The second response information is used to instruct the first electronic device to establish a connection with the third electronic device through the second electronic device. The network segment corresponding to the first electronic device is different from the network segment corresponding to the third electronic device. The third electronic device is configured with a second routing rule, which is used to instruct data packets whose destination IP is the IP of the first electronic device to be sent to the second electronic device.
14. A communication system, characterized in that, The system includes a first electronic device, a second electronic device, and a third electronic device. The first electronic device establishes a first WiFi P2P connection with the second electronic device, and the second electronic device establishes a second WiFi P2P connection with the third electronic device. The first WiFi P2P connection and the second WiFi P2P connection correspond to different network segments. The communication system is used to perform the method as described in any one of claims 1-10.
15. An electronic device, characterized in that, The electronic device includes: a wireless communication module, a memory, and one or more processors; the wireless communication module, the memory, and the processor are coupled together. The memory is used to store computer program code, which includes computer instructions; when the computer instructions are executed by the processor, the electronic device performs the method as described in any one of claims 11-13.
16. A computer-readable storage medium, characterized in that, Includes computer instructions; When the computer instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 11-13.
17. A computer program product, characterized in that, When the computer program product is run on a routing device, it causes the routing device to perform the method as described in any one of claims 11-13.