WO2019153869A1 - Wifi connection method and apparatus - Google Patents

Wifi connection method and apparatus Download PDF

Info

Publication number
WO2019153869A1
WO2019153869A1 PCT/CN2018/120311 CN2018120311W WO2019153869A1 WO 2019153869 A1 WO2019153869 A1 WO 2019153869A1 CN 2018120311 W CN2018120311 W CN 2018120311W WO 2019153869 A1 WO2019153869 A1 WO 2019153869A1
Authority
WO
WIPO (PCT)
Prior art keywords
character
address
electronic device
preset
nibble
Prior art date
Application number
PCT/CN2018/120311
Other languages
French (fr)
Chinese (zh)
Inventor
章浙锋
Original Assignee
杭州海康威视数字技术股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州海康威视数字技术股份有限公司 filed Critical 杭州海康威视数字技术股份有限公司
Publication of WO2019153869A1 publication Critical patent/WO2019153869A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/10Mapping addresses of different types
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/35Network arrangements, protocols or services for addressing or naming involving non-standard use of addresses for implementing network functionalities, e.g. coding subscription information within the address or functional addressing, i.e. assigning an address to a function
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5069Address allocation for group communication, multicast communication or broadcast communication
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/11Allocation or use of connection identifiers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2101/00Indexing scheme associated with group H04L61/00
    • H04L2101/60Types of network addresses
    • H04L2101/618Details of network addresses
    • H04L2101/622Layer-2 addresses, e.g. medium access control [MAC] addresses

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

Provided are a WiFi connection method and apparatus, for use in a first electronic device. The method comprises: for each character in a first character string and a second character string, encoding the character to obtain an IP address corresponding to the character, wherein the first character string is a service set identifier of a WiFi network to be accessed by a second electronic device, and the second character string is the password of the WiFi network to be accessed by the second electronic device; mapping an IP address corresponding to each character to a MAC address; and periodically sending each MAC address obtained by means of mapping and which serves as a multicast frame of a destination address to the second electronic device, so that the second electronic device captures and parses the multicast frame, and obtains the service set identifier and the password, so as to access the WiFi network according to the service set identifier and the password. A device can quickly access a WiFi network by using the solution provided in the embodiments of the present application.

Description

一种WiFi连接方法及装置WiFi connection method and device
本申请要求于2018年2月6日提交中国专利局、申请号为201810118969.7发明名称为“一种WiFi连接方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 20110111896, filed on Feb. 6, 2018, the entire disclosure of which is incorporated herein by reference.
技术领域Technical field
本申请涉及无线通信技术领域,特别是涉及一种WiFi连接方法及装置。The present application relates to the field of wireless communication technologies, and in particular, to a WiFi connection method and apparatus.
背景技术Background technique
目前,各种电子设备的使用越来越广泛,一些情况下,需要两台电子设备进行连接,以便上述两台电子设备中的一台电子设备控制另一台电子设备,例如,用户在使用可穿戴设备时通常会将可穿戴设备与手持设备(比如手机)进行连接,以便于通过手持设备操作和控制可穿戴设备。At present, various electronic devices are used more and more widely. In some cases, two electronic devices are required to be connected, so that one of the two electronic devices controls another electronic device, for example, the user is using When the device is worn, the wearable device is typically connected to a handheld device, such as a cell phone, to facilitate operation and control of the wearable device through the handheld device.
现有技术中,手持设备和可穿戴设备之间可以采用WiFi连接,例如,以手持设备作为WiFi热点,可穿戴设备通过连接该WiFi热点,与手持设备实现WiFi连接,或者,通过手持设备和可穿戴设备均连接同一WiFi网络,实现两个设备的WiFi连接。也就是说,这两种方式均需要将可穿戴设备接入WiFi网络。In the prior art, a WiFi connection may be adopted between the handheld device and the wearable device, for example, the handheld device is used as a WiFi hotspot, and the wearable device implements a WiFi connection with the handheld device by connecting the WiFi hotspot, or through the handheld device and The wearable devices are all connected to the same WiFi network to implement WiFi connection between the two devices. That is to say, both methods need to connect the wearable device to the WiFi network.
但是,这两种可穿戴设备接入WiFi网络的方案,需要用户手动在可穿戴设备上配置WiFi热点或WiFi网络的WiFi参数(包括SSID(Service Set Identifier,服务集标识)和PWD(Pass Word,密码)),而手动配置WiFi参数的方式比较麻烦,导致可穿戴设备不能快速接入WiFi网络。However, the scheme for the two types of wearable devices to access the WiFi network requires the user to manually configure the WiFi hotspot or the WiFi network WiFi parameters (including the SSID (Service Set Identifier) and the PWD (Pass Word,) on the wearable device. Password)), and the manual configuration of WiFi parameters is cumbersome, resulting in the wearable device not being able to quickly access the WiFi network.
发明内容Summary of the invention
本申请实施例的目的在于提供一种WiFi连接方法及装置、电子设备、计算机可读存储介质,以实现设备快速接入WiFi网络。具体技术方案如下:The purpose of the embodiment of the present application is to provide a WiFi connection method and device, an electronic device, and a computer readable storage medium, so as to implement fast access of the device to the WiFi network. The specific technical solutions are as follows:
为达到上述目的,本申请实施例提供了一种WiFi连接方法,应用于第一电子设备,所述方法包括:To achieve the above objective, the embodiment of the present application provides a WiFi connection method, which is applied to a first electronic device, where the method includes:
针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi 网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;For each character in the first character string and the second character string, the character is encoded to obtain an IP address corresponding to the character, where the first character string is: a WiFi network to be accessed by the second electronic device The service set identifier, the second character string is: a password of a WiFi network to be accessed by the second electronic device;
将每一字符对应的IP地址映射为MAC地址;Mapping the IP address corresponding to each character to a MAC address;
周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。And periodically transmitting, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, and obtains the service set identifier and the Said password, accessing said WiFi network according to said service set identifier and said password.
可选的,所述针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址的步骤,包括:Optionally, the step of encoding the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character includes:
根据所述字符所在字符串的类别,确定所述字符对应的IP地址的第一预设比特位的取值;Determining, according to a category of the character string in which the character is located, a value of a first preset bit of the IP address corresponding to the character;
根据所述字符在字符串中的顺序号,确定所述字符对应的IP地址的第二预设比特位的取值;Determining, according to the sequence number of the character in the character string, a value of a second preset bit of the IP address corresponding to the character;
根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值,其中,所述第一预设比特位、所述第二预设比特位和所述第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。Determining, by the content of the character, a value of a third preset bit of the IP address corresponding to the character, where the first preset bit, the second preset bit, and the third The sum of the number of bits of the preset bit is determined by the mapping relationship between the IP address and the MAC address.
可选的,所述第三预设比特位的数量大于等于16位;Optionally, the number of the third preset bits is greater than or equal to 16 bits;
所述根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值的步骤,包括:The determining, according to the content of the character, the value of the third preset bit of the IP address corresponding to the character, includes:
根据第一码值的高半字节和低半字节,将所述字符编码为两个字节,其中,所述第一码值为:所述字符在预设编码规则中对应的码值;Encoding the character into two bytes according to a high nibble and a low nibble of the first code value, where the first code value is: a code value corresponding to the character in a preset encoding rule ;
根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值。And determining, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character.
可选的,所述根据第一码值的高半字节和低半字节,将所述字符编码为两个字节的步骤,包括:Optionally, the step of encoding the character into two bytes according to the high nibble and the low nibble of the first code value, including:
根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,所述第二码值为:所述字符所在字符串中的上一字符在预设编码规则中对应 的码值;Determining, according to a lower nibble of the second code value, a high nibble of the first byte of the two bytes, wherein the second code value is: a previous character in the character string of the character is in advance Set the corresponding code value in the coding rule;
根据第一码值的高半字节,确定所述第一字节的低半字节;Determining a lower nibble of the first byte according to a high nibble of the first code value;
根据第一码值的高半字节,确定两个字节中第二字节的高半字节;Determining a high nibble of a second byte of the two bytes according to a high nibble of the first code value;
根据第一码值的低半字节,确定所述第二字节的低半字节;Determining a lower nibble of the second byte according to a lower nibble of the first code value;
所述根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值的步骤,包括:And the step of determining, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character, including:
将所述第一字节确定为所述第三预设比特位中第一预设8比特位的取值;Determining, by the first byte, a value of a first preset 8-bit in the third preset bit;
将所述第二字节确定为所述第三预设比特位中第二预设8比特位的取值。Determining, by the second byte, a value of a second preset 8-bit in the third preset bit.
可选的,所述方法还包括:Optionally, the method further includes:
接收所述第二电子设备反馈的成功接入所述WiFi网络的信息,结束所述周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧的步骤。Receiving the information that the second electronic device feeds back successfully to the WiFi network, and ending the step of periodically transmitting, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address.
为达到上述目的,本申请实施例还提供了一种WiFi连接装置,应用于第一电子设备,所述装置包括:To achieve the above objective, the embodiment of the present application further provides a WiFi connection device, which is applied to a first electronic device, where the device includes:
编码模块,用于针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;The encoding module is configured to encode the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character, where the first character string is: the second electronic device is to be a service set identifier of the accessed WiFi network, where the second character string is: a password of the WiFi network to be accessed by the second electronic device;
映射模块,用于将每一字符对应的IP地址映射为MAC地址;a mapping module, configured to map an IP address corresponding to each character to a MAC address;
发送模块,用于周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。a sending module, configured to periodically send, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, to obtain the The service set identifier and the password are accessed according to the service set identifier and the password to the WiFi network.
可选的,所述编码模块,包括:Optionally, the encoding module includes:
第一确定子模块,用于根据所述字符所在字符串的类别,确定所述字符对应的IP地址的第一预设比特位的取值;a first determining submodule, configured to determine, according to a category of the character string in which the character is located, a value of a first preset bit of the IP address corresponding to the character;
第二确定子模块,用于根据所述字符在字符串中的顺序号,确定所述字符对应的IP地址的第二预设比特位的取值;a second determining submodule, configured to determine, according to the sequence number of the character in the character string, a value of a second preset bit of the IP address corresponding to the character;
第三确定子模块,用于根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值,其中,所述第一预设比特位、所述第二预设比特位和所述第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。a third determining submodule, configured to determine, according to the content of the character, a value of a third preset bit of the IP address corresponding to the character, where the first preset bit and the second pre The sum of the bits of the bit and the third predetermined bit is determined by the mapping relationship between the IP address and the MAC address.
可选的,所述第三预设比特位的数量大于等于16位;Optionally, the number of the third preset bits is greater than or equal to 16 bits;
所述第三确定子模块,包括:The third determining submodule includes:
编码单元,用于根据第一码值的高半字节和低半字节,将所述字符编码为两个字节,其中,所述第一码值为:所述字符在预设编码规则中对应的码值;a coding unit, configured to encode the character into two bytes according to a high nibble and a low nibble of the first code value, where the first code value is: the character is in a preset encoding rule Corresponding code value;
确定单元,用于根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值。And a determining unit, configured to determine, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character.
可选的,所述编码单元,包括:Optionally, the coding unit includes:
第一确定子单元,用于根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,所述第二码值为:所述字符所在字符串中的上一字符在预设编码规则中对应的码值;a first determining subunit, configured to determine a high nibble of the first byte of the two bytes according to a lower nibble of the second code value, where the second code value is: a character of the character The code value corresponding to the previous character in the string in the preset encoding rule;
第二确定子单元,用于根据第一码值的高半字节,确定所述第一字节的低半字节;a second determining subunit, configured to determine a lower nibble of the first byte according to a high nibble of the first code value;
第三确定子单元,用于根据第一码值的高半字节,确定两个字节中第二字节的高半字节;a third determining subunit, configured to determine a high nibble of the second byte of the two bytes according to the high nibble of the first code value;
第四确定子单元,用于根据第一码值的低半字节,确定所述第二字节的低半字节;a fourth determining subunit, configured to determine a lower nibble of the second byte according to a lower nibble of the first code value;
所述确定单元,包括:The determining unit includes:
第五确定子单元,用于将所述第一字节确定为所述第三预设比特位中第一预设8比特位的取值;a fifth determining subunit, configured to determine the first byte as a value of a first preset 8-bit in the third preset bit;
第六确定子单元,用于将所述第二字节确定为所述第三预设比特位中第二预设8比特位的取值。And a sixth determining subunit, configured to determine the second byte as a value of a second preset 8-bit in the third preset bit.
可选的,所述装置还包括:Optionally, the device further includes:
接收模块,用于接收所述第二电子设备反馈的成功接入所述WiFi网络的信息,结束所述发送模块执行周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧的步骤。a receiving module, configured to receive information that the second electronic device feeds back successfully to the WiFi network, and end the sending module to periodically send each MAC address obtained by mapping to the second electronic device as a destination address. The step of multicasting frames.
为达到上述目的,本申请实施例还提供了一种电子设备,包括处理器、通信接口、存储器和通信总线,其中,处理器,通信接口,存储器通过通信总线完成相互间的通信;In order to achieve the above objective, an embodiment of the present application further provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete communication with each other through a communication bus;
存储器,用于存放计算机程序;a memory for storing a computer program;
处理器,用于执行存储器上所存放的程序时,实现上述任一所述的应用于第一电子设备的WiFi连接方法。The processor, when used to execute the program stored on the memory, implements the WiFi connection method applied to the first electronic device according to any one of the foregoing.
为达到上述目的,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现上述任一所述的应用于第一电子设备的WiFi连接方法。To achieve the above objective, the embodiment of the present application further provides a computer readable storage medium, where the computer readable storage medium stores a computer program, and when the computer program is executed by the processor, implements any of the applications described above. A WiFi connection method for the first electronic device.
本申请实施例提供的方案,第一电子设备将第二电子设备待接入的WiFi网络的服务集标识和密码中的各个字符编码为IP地址,并映射为MAC地址,然后发送由各个MAC地址作为目的地址的组播帧,这样,第二电子设备可以抓取并解析组播帧获得服务器标识和密码,从而接入WiFi网络。可见,本申请实施例提供方案,不需要手动在第二电子设备上配置WiFi参数,即可实现第二电子设备快速接入WiFi网络。In the solution provided by the embodiment of the present application, the first electronic device encodes each character in the service set identifier and password of the WiFi network to be accessed by the second electronic device into an IP address, and maps to a MAC address, and then sends each MAC address. As the multicast frame of the destination address, the second electronic device can capture and parse the multicast frame to obtain the server identifier and password, thereby accessing the WiFi network. It can be seen that the embodiment of the present application provides a solution that the second electronic device can be quickly accessed into the WiFi network without manually configuring the WiFi parameter on the second electronic device.
附图说明DRAWINGS
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings to be used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are only It is a certain embodiment of the present application, and other drawings can be obtained according to the drawings without any creative work for those skilled in the art.
图1为本申请实施例提供的一种WiFi连接方法的流程示意图;FIG. 1 is a schematic flowchart of a WiFi connection method according to an embodiment of the present application;
图2为图1所示实施例中对字符进行编码的流程示意图;2 is a schematic flow chart of encoding characters in the embodiment shown in FIG. 1;
图3为本申请实施例提供的另一种WiFi连接方法的流程示意图;FIG. 3 is a schematic flowchart of another WiFi connection method according to an embodiment of the present disclosure;
图4为图3所示实施例中对IP地址进行反编码的流程示意图;4 is a schematic flow chart of inverse encoding an IP address in the embodiment shown in FIG. 3;
图5为本申请实施例提供的一种WiFi连接装置的结构示意图;FIG. 5 is a schematic structural diagram of a WiFi connection apparatus according to an embodiment of the present application;
图6为图5所示实施例中编码模块的结构示意图;6 is a schematic structural diagram of an encoding module in the embodiment shown in FIG. 5;
图7为本申请实施例提供的另一种WiFi连接装置的结构示意图;FIG. 7 is a schematic structural diagram of another WiFi connection apparatus according to an embodiment of the present disclosure;
图8为图7所示实施例中解析模块的结构示意图;8 is a schematic structural diagram of a parsing module in the embodiment shown in FIG. 7;
图9为本申请实施例提供的一种电子设备的结构示意图;FIG. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure;
图10为本申请实施例提供的另一种电子设备的结构示意图。FIG. 10 is a schematic structural diagram of another electronic device according to an embodiment of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
为解决现有技术的问题,本申请实施例提供了一种WiFi连接方法、装置电子设备、计算机可读存储介质。To solve the problem of the prior art, the embodiment of the present application provides a WiFi connection method, a device electronic device, and a computer readable storage medium.
下面对本申请实施例提供的一种WiFi连接方法进行介绍。A WiFi connection method provided by an embodiment of the present application is introduced below.
参见图1,图1为本申请实施例提供的一种WiFi连接方法的流程示意图,该方法应用于第一电子设备,包括如下步骤:Referring to FIG. 1 , FIG. 1 is a schematic flowchart of a WiFi connection method according to an embodiment of the present application. The method is applied to a first electronic device, and includes the following steps:
S101,针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址。S101. Encode the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character.
其中,第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,第二字符串为:第二电子设备待接入的WiFi网络的密码。服务集标识是指唯一命名WiFi网络的一串字符。The first character string is: a service set identifier of the WiFi network to be accessed by the second electronic device, and the second character string is a password of the WiFi network to be accessed by the second electronic device. A service set identifier is a string of characters that uniquely name a WiFi network.
本步骤中,对第一字符串和第二字符串中的各个字符分别进行编码,得到每一字符的编码结果,然后对于每一字符而言,采用这一字符的编码结果, 得到一个IP地址,作为这一字符对应的IP地址。In this step, each character in the first character string and the second character string is separately encoded to obtain an encoding result of each character, and then for each character, the encoding result of the character is used to obtain an IP address. , as the IP address corresponding to this character.
在一种实现方式中,可以利用第一电子设备中的预设应用软件来对第一字符串和第二字符串中的字符分别进行编码,得到各个字符对应的编码结果。In an implementation manner, the preset characterizing software in the first electronic device may be used to separately encode the characters in the first character string and the second character string to obtain an encoding result corresponding to each character.
或者,一种实现方式中,对字符进行编码时,也可以是按照预设的码表进行编码,得到字符的编码结果,例如,上述预设的码表可以是ASCII码表等等。Alternatively, in an implementation manner, when encoding a character, the encoding may be performed according to a preset code table to obtain a result of encoding the character. For example, the preset code table may be an ASCII code table or the like.
一种实现方式中,上述第一电子设备可以是手机、电脑、平板电脑等智能终端,上述第二电子设备可以是手机、电脑、平板电脑等智能终端,当然还可以是智能手环、智能手表、智能眼镜等可穿戴设备。In an implementation manner, the first electronic device may be a smart terminal such as a mobile phone, a computer, or a tablet computer, and the second electronic device may be a smart terminal such as a mobile phone, a computer, a tablet computer, or a smart wristband or a smart watch. Wearable devices such as smart glasses.
S102,将每一字符对应的IP地址映射为MAC地址。S102. Map an IP address corresponding to each character to a MAC address.
在一种实现方式中,可以将IP地址中的预设比特位直接复制到MAC地址的预设比特位,得到映射后的MAC地址。In an implementation manner, the preset bit in the IP address can be directly copied to the preset bit of the MAC address to obtain the mapped MAC address.
举例而言,以32比特位的IP地址(Internet Protocol Address,互联网协议地址)和48比特位的MAC地址(Media Access Control Address,物理地址)为例:For example, a 32-bit IP address (Internet Protocol Address) and a 48-bit MAC address (Media Access Control Address) are used as examples:
在组播这种数据发送方式中,IP地址是以1110开头的D类地址,由1110和多播组号构成,范围是从224.0.0.0到239.255.255.255,而32比特位的IP地址和48比特位的MAC地址之间的转换存在着固定的规则,MAC地址的高24比特位为01:00:5e,第23比特位为0,将IP地址的低23比特位直接复制到MAC地址的低23比特位可以形成组播帧的MAC地址。由于IP地址的高4比特位为1110,低23比特位复制到MAC地址的低23比特位,因此IP地址中间有5个比特位没有使用到,这样一来IP地址和MAC地址就不是一一对应的,一个MAC地址最多可以映射出32个IP地址。但是,可以将IP地址中间的5个比特位设置为固定值,即可实现一个MAC地址映射出一个IP地址。In the multicast data transmission mode, the IP address is a class D address beginning with 1110, consisting of 1110 and a multicast group number, ranging from 224.0.0.0 to 239.255.255.255, and the 32-bit IP address and 48. There is a fixed rule for the conversion between the MAC addresses of the bits. The upper 24 bits of the MAC address are 01:00:5e, the 23rd bit is 0, and the lower 23 bits of the IP address are directly copied to the MAC address. The lower 23 bits can form the MAC address of the multicast frame. Since the upper 4 bits of the IP address are 1110, the lower 23 bits are copied to the lower 23 bits of the MAC address, so 5 bits in the middle of the IP address are not used, so that the IP address and the MAC address are not one by one. Correspondingly, a MAC address can map up to 32 IP addresses. However, you can set a MAC address to map an IP address by setting the 5 bits in the middle of the IP address to a fixed value.
S103,周期性向第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得第二电子设备抓取并解析组播帧,获得服务集标识和密码,根据服务集标识和密码接入WiFi网络。S103. The multicast frame that is obtained by mapping each MAC address as the destination address is periodically sent to the second electronic device, so that the second electronic device captures and parses the multicast frame to obtain the service set identifier and the password, according to the service set identifier and The password is connected to the WiFi network.
在一种实现方式中,第二电子设备可以抓取第一电子设备发送的组播帧并进行解析,得到各个组播帧中的MAC地址,根据IP地址和MAC地址的映射关系,得到各个MAC地址对应的IP地址,再对各个IP地址反编码,得到各个IP地址对应的字符,进而根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码,最后根据服务集标识和密码接入WiFi网络。In an implementation manner, the second electronic device may capture the multicast frame sent by the first electronic device and perform parsing to obtain a MAC address in each multicast frame, and obtain each MAC according to the mapping relationship between the IP address and the MAC address. The IP address corresponding to the address is de-encoded for each IP address, and the characters corresponding to each IP address are obtained. Then, the service set identifier and password of the WiFi network to be accessed are determined according to the characters corresponding to each IP address, and finally, according to the service set identifier and The password is connected to the WiFi network.
本申请实施例提供的方案可以应用在多种场景中。The solution provided by the embodiment of the present application can be applied in various scenarios.
例如,第二电子设备待接入的WiFi网络可以为第一电子设备自身已接入的WiFi网络,或者,第二电子设备待接入的WiFi网络也可以不是第一电子设备当前所接入的WiFi网络,这两种应用场景中,WiFi网络都需要依赖于路由器来创建。For example, the WiFi network to be accessed by the second electronic device may be the WiFi network that the first electronic device has accessed, or the WiFi network to be accessed by the second electronic device may not be currently accessed by the first electronic device. WiFi network, in both scenarios, WiFi networks need to rely on routers to create.
再如,若第一电子设备为手持设备,则可以以第一电子设备作为WiFi热点,第二电子设备接入该WiFi热点,此时,第二电子设备可以通过第一电子设备的3G或4G网络进行数据传输,例如上传数据到互联网。这种应用场景中,第一电子设备与第二电子设备之间的WiFi连接摆脱了对路由器的依赖,在没有路由器的情况下仍可以保持第一电子设备和第二电子设备的WiFi连接,并且与其它需要借助路由器来实现第二电子设备接入WiFi网络的方式相比,可以更加简洁、方便的接入WiFi网络。For example, if the first electronic device is a handheld device, the first electronic device can be used as a WiFi hotspot, and the second electronic device can access the WiFi hotspot. At this time, the second electronic device can pass the 3G or 4G of the first electronic device. The network performs data transmission, such as uploading data to the Internet. In such an application scenario, the WiFi connection between the first electronic device and the second electronic device is free from the dependence on the router, and the WiFi connection of the first electronic device and the second electronic device can still be maintained without the router, and Compared with other methods that need to use a router to implement the second electronic device to access the WiFi network, the WiFi network can be accessed more simply and conveniently.
可以理解的,当第二电子设备接入WiFi网络后,第一电子设备则不必要继续发送由各个MAC地址作为目的地址的组播帧,基于此,在一种具体实施方式中,该方法还可以包括:接收第二电子设备反馈的成功接入WiFi网络的信息,结束发送由映射得到的各个MAC地址作为目的地址的组播帧。这样,可以进一步节约网络资源。It can be understood that, after the second electronic device accesses the WiFi network, the first electronic device does not need to continue to send the multicast frame with each MAC address as the destination address. Based on this, in a specific implementation manner, the method further The method may include: receiving information of the successful access to the WiFi network fed back by the second electronic device, and ending sending the multicast frame with each MAC address obtained by the mapping as the destination address. In this way, network resources can be further saved.
综上所述,本申请实施例提供的方案,第一电子设备将第二电子设备待接入的WiFi网络的服务集标识和密码中的各个字符编码为IP地址,并映射为MAC地址,然后发送由各个MAC地址作为目的地址的组播帧,这样,第二电子设备可以抓取并解析组播帧,获得服务器标识和密码,从而接入WiFi网络。可见,本申请实施例提供方案,不需要手动在第二电子设备上配置WiFi参数,即可实现第二电子设备快速接入WiFi网络。In summary, in the solution provided by the embodiment of the present application, the first electronic device encodes each character in the service set identifier and password of the WiFi network to be accessed by the second electronic device into an IP address, and maps to a MAC address, and then maps to a MAC address, and then A multicast frame is sent from each MAC address as a destination address, so that the second electronic device can capture and parse the multicast frame, obtain the server identifier and password, and access the WiFi network. It can be seen that the embodiment of the present application provides a solution that the second electronic device can be quickly accessed into the WiFi network without manually configuring the WiFi parameter on the second electronic device.
在第二电子设备为可穿戴设备时,由于在可穿戴设备上不便于配置WiFi参数,而应用本申请实施例提供的方案,不需要在可穿戴设备上配置WiFi参数就可以使可穿戴设备接入WiFi网络,可见本申请实施例提供的方案便于可穿戴设备接入WiFi网络。进一步的,若第一电子设备为手持设备并且以手持设备作为WiFi热点,而可穿戴设备需要接入该WiFi热点实现两个设备的WiFi连接,则应用本申请实施例提供的方案可以快速使任意一个手持设备和可穿戴设备互联。When the second electronic device is a wearable device, the WiFi parameter is not conveniently configured on the wearable device, and the solution provided by the embodiment of the present application is applied, and the wearable device can be connected without configuring the WiFi parameter on the wearable device. The solution provided in the embodiment of the present application is convenient for the wearable device to access the WiFi network. Further, if the first electronic device is a handheld device and the handheld device is used as a WiFi hotspot, and the wearable device needs to access the WiFi hotspot to implement the WiFi connection of the two devices, the solution provided by the embodiment of the present application can be quickly made arbitrary. A handheld device and a wearable device are interconnected.
下面详细介绍步骤S101中针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址的一种实现方式。The following describes in detail, in step S101, an implementation of encoding the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character.
具体的,如图2所示,按照以下步骤,获得第一字符串和第二字符串中每一字符对应的IP地址:Specifically, as shown in FIG. 2, the IP address corresponding to each character in the first character string and the second character string is obtained according to the following steps:
S1011,根据字符所在字符串的类别,确定字符对应的IP地址的第一预设比特位的取值;S1011: Determine, according to a category of the character string in which the character is located, a value of a first preset bit of the IP address corresponding to the character;
其中,对于待编码的任一字符,若该字符为第一字符串中的字符,则该字符所在字符串的类别为服务集标识,若该字符为第二字符串中的字符,则该字符所在字符串的类别为密码;If any character to be encoded is a character in the first string, the category of the string in which the character is located is a service set identifier, and if the character is a character in the second string, the character The category of the string is the password;
S1012,根据字符在字符串中的顺序号,确定字符对应的IP地址的第二预设比特位的取值;S1012: Determine, according to a sequence number of the character in the character string, a value of a second preset bit of the IP address corresponding to the character;
S1013,根据字符的内容,确定字符对应的IP地址的第三预设比特位的取值;S1013: Determine, according to the content of the character, a value of a third preset bit of the IP address corresponding to the character;
其中,第一预设比特位、第二预设比特位和第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。在一种实现方式中,IP地址与MAC地址的映射关系可以为:将IP地址映射到MAC地址时是将IP地址的低23比特位直接复制到MAC地址的低23比特位。The sum of the first preset bit, the second preset bit, and the third preset bit is determined by a mapping relationship between the IP address and the MAC address. In an implementation manner, the mapping relationship between the IP address and the MAC address may be: when mapping the IP address to the MAC address, the lower 23 bits of the IP address are directly copied to the lower 23 bits of the MAC address.
一种实现方式中,可以由IP地址与MAC地址的映射关系以及IP地址的比特位总数,确定IP地址中用于标识字符的编码结果的比特位。In an implementation manner, the bit number of the IP address used to identify the encoding result of the character may be determined by the mapping relationship between the IP address and the MAC address and the total number of bits of the IP address.
举例而言,在IP地址为32比特位,并且IP地址映射到MAC地址时是将 IP地址的低23比特位直接复制到MAC地址的低23比特位的情况下,可以将IP地址的低23比特位用于标识字符的编码结果,而将IP地址的高9比特位设置为固定值。由于在组播中IP地址的高4比特位总是1110,因此可以设置IP地址的高8位为固定值,范围为224~239。而IP地址的第23比特位也可以设置为固定值,例如设置为0或为1。For example, when the IP address is 32 bits and the IP address is mapped to the MAC address, the lower 23 bits of the IP address are directly copied to the lower 23 bits of the MAC address, and the IP address can be lower 23 The bit is used to identify the encoding result of the character, and the high 9 bits of the IP address are set to a fixed value. Since the upper 4 bits of the IP address are always 1110 in multicast, the upper 8 bits of the IP address can be set to a fixed value ranging from 224 to 239. The 23rd bit of the IP address can also be set to a fixed value, for example, set to 0 or 1.
在IP地址中用于标识字符的编码结果的比特位中,可以将第一预设比特位用于标记字符所在字符串的类别,即标记该字符是位于服务集标识中还是位于密码中,将第二预设比特位用于标记字符在字符串中的顺序号,将第三预设比特位用于标记字符所表示的具体内容。In the bit of the IP address used to identify the encoding result of the character, the first preset bit may be used to mark the category of the character string in which the character is located, that is, whether the character is located in the service set identifier or in the password, The second preset bit is used to mark the sequence number of the character in the character string, and the third preset bit is used to mark the specific content represented by the character.
对于第一预设比特位,举例而言,若IP地址为32比特位且低23比特位用于标识字符的编码结果,可以将IP地址的1个比特位作为第一预设比特位,例如第22比特位,具体为:第22比特位为0,表示字符所在字符串为服务集标识,第22比特位为1,表示字符所在字符串为密码。也可以将IP地址中的两个比特位作为第一预设比特位,例如第22、21比特位,具体为:第22、21比特位为00,表示字符所在字符串为服务集标识,第22、21比特位为01,表示字符所在字符串为密码。当然,在具体实施时,第一预设比特位的位数和位置可以按照需要进行设定,本申请实施例对此不做限定。For the first preset bit, for example, if the IP address is 32 bits and the lower 23 bits are used to identify the encoding result of the character, one bit of the IP address may be used as the first preset bit, for example, The 22nd bit is specifically: the 22nd bit is 0, indicating that the character string of the character is the service set identifier, and the 22nd bit is 1, indicating that the character string of the character is a password. The two bits in the IP address may also be used as the first preset bit, for example, the 22nd and 21st bits, specifically: the 22nd and 21st bits are 00, indicating that the character string is the service set identifier, 22, 21 bits are 01, indicating that the character string is a password. Certainly, in the specific implementation, the number of bits and the position of the first preset bit can be set as needed, which is not limited in this embodiment of the present application.
对于第二预设比特位,举例而言,若IP地址为32比特位且低23比特位用于标识字符的编码结果,可以将低23比特位中除第一预设比特位外的若干个比特位作为第二预设比特位。以第二预设比特位的位数为3为例,顺序号为1时第二预设比特位可以表示为000,顺序号为2时第二预设比特位可以表示为001,以此类推。可以理解的,第二预设比特位的位数与字符串最多可包含的字符的数量相关,若字符串最多可包含的的字符数量越多,则第二预设比特位的位数越多。在具体实施时,第二预设比特位的位数和位置可以按照需要进行设定,本申请实施例对此不做限定。For the second preset bit, for example, if the IP address is 32 bits and the lower 23 bits are used to identify the encoding result of the character, several of the lower 23 bits except the first preset bit may be The bit is used as the second predetermined bit. For example, if the number of bits of the second preset bit is 3, the second preset bit can be represented as 000 when the sequence number is 1, the second preset bit can be represented as 001 when the sequence number is 2, and so on. . It can be understood that the number of bits of the second preset bit is related to the maximum number of characters that the string can contain. If the number of characters that the string can contain at most, the more bits of the second preset bit . In the specific implementation, the number of bits and the position of the second preset bit can be set as needed, which is not limited in this embodiment of the present application.
在一种具体实施方式中,IP地址的第23~16比特位如表1所示,其中,第23比特位预先设定为固定值0,第22比特位作为第一预设比特位,其中当字符所在字符串为服务集标识时第22比特位为0,当字符所在字符串为密码时第22比特位为1,第21~16比特位作为第二预设比特位。也就是说,IP 地址的第23~16比特位可以用于区分SSID和PWD。In a specific implementation manner, the 23rd to 16th bits of the IP address are as shown in Table 1, wherein the 23rd bit is preset to a fixed value of 0, and the 22nd bit is used as the first preset bit, wherein The 22nd bit is 0 when the character string is the service set identifier, the 22nd bit is 1 when the character string is the password, and the 21st to 16th bits are the second preset bit. That is, the 23rd to 16th bits of the IP address can be used to distinguish between the SSID and the PWD.
表1Table 1
Figure PCTCN2018120311-appb-000001
Figure PCTCN2018120311-appb-000001
以表1所示的方式进行编码时,对于服务集标识中的第2个字符,编码后得到的IP地址中第23~16比特位为000000001(以十进制表示为1),对于密码中的第2个字符,编码后的到的IP地址中第23~16比特位为010000001(以十进制表示为65)。When encoding in the manner shown in Table 1, for the second character in the service set identifier, the 23rd to 16th bits in the encoded IP address are 000000001 (in decimal), for the second in the password. 2 characters, the 23rd to 16th bits in the encoded IP address are 010000001 (in decimal notation 65).
对于第三预设比特位,第三预设比特位用于标记字符所表示的具体内容,在一种实现方式中,可以查找字符在预设编码规则(如ASCII编码)下所对应的二进制数字,以查找到的二进制数字作为第三预设比特位的取值。这种方式中,第三预设比特位的位数可以由预设编码规则决定。For the third preset bit, the third preset bit is used to mark the specific content represented by the character. In an implementation manner, the binary number corresponding to the character under the preset encoding rule (such as ASCII encoding) can be searched for. The binary number found is used as the value of the third preset bit. In this way, the number of bits of the third preset bit can be determined by a preset encoding rule.
在另一种实现方式中,可以预先设置第三预设比特位的数量大于等于16位,则在上述S1013中,根据字符的内容,确定字符对应的IP地址的第三预设比特位的取值的步骤,可以包括:In another implementation manner, the number of the third preset bits may be preset to be greater than or equal to 16 bits, and in the foregoing S1013, determining the third preset bit of the IP address corresponding to the character according to the content of the character. The steps of the value may include:
根据第一码值的高半字节和低半字节,将字符编码为两个字节,其中,第一码值为:字符在预设编码规则中对应的码值;Encoding the character into two bytes according to the high nibble and the low nibble of the first code value, where the first code value is: a code value corresponding to the character in the preset encoding rule;
根据编码后的两个字节,确定字符对应的IP地址的第三预设比特位的取值。The value of the third preset bit of the IP address corresponding to the character is determined according to the encoded two bytes.
上述预设编码规则可以为ASCII编码,在ASCII编码中,字符对应的码值由8比特位二进制数字组成,那么可以将前4比特位定义为码值的高半字节H,后4位比特定义为码值的低半字节L。例如,字符“M”,在ASCII编码中对应的码值为0x4D(以十六进制表示),其中0x4为高半字节H,0xD为低半字节L。The above preset encoding rule may be ASCII encoding. In ASCII encoding, the code value corresponding to the character is composed of 8-bit binary digits, then the first 4 bits may be defined as the high nibble H of the code value, and the last 4 bits. Defined as the lower nibble L of the code value. For example, the character "M" has a corresponding code value of 0x4D (in hexadecimal notation) in ASCII encoding, where 0x4 is the high nibble H and 0xD is the low nibble L.
在一种具体实现方式中,由第一码值的高半字节和低半字节编码得到第i个字符对应的两个字节的方式,可以如表2、表3、表4所示,其中,H i和L i分别表示第i个字符在ASCII编码规则中对应的码值的高半字节和低半字节。在这种具体实现方式中,仅仅根据第一码值来将字符编码为两个字节。 In a specific implementation manner, the method of encoding the two bytes corresponding to the ith character by the high nibble and the lower nibble of the first code value may be as shown in Table 2, Table 3, and Table 4. Where H i and L i respectively represent the upper nibble and the lower nibble of the code value corresponding to the i-th character in the ASCII encoding rule. In this particular implementation, the characters are encoded into two bytes based only on the first code value.
如表2所示的编码方式,直接将第一码值的低半字节和高半字节分别作为第一字节和第二字节的高半字节,将第一码值的高半字节和低半字节进行预设的数据处理后分别作为第一字节和第二字节的低半字节。As shown in Table 2, the lower nibble and the high nibble of the first code value are directly used as the high nibble of the first byte and the second byte, respectively, and the upper half of the first code value is obtained. The byte and the lower nibble are subjected to preset data processing as the lower nibble of the first byte and the second byte, respectively.
如表3所示的编码方式,直接将第一码值的高半字节和低半字节分别作为第一字节和第二字节的低半字节,将第一码值的低半字节和高半字节进行预设的数据处理后分别作为第一字节和第二字节的高半字节。As shown in the encoding method of Table 3, the high nibble and the low nibble of the first code value are directly used as the lower nibble of the first byte and the second byte, respectively, and the lower half of the first code value is obtained. The byte and the high nibble are subjected to preset data processing as the high nibble of the first byte and the second byte, respectively.
如表4所示的编码方式,直接将第一码值的低半字节和高半字节分别作为第一字节和第二字节的高半字节,将第一码值的高半字节和低半字节分别作为第一字节和第二字节的低半字节。As shown in Table 4, the lower nibble and the high nibble of the first code value are directly used as the high nibble of the first byte and the second byte, respectively, and the upper half of the first code value is obtained. The byte and the lower nibble are the lower nibble of the first byte and the second byte, respectively.
表2Table 2
  字节序号Byte number 高半字节High nibble 低半字节Low nibble
第一字节First byte 2i2i L i L i H i^(1%16) H i ^(1%16)
第二字节Second byte 2i+12i+1 H i H i L i^(2%16) L i ^(2%16)
表3table 3
  字节序号Byte number 高半字节High nibble 低半字节Low nibble
第一字节First byte 2i2i L i^(2i%16) L i ^(2i%16) H i H i
第二字节Second byte 2i+12i+1 H i^((2i+1)%16) H i ^((2i+1)%16) L i L i
表4Table 4
  字节序号Byte number 高半字节High nibble 低半字节Low nibble
第一字节First byte 2i2i L i L i H i H i
第二字节Second byte 2i+12i+1 H i H i L i L i
由于第三预设比特位的数量大于等于16位,因此,可以将第一字节和第二字节确定为其中16位的取值,而对于其它剩余的比特位可以预先设置为固定的取值。Since the number of the third preset bits is greater than or equal to 16 bits, the first byte and the second byte may be determined as the value of 16 bits, and the other remaining bits may be preset to be fixed. value.
在另一种具体实现方式中,还可以根据第一码值和第二码值,将字符编码为两个字节,其中第二码值为:字符所在字符串中的上一字符在预设编码规则中对应的码值,可以理解,利用第一码值和第二码值进行编码,便于在后续解码过程中校验字符的顺序是否正确。这样,上述根据第一码值的高半字节和低半字节,将字符编码为两个字节的步骤,可以包括:In another specific implementation, the character may be encoded into two bytes according to the first code value and the second code value, where the second code value is: the previous character in the character string is preset For the corresponding code value in the coding rule, it can be understood that the first code value and the second code value are used for encoding, so that it is convenient to check whether the order of the characters is correct in the subsequent decoding process. Thus, the step of encoding the character into two bytes according to the high nibble and the low nibble of the first code value may include:
根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,第二码值为:字符所在字符串中的上一字符在预设编码规则中对应的码值;Determining, according to the lower nibble of the second code value, a high nibble of the first byte of the two bytes, wherein the second code value is: the previous character in the string in which the character is located is in a preset encoding rule Corresponding code value;
根据第一码值的高半字节,确定所述第一字节的低半字节;Determining a lower nibble of the first byte according to a high nibble of the first code value;
根据第一码值的高半字节,确定两个字节中第二字节的高半字节;Determining a high nibble of a second byte of the two bytes according to a high nibble of the first code value;
根据第一码值的低半字节,确定所述第二字节的低半字节。The lower nibble of the second byte is determined based on the lower nibble of the first code value.
相应的,上述根据编码后的两个字节,确定字符对应的IP地址的第三预设比特位的取值的步骤,可以包括:Correspondingly, the step of determining the value of the third preset bit of the IP address corresponding to the character according to the encoded two bytes may include:
将第一字节确定为第三预设比特位中第一预设8比特位的取值;Determining, by the first byte, a value of a first preset 8-bit in the third preset bit;
将第二字节确定为第三预设比特位中第二预设8比特位的取值。The second byte is determined as the value of the second preset 8-bit in the third preset bit.
也就是,在确定上述第一字节和第二字节后,可以将第一字节中各个比特位的取值赋值给第三预设比特位中的第一预设8比特位,将第二字节中各个比特位的取值赋值给第三预设比特位中的第二预设8比特位。That is, after determining the first byte and the second byte, the value of each bit in the first byte may be assigned to the first preset 8-bit in the third preset bit, The value of each bit in the two bytes is assigned to the second preset 8 bits in the third preset bit.
另外,上述第一预设8比特位和第二预设8比特位是指:第三预设比特位中、预先设定好的8个比特位,其中,第一预设8比特位和第二预设8比特位不互相重合。In addition, the first preset 8-bit and the second preset 8-bit refer to: a preset eight bits in the third preset bit, wherein the first preset 8-bit and the first The two preset 8-bit bits do not coincide with each other.
这里再举例说明下上述的“字符所在字符串中的上一字符”,以字符串“asdf”为例,字符s在该字符串中的上一字符为a。Here is an example of the above "the last character in the string in which the character is located", taking the character string "asdf" as an example, the character of the character s in the previous character is a.
以一个字符串为例,利用上述编码方式,可以将该字符串中第i个字符编码为如表5、表6或表7所示的两个字节,其中L i-1表示该字符串中第i-1个字符在预设编码规则中对应的码值的低半字节。可以理解的,在编码时利用L i-1对第i个字符进行编码,确定第一字节的高半字节,便于在解码时通过第一字节的高半字节来校验字节序号的正确性。需要说明的是,以字符串“asdf”为例,由于字符a为该字符串中的第一个字符,在该字符串中不存在字符a的上一字符,则在对第一个字符a进行编码时,可以直接将L i-1置为0来确定第一字节的高半字节。 Taking a character string as an example, using the above encoding method, the i-th character in the string can be encoded into two bytes as shown in Table 5, Table 6, or Table 7, where L i-1 represents the string. The lower nibble of the corresponding code value in the i-1th character in the preset encoding rule. It can be understood that the i- th character is encoded by L i-1 at the time of encoding, and the high nibble of the first byte is determined, so that the byte is checked by the high nibble of the first byte during decoding. The correctness of the serial number. It should be noted that, taking the character string “asdf” as an example, since the character a is the first character in the string, and the previous character of the character a does not exist in the string, the first character a is When encoding, you can directly set L i-1 to 0 to determine the high nibble of the first byte.
表5table 5
Figure PCTCN2018120311-appb-000002
Figure PCTCN2018120311-appb-000002
表6Table 6
  字节序号Byte number 高半字节High nibble 低半字节Low nibble
第一字节First byte 2i2i L i-1^(2i%16) L i-1 ^(2i%16) H i H i
第二字节Second byte 2i+12i+1 H i^((2i+1)%16) H i ^((2i+1)%16) L i L i
表7Table 7
  字节序号Byte number 高半字节High nibble 低半字节Low nibble
第一字节First byte 2i2i L i-1 L i-1 H i H i
第二字节Second byte 2i+12i+1 H i H i L i L i
针对每个字符,在将字符编码为两个字节后,可以根据编码后的两个字节,确定字符对应的IP地址的第三预设比特位的取值。当第三预设比特位的数量为16位时,可以将第一字节确定为16比特位中高8比特位的取值,将第二字节确定为16比特位中低8比特位的取值;当第三预设比特位的数量大于16位时,比如18比特位,可以将第一字节确定为18比特位中的0-7比特位的取值,将第二字节确定为18比特位中8-15比特位的取值,对于第16、17比特位的取值可以预先设置为固定的取值。For each character, after encoding the character into two bytes, the value of the third preset bit of the IP address corresponding to the character may be determined according to the encoded two bytes. When the number of the third preset bits is 16 bits, the first byte may be determined as the value of the upper 8 bits of the 16 bits, and the second byte is determined to be the lower 8 bits of the 16 bits. Value; when the number of third preset bits is greater than 16 bits, such as 18 bits, the first byte may be determined as the value of 0-7 bits in the 18 bits, and the second byte is determined as The value of 8-15 bits in the 18-bit bit can be set to a fixed value for the values of the 16th and 17th bits.
举例而言,对于服务集标识为My的字符串,如表8所示,在ASCII编码规则下,字符M对应的码值为0x4D,则字符M对应的码值的高半字节H 0和低半字节L 0分别为0x4和0xD,字符y对应的码值为0x79,则字符y对应的码值的高半字节H 1和低半字节L 1分别为0x7和0x9。 For example, for a character string whose service set identifier is My, as shown in Table 8, under the ASCII encoding rule, the code value corresponding to the character M is 0x4D, and the high nibble H 0 of the code value corresponding to the character M is The lower nibble L 0 is 0x4 and 0xD, respectively, and the code value corresponding to the character y is 0x79, and the high nibble H 1 and the low nibble L 1 of the code value corresponding to the character y are 0x7 and 0x9, respectively.
表8Table 8
Figure PCTCN2018120311-appb-000003
Figure PCTCN2018120311-appb-000003
Figure PCTCN2018120311-appb-000004
Figure PCTCN2018120311-appb-000004
若设置IP地址的第三预设比特位为16位,则根据上述方法进行编码第三预设比特位时,如表9所示,对字符M编码后得到的两个字节分别为0x04、0x5D(以十六进制表示),将其中的第一字节0x04作为第三预设比特位中高8比特位的取值、第二字节0x5D作为第三预设比特位中低8比特位的取值,并且以表1所示的IP地址的第一预设比特位和第二预设比特位的编码方式,最终,对字符M进行编码得到的IP地址可以为239.0.4.93(以十进制表示),对字符y进行编码得到的IP地址可以为239.1.247.73(以十进制表示),其中,将十六进制转为十进制时,0x04=4,0x5D=93,0xF7=247,0x49=73。If the third preset bit of the IP address is set to 16 bits, when the third preset bit is encoded according to the above method, as shown in Table 9, the two bytes obtained by encoding the character M are 0x04, respectively. 0x5D (in hexadecimal notation), the first byte 0x04 is taken as the value of the upper 8 bits of the third preset bit, and the second byte 0x5D is taken as the lower 8 bits of the third preset bit. The value of the first preset bit and the second preset bit of the IP address shown in Table 1 is finally encoded. The IP address obtained by encoding the character M may be 239.0.4.93 (in decimal). Representation), the IP address obtained by encoding the character y can be 239.1.247.73 (in decimal), where hexadecimal is converted to decimal, 0x04=4, 0x5D=93, 0xF7=247, 0x49=73 .
表9Table 9
Figure PCTCN2018120311-appb-000005
Figure PCTCN2018120311-appb-000005
由表7可知,在编码时,序号为2i+1的字节的高半字节是根据序号为2i的字节的低半字节形成的,而第二电子设备在解码之后,可以通过前一序号的字节的低半字节和当前序号的字节的高半字节来校验当前字节序号的正确性,这样可以避免外来数据包的干扰。可见,利用这种方式编码出来的相邻两个字节的序号有关联,当接收到干扰的数据包时,第二电子设备可以通过前一个字节来校验序号的有效性。As can be seen from Table 7, at the time of encoding, the high nibble of the byte of sequence number 2i+1 is formed according to the lower nibble of the byte of sequence number 2i, and the second electronic device can pass before decoding. The lower nibble of a sequence of bytes and the high nibble of the byte of the current sequence number are used to verify the correctness of the current byte sequence number, thus avoiding interference from external data packets. It can be seen that the sequence numbers of two adjacent bytes encoded in this manner are associated. When receiving the interfered data packet, the second electronic device can check the validity of the sequence number through the previous byte.
应用图2所示实施例的编码方式,将WiFi网络的服务集标识和密码中的各个字符编码为IP地址,可以提高第二电子设备解析得到WiFi网络的服务集标识和密码的速度,进一步提高第二电子设备接入WiFi网络的速度。并且,利用组播IP地址的结构以及其和MAC地址特殊的对应关系,将服务集标识和密码编码后得到的IP地址进行组播,减少了组播时传输的数据量,而且通过IP地址方式携带需要传输的数据也较为安全、高效。Applying the coding mode of the embodiment shown in FIG. 2, encoding the service set identifier and the password in the WiFi network as an IP address, can improve the speed at which the second electronic device parses the service set identifier and password of the WiFi network, and further improves the speed. The speed at which the second electronic device accesses the WiFi network. Moreover, by using the structure of the multicast IP address and its special correspondence with the MAC address, the IP address obtained by encoding the service set identifier and the password is multicast, thereby reducing the amount of data transmitted during multicast, and by means of IP address It is safer and more efficient to carry the data that needs to be transmitted.
为了实现设备快速接入WiFi网络,基于上述的应用于第一电子设备的WiFi连接方法,本申请实施例还提供了一种WiFi连接方法,该方法应用于第二电子设备,如图3所示,包括如下步骤:In order to implement the device to quickly access the WiFi network, the embodiment of the present application further provides a WiFi connection method, which is applied to the second electronic device, as shown in FIG. 3, according to the above-mentioned WiFi connection method applied to the first electronic device. , including the following steps:
S301,抓取第一电子设备周期性发送的各个组播帧。S301. Capture each multicast frame periodically sent by the first electronic device.
S302,解析抓取到的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码。S302, parsing the captured multicast frame, obtaining a MAC address in each multicast frame, de-mapping each MAC address to obtain each IP address, and inversely encoding each IP address to obtain characters corresponding to each IP address, according to each IP address. The corresponding character determines the service set identifier and password of the WiFi network to be accessed.
其中,各个IP地址为第一电子设备对第一字符串和第二字符串中的各个字符分别进行编码得到的,第一字符串为:服务集标识,第二字符串为:密码。Each of the IP addresses is obtained by encoding, by the first electronic device, each character in the first character string and the second character string, where the first character string is: a service set identifier, and the second character string is: a password.
在解析组播帧得到组播帧中的MAC地址后,可以根据IP地址与MAC地址的映射关系,反映射得到IP地址。After the multicast frame is parsed to obtain the MAC address in the multicast frame, the IP address can be obtained by inverse mapping according to the mapping between the IP address and the MAC address.
在一种实现方式中,可以利用第二电子设备中的预设应用软件来对解析组播帧,得到各个字符对应的IP地址。In an implementation manner, the preset application software in the second electronic device may be used to parse the multicast frame to obtain an IP address corresponding to each character.
具体的,对应于图2所示实施例中第一电子设备对第一字符串和第二字符串中的各个字符分别进行编码得到每一字符对应的IP地址的编码方式,本申请实施例中对各个IP地址反编码得到各个IP地址对应的字符的步骤如图4所示,可以包括:Specifically, corresponding to the first electronic device in the embodiment shown in FIG. 2, each of the first character string and the second character string is encoded to obtain an encoding mode of the IP address corresponding to each character, which is used in the embodiment of the present application. The step of de-encoding each IP address to obtain characters corresponding to each IP address is as shown in FIG. 4, and may include:
按照以下步骤,对每一IP地址反编码得到每一IP地址对应的字符:Follow the steps below to inversely encode each IP address to get the character corresponding to each IP address:
S3021,根据IP地址的第一预设比特位的取值,确定IP地址对应的字符所在字符串的类别;S3021: Determine, according to the value of the first preset bit of the IP address, a category of a character string in which the character corresponding to the IP address is located;
S3022,根据IP地址的第二预设比特位的取值,确定IP地址对应的字符在字符串中的顺序号;S3022: Determine, according to the value of the second preset bit of the IP address, a sequence number of the character corresponding to the IP address in the character string;
S3023,根据IP地址的第三预设比特位的取值,确定IP地址对应的字符的内容。S3023. Determine the content of the character corresponding to the IP address according to the value of the third preset bit of the IP address.
相应的,在第三预设比特位的数量大于等于16位时,上述根据IP地址 的第三预设比特位的取值,确定IP地址对应的字符的内容的步骤,可以包括:Correspondingly, when the number of the third preset bits is greater than or equal to 16 bits, the step of determining the content of the character corresponding to the IP address according to the value of the third preset bit of the IP address may include:
根据IP地址的第三预设比特位的取值,确定两个字节;Determining two bytes according to the value of the third preset bit of the IP address;
根据所确定的两个字节,确定第一码值的高半字节和低半字节;其中,第一码值为IP地址对应的字符在预设编码规则中对应的码值;Determining, according to the determined two bytes, a high nibble and a low nibble of the first code value, where the first code value is a code value corresponding to the character corresponding to the IP address in the preset encoding rule;
从所述预设编码规则中确定由所述高半字节和低半字节组成的第一码值对应的字符的内容,作为IP地址对应的字符的内容。Determining, from the preset encoding rule, content of a character corresponding to the first code value composed of the high nibble and the lower nibble as content of a character corresponding to the IP address.
在一种具体实现方式中,上述根据IP地址的第三预设比特位的取值,确定两个字节的步骤,可以包括:In a specific implementation, the step of determining two bytes according to the value of the third preset bit of the IP address may include:
将第三预设比特位中第一预设8比特位的取值,确定为两个字节中的第一字节;Determining, by the third preset bit, a value of the first preset 8-bit, as the first byte of the two bytes;
将第三预设比特位中第二预设8比特位的取值,确定为两个字节中的第二字节。The value of the second preset 8-bit in the third preset bit is determined as the second byte of the two bytes.
上述根据所确定的两个字节,确定第一码值的高半字节和低半字节的步骤,可以包括:The foregoing steps of determining a high nibble and a low nibble of the first code value according to the determined two bytes may include:
根据第一字节的低半字节,确定第一码值的高半字节;Determining a high nibble of the first code value according to a lower nibble of the first byte;
根据第二字节的低半字节,确定第一码值的低半字节。The lower nibble of the first code value is determined based on the lower nibble of the second byte.
例如,对于以表3、表4、表6、表7所示的编码方式编码得到的第一字节和第二字节,在解码时可以直接将第一字节的低半字节确定为第一码值的高半字节,将第二字节的低半字节确定为第一码值的低半字节。For example, for the first byte and the second byte encoded by the coding methods shown in Table 3, Table 4, Table 6, and Table 7, the lower nibble of the first byte can be directly determined as being decoded at the time of decoding. The upper nibble of the first code value determines the lower nibble of the second byte as the lower nibble of the first code value.
对于以表2所示的编码方式编码得到的第一字节和第二字节,在解码时可以将第一字节的低半字节进行相应的反运算,得到第一码值的高半字节,将第二字节的低半字节进行相应的反运算,得到第一码值的低半字节。For the first byte and the second byte encoded by the encoding method shown in Table 2, the lower nibble of the first byte can be inversely calculated during decoding to obtain the upper half of the first code value. Byte, the lower nibble of the second byte is inversely operated to obtain the lower nibble of the first code value.
对于以表5所示的编码方式编码得到的第一字节和第二字节,在解码时,由于在步骤S3022中已经确定出了字符在字符串中的顺序号i,则此时可以根据顺序号i将第一字节的低半字节进行相应的反运算,得到第一码值的高半字节,根据顺序号i将第二字节的低半字节进行相应的反运算,得到第一码 值的低半字节。For the first byte and the second byte encoded by the encoding method shown in Table 5, at the time of decoding, since the sequence number i of the character in the character string has been determined in step S3022, then The sequence number i performs a corresponding inverse operation on the lower nibble of the first byte to obtain a high nibble of the first code value, and performs a corresponding inverse operation on the lower nibble of the second byte according to the sequence number i. The lower nibble of the first code value is obtained.
另外,为了在解码时校验字节序号的正确性,在上述根据第一字节的低半字节,确定第一码值的高半字节的步骤之前,还可以根据两个字节中第一字节的高半字节,确定出一个半字节的内容,然后判断所确定的半字节是否与第二码值的低半字节相同,如果相同,表示所确定的两个字节校验通过,则可以执行根据第一字节的低半字节,确定第一码值的高半字节的步骤,并进行后续的解码步骤,得到正确的字符,如果不相同,表示所确定的两个字节校验不通过,则可以结束解码步骤。In addition, in order to check the correctness of the byte number at the time of decoding, before the step of determining the high nibble of the first code value according to the lower nibble of the first byte, it may be based on two bytes. The upper nibble of the first byte determines the content of a nibble, and then determines whether the determined nibble is the same as the lower nibble of the second code value. If they are the same, the determined two words are represented. After the checksum is passed, the step of determining the high nibble of the first code value according to the lower nibble of the first byte may be performed, and the subsequent decoding step is performed to obtain the correct character. If not, the indication is If the determined two-byte check fails, the decoding step can be ended.
S303,根据服务集标识和密码接入WiFi网络。S303. Access the WiFi network according to the service set identifier and the password.
本申请实施例提供的方案可以应用在多种场景中。The solution provided by the embodiment of the present application can be applied in various scenarios.
例如,第二电子设备待接入的WiFi网络可以为第一电子设备自身已接入的WiFi网络,或者,第二电子设备待接入的WiFi网络也可以不是第一电子设备当前所接入的WiFi网络,这两种应用场景中,WiFi网络都需要依赖于路由器来创建。For example, the WiFi network to be accessed by the second electronic device may be the WiFi network that the first electronic device has accessed, or the WiFi network to be accessed by the second electronic device may not be currently accessed by the first electronic device. WiFi network, in both scenarios, WiFi networks need to rely on routers to create.
再如,若第一电子设备为手持设备,则可以以第一电子设备作为WiFi热点,第二电子设备接入该WiFi热点,此时,第二电子设备可以通过第一电子设备的3G/4G网络进行数据传输,例如上传数据到互联网。这种应用场景中,第一电子设备与第二电子设备之间的WiFi连接摆脱了对路由器的依赖,在没有路由器的情况下仍可以保持第一电子设备和第二电子设备的WiFi连接。For example, if the first electronic device is a handheld device, the first electronic device can be used as a WiFi hotspot, and the second electronic device can access the WiFi hotspot. At this time, the second electronic device can pass the 3G/4G of the first electronic device. The network performs data transmission, such as uploading data to the Internet. In such an application scenario, the WiFi connection between the first electronic device and the second electronic device is free of dependence on the router, and the WiFi connection of the first electronic device and the second electronic device can still be maintained without the router.
可以理解的,当第二电子设备接入WiFi网络后,第一电子设备则不必要继续发送由各个MAC地址作为目的地址的组播帧,基于此,在一种具体实施方式中,该方法还可以包括:在接入WiFi网络后,向第一电子设备反馈成功接入WiFi网络的信息,以使得第一电子设备结束发送由映射得到的各个MAC地址作为目的地址的组播帧,这样,可以节约网络资源。It can be understood that, after the second electronic device accesses the WiFi network, the first electronic device does not need to continue to send the multicast frame with each MAC address as the destination address. Based on this, in a specific implementation manner, the method further After the access to the WiFi network, the information about the successful access to the WiFi network is fed back to the first electronic device, so that the first electronic device ends sending the multicast frame with each MAC address obtained by the mapping as the destination address, so that Save network resources.
综上所述,本申请实施例提供的方案,第二电子设备抓取并解析第一电子设备发送的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码,从 而接入WiFi网络。可见,本申请实施例提供方案,不需要手动在第二电子设备上配置WiFi参数,即可实现第二电子设备快速接入WiFi网络。In summary, in the solution provided by the embodiment of the present application, the second electronic device captures and parses the multicast frame sent by the first electronic device, obtains a MAC address in each multicast frame, and demaps each MAC address to obtain each IP address. The address is obtained by de-encoding each IP address to obtain a character corresponding to each IP address, and determining a service set identifier and password of the WiFi network to be accessed according to characters corresponding to each IP address, thereby accessing the WiFi network. It can be seen that the embodiment of the present application provides a solution that the second electronic device can be quickly accessed into the WiFi network without manually configuring the WiFi parameter on the second electronic device.
与上述应用于第一电子设备的方法实施例相对应,本申请实施例还提供了一种WiFi连接装置,如图5所示,该装置应用于第一电子设备,可以包括:Corresponding to the foregoing method embodiment applied to the first electronic device, the embodiment of the present application further provides a WiFi connection device. As shown in FIG. 5, the device is applied to the first electronic device, and may include:
编码模块501,用于针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;The encoding module 501 is configured to encode the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character, where the first character string is: the second electronic device a service set identifier of the WiFi network to be accessed, the second character string being: a password of the WiFi network to be accessed by the second electronic device;
映射模块502,用于将每一字符对应的IP地址映射为MAC地址;The mapping module 502 is configured to map an IP address corresponding to each character to a MAC address.
发送模块503,用于周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。The sending module 503 is configured to periodically send, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, and obtains a Describe the service set identifier and the password, and access the WiFi network according to the service set identifier and the password.
作为本申请的一个具体实施例,如图6所示,所述编码模块501,可以包括:As a specific embodiment of the present application, as shown in FIG. 6, the encoding module 501 may include:
第一确定子模块5011,用于根据字符所在字符串的类别,确定字符对应的IP地址的第一预设比特位的取值;The first determining sub-module 5011 is configured to determine, according to the category of the character string in which the character is located, the value of the first preset bit of the IP address corresponding to the character;
第二确定子模块5012,用于根据字符在字符串中的顺序号,确定字符对应的IP地址的第二预设比特位的取值;The second determining sub-module 5012 is configured to determine, according to the sequence number of the character in the character string, the value of the second preset bit of the IP address corresponding to the character;
第三确定子模块5013,用于根据字符的内容,确定字符对应的IP地址的第三预设比特位的取值,其中,所述第一预设比特位、所述第二预设比特位和所述第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。The third determining sub-module 5013 is configured to determine, according to the content of the character, a value of a third preset bit of the IP address corresponding to the character, where the first preset bit and the second preset bit The sum of the digits of the third preset bit is determined by the mapping relationship between the IP address and the MAC address.
作为本申请的一个具体实施例,所述第三预设比特位的数量大于等于16位;As a specific embodiment of the present application, the number of the third preset bits is greater than or equal to 16 bits;
所述第三确定子模块5013,可以包括:The third determining submodule 5013 may include:
编码单元,用于根据第一码值的高半字节和低半字节,将字符编码为两个字节,其中,所述第一码值为:字符在预设编码规则中对应的码值;a coding unit, configured to encode a character into two bytes according to a high nibble and a low nibble of the first code value, where the first code value is: a code corresponding to a character in a preset encoding rule value;
确定单元,用于根据编码后的两个字节,确定字符对应的IP地址的第三预设比特位的取值。And a determining unit, configured to determine, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character.
作为本申请的一个具体实施例,所述编码单元,可以包括:As a specific embodiment of the present application, the coding unit may include:
第一确定子单元,用于根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,所述第二码值为:字符所在字符串中的上一字符在预设编码规则中对应的码值;a first determining subunit, configured to determine a high nibble of the first byte of the two bytes according to a lower nibble of the second code value, where the second code value is: a string in which the character is located The code value corresponding to the previous character in the preset encoding rule;
第二确定子单元,用于根据第一码值的高半字节,确定所述第一字节的低半字节;a second determining subunit, configured to determine a lower nibble of the first byte according to a high nibble of the first code value;
第三确定子单元,用于根据第一码值的高半字节,确定两个字节中第二字节的高半字节;a third determining subunit, configured to determine a high nibble of the second byte of the two bytes according to the high nibble of the first code value;
第四确定子单元,用于根据第一码值的低半字节,确定所述第二字节的低半字节;a fourth determining subunit, configured to determine a lower nibble of the second byte according to a lower nibble of the first code value;
相应的,所述确定单元,可以包括:Correspondingly, the determining unit may include:
第五确定子单元,用于将所述第一字节确定为所述第三预设比特位中第一预设8比特位的取值;a fifth determining subunit, configured to determine the first byte as a value of a first preset 8-bit in the third preset bit;
第六确定子单元,用于将所述第二字节确定为所述第三预设比特位中第二预设8比特位的取值。And a sixth determining subunit, configured to determine the second byte as a value of a second preset 8-bit in the third preset bit.
作为本申请的一个具体实施例,所述装置还可以包括:As a specific embodiment of the application, the device may further include:
接收模块,用于接收所述第二电子设备反馈的成功接入所述WiFi网络的信息,结束所述发送模块执行周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧的步骤。a receiving module, configured to receive information that the second electronic device feeds back successfully to the WiFi network, and end the sending module to periodically send each MAC address obtained by mapping to the second electronic device as a destination address. The step of multicasting frames.
本申请实施例提供的方案,第二电子设备抓取并解析第一电子设备发送的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码,从而接入WiFi网络。可见,本申请实施例提供方案,不需要手动在第二电子设备上配置WiFi参数,即可实现第二电子设备快速接入WiFi网络。In the solution provided by the embodiment of the present application, the second electronic device captures and parses the multicast frame sent by the first electronic device, obtains a MAC address in each multicast frame, and demaps each MAC address to obtain each IP address, for each IP address. The address is inverse-coded to obtain the characters corresponding to each IP address, and the service set identifier and password of the WiFi network to be accessed are determined according to the characters corresponding to the respective IP addresses, thereby accessing the WiFi network. It can be seen that the embodiment of the present application provides a solution that the second electronic device can be quickly accessed into the WiFi network without manually configuring the WiFi parameter on the second electronic device.
与上述应用于第二电子设备的方法实施例相对应,本申请实施例还提供了一种WiFi连接装置,如图7所示,该装置应用于第二电子设备,可以包括:The embodiment of the present application further provides a WiFi connection device. As shown in FIG. 7, the device is applied to the second electronic device, and may include:
抓取模块701,用于抓取第一电子设备周期性发送的各个组播帧;The capture module 701 is configured to capture each multicast frame periodically sent by the first electronic device.
解析模块702,用于解析抓取到的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码;其中,各个IP地址为所述第一电子设备对第一字符串和第二字符串中的各个字符分别进行编码得到的,所述第一字符串为:所述服务集标识,所述第二字符串为:所述密码;The parsing module 702 is configured to parse the captured multicast frame, obtain a MAC address in each multicast frame, demap all the MAC addresses to obtain each IP address, and inversely encode each IP address to obtain a character corresponding to each IP address. Determining, according to the character corresponding to each IP address, a service set identifier and a password of the WiFi network to be accessed; wherein each IP address is used by the first electronic device to encode each character in the first character string and the second character string respectively The first character string is: the service set identifier, and the second character string is: the password;
连接模块703,用于根据所述服务集标识和密码接入所述WiFi网络。The connection module 703 is configured to access the WiFi network according to the service set identifier and password.
作为本申请的一个具体实施例,如图8所示,所述解析模块702,可以包括:As a specific embodiment of the present application, as shown in FIG. 8, the parsing module 702 may include:
第一确定子模块7021,用于根据IP地址的第一预设比特位的取值,确定IP地址对应的字符所在字符串的类别;The first determining sub-module 7021 is configured to determine, according to the value of the first preset bit of the IP address, a category of a character string in which the character corresponding to the IP address is located;
第二确定子模块7022,用于根据IP地址的第二预设比特位的取值,确定IP地址对应的字符在字符串中的顺序号;The second determining sub-module 7022 is configured to determine, according to the value of the second preset bit of the IP address, a sequence number of the character corresponding to the IP address in the character string;
第三确定子模块7023,用于根据IP地址的第三预设比特位的取值,确定IP地址对应的字符的内容。The third determining sub-module 7023 is configured to determine, according to the value of the third preset bit of the IP address, the content of the character corresponding to the IP address.
作为本申请的一个具体实施例,所述第三预设比特位的数量可以大于等于16位;As a specific embodiment of the present application, the number of the third preset bits may be greater than or equal to 16 bits;
所述第三确定子模块7023,可以包括:The third determining submodule 7023 may include:
第一确定单元,用于根据IP地址的第三预设比特位的取值,确定两个字节;a first determining unit, configured to determine two bytes according to a value of a third preset bit of the IP address;
第二确定单元,用于根据所确定的两个字节,确定第一码值的高半字节和低半字节;其中,第一码值为IP地址对应的字符在预设编码规则中对应的码值;a second determining unit, configured to determine a high nibble and a low nibble of the first code value according to the determined two bytes; wherein the first code value is a character corresponding to the IP address in a preset encoding rule Corresponding code value;
第三确定单元,用于从所述预设编码规则中确定由所述高半字节和低半字节组成的第一码值对应的字符的内容,作为IP地址对应的字符的内容。And a third determining unit, configured to determine, from the preset encoding rule, content of a character corresponding to the first code value composed of the high nibble and the low nibble as the content of the character corresponding to the IP address.
作为本申请的一个具体实施例,所述第一确定单元,可以包括:As a specific embodiment of the present application, the first determining unit may include:
第一确定子单元,用于将所述第三预设比特位中第一预设8比特位的取值,确定为两个字节中的第一字节;a first determining subunit, configured to determine a value of the first preset 8 bits in the third preset bit as the first byte of the two bytes;
第二确定子单元,用于将所述第三预设比特位中第二预设8比特位的取值,确定为两个字节中的第二字节;a second determining subunit, configured to determine a value of the second preset 8 bits in the third preset bit as a second byte of the two bytes;
相应的,所述第二确定单元,可以包括:Correspondingly, the second determining unit may include:
第三确定子单元,用于根据所述第一字节的低半字节,确定第一码值的高半字节;a third determining subunit, configured to determine a high nibble of the first code value according to the lower nibble of the first byte;
第四确定子单元,用于根据所述第二字节的低半字节,确定第一码值的低半字节。And a fourth determining subunit, configured to determine a lower nibble of the first code value according to the lower nibble of the second byte.
作为本申请的一个具体实施例,所述装置还可以包括:As a specific embodiment of the application, the device may further include:
第五确定子单元,用于在所述第三确定子单元根据所述第一字节的低半字节,确定第一码值的高半字节之前,根据所述第一字节的高半字节,确定第一半字节;a fifth determining subunit, configured to determine, according to the lower nibble of the first byte, the high nibble of the first code value, according to the first byte a nibble, determining the first nibble;
判断子单元,用于判断所述第一半字节与第二码值的低半字节是否相同,其中,所述第二码值为:字符所在字符串中的上一字符在预设编码规则中对应的码值;如果相同,触发所述第三确定子单元。a determining subunit, configured to determine whether the first nibble and the lower nibble of the second code value are the same, wherein the second code value is: the previous character in the character string in the character is in the preset encoding The corresponding code value in the rule; if the same, the third determining subunit is triggered.
作为本申请的一个具体实施例,所述装置还可以包括:As a specific embodiment of the application, the device may further include:
发送模块,用于在接入所述WiFi网络后,向所述第一电子设备反馈成功接入所述WiFi网络的信息,以使得所述第一电子设备结束发送由映射得到的各个MAC地址作为目的地址的组播帧。a sending module, after accessing the WiFi network, feeding back information of the WiFi network to the first electronic device, so that the first electronic device ends sending each MAC address obtained by mapping Multicast frame of the destination address.
本申请实施例提供的方案,第二电子设备抓取并解析第一电子设备发送的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地 址对应的字符确定待接入的WiFi网络的服务集标识和密码,从而接入WiFi网络。可见,本申请实施例提供方案,不需要手动在第二电子设备上配置WiFi参数,即可实现第二电子设备快速接入WiFi网络。In the solution provided by the embodiment of the present application, the second electronic device captures and parses the multicast frame sent by the first electronic device, obtains a MAC address in each multicast frame, and demaps each MAC address to obtain each IP address, for each IP address. The address is inverse-coded to obtain the characters corresponding to each IP address, and the service set identifier and password of the WiFi network to be accessed are determined according to the characters corresponding to the respective IP addresses, thereby accessing the WiFi network. It can be seen that the embodiment of the present application provides a solution that the second electronic device can be quickly accessed into the WiFi network without manually configuring the WiFi parameter on the second electronic device.
本申请实施例还提供了一种电子设备,如图9所示,包括处理器901、通信接口902、存储器903和通信总线904,其中,处理器901,通信接口902,存储器903通过通信总线904完成相互间的通信,The embodiment of the present application further provides an electronic device, as shown in FIG. 9, including a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 pass through the communication bus 904. Complete communication with each other,
存储器903,用于存放计算机程序;a memory 903, configured to store a computer program;
处理器901,用于执行存储器903上所存放的程序时,实现如下步骤:The processor 901 is configured to perform the following steps when executing the program stored on the memory 903:
针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;For each character in the first character string and the second character string, the character is encoded to obtain an IP address corresponding to the character, where the first character string is: a WiFi network to be accessed by the second electronic device The service set identifier, the second character string is: a password of a WiFi network to be accessed by the second electronic device;
将每一字符对应的IP地址映射为MAC地址;Mapping the IP address corresponding to each character to a MAC address;
周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。And periodically transmitting, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, and obtains the service set identifier and the Said password, accessing said WiFi network according to said service set identifier and said password.
可见,本申请实施例提供电子设备,将其它电子设备待接入的WiFi网络的服务集标识和密码中的各个字符编码为IP地址,并映射为MAC地址,然后发送由各个MAC地址作为目的地址的组播帧,这样,其它电子设备可以抓取并解析组播帧获得服务器标识和密码,而不需要手动在其它电子设备上配置WiFi参数,即可实现其它电子设备快速接入WiFi网络。It can be seen that the embodiment of the present application provides an electronic device, which encodes each character in the service set identifier and password of the WiFi network to be accessed by other electronic devices into an IP address, and maps to a MAC address, and then sends each MAC address as a destination address. The multicast frame, in this way, other electronic devices can capture and parse the multicast frame to obtain the server identification and password, without manually configuring the WiFi parameters on other electronic devices, so that other electronic devices can quickly access the WiFi network.
关于该方法各个步骤的具体实现以及相关解释内容可以参见上述图1所示的方法实施例,在此不做赘述。For the specific implementation of the various steps of the method and the related explanations, refer to the method embodiment shown in FIG. 1 above, and no further details are provided herein.
另外,处理器901执行存储器903上所存放的程序而实现的WiFi连接方法的其他实现方式,与前述方法实施例部分所提及的实现方式相同,这里也不再赘述。In addition, other implementation manners of the WiFi connection method implemented by the processor 901 executing the program stored in the memory 903 are the same as those mentioned in the foregoing method embodiment, and are not described herein again.
本申请实施例还提供了一种电子设备,如图10所示,包括处理器101、 通信接口102、存储器103和通信总线104,其中,处理器101,通信接口102,存储器103通过通信总线104完成相互间的通信,The embodiment of the present application further provides an electronic device, as shown in FIG. 10, including a processor 101, a communication interface 102, a memory 103, and a communication bus 104. The processor 101, the communication interface 102, and the memory 103 pass through the communication bus 104. Complete communication with each other,
存储器103,用于存放计算机程序;a memory 103, configured to store a computer program;
处理器101,用于执行存储器103上所存放的程序时,实现如下步骤:The processor 101 is configured to perform the following steps when executing the program stored on the memory 103:
抓取第一电子设备周期性发送的各个组播帧;Grab each multicast frame periodically sent by the first electronic device;
解析抓取到的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码;其中,各个IP地址为所述第一电子设备对第一字符串和第二字符串中的各个字符分别进行编码得到的,所述第一字符串为:所述服务集标识,所述第二字符串为:所述密码;Parsing the captured multicast frame, obtaining the MAC address in each multicast frame, de-mapping each MAC address to obtain each IP address, and inverse-encoding each IP address to obtain characters corresponding to each IP address, according to each IP address. The character determines a service set identifier and a password of the WiFi network to be accessed; wherein each IP address is obtained by encoding, by the first electronic device, each character in the first character string and the second character string, A string is: the service set identifier, and the second string is: the password;
根据所述服务集标识和密码接入所述WiFi网络。Accessing the WiFi network according to the service set identifier and password.
可见,本申请实施例提供电子设备,通过抓取并解析其它电子设备发送的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码,而不需要手动配置WiFi参数,即可实现快速接入WiFi网络。It can be seen that the embodiment of the present application provides an electronic device, which obtains a MAC address in each multicast frame by fetching and parsing a multicast frame sent by another electronic device, and de-maps each MAC address to obtain each IP address, and is inverse for each IP address. The code obtains the characters corresponding to each IP address, and determines the service set identifier and password of the WiFi network to be accessed according to the characters corresponding to the respective IP addresses. Instead of manually configuring the WiFi parameters, the WiFi network can be quickly accessed.
关于该方法各个步骤的具体实现以及相关解释内容可以参见上述图3所示的方法实施例,在此不做赘述。For the specific implementation of the various steps of the method and the related explanations, refer to the method embodiment shown in FIG. 3 above, and no further details are provided herein.
另外,处理器101执行存储器103上所存放的程序而实现的WiFi连接方法的其他实现方式,与前述方法实施例部分所提及的实现方式相同,这里也不再赘述。In addition, other implementation manners of the WiFi connection method implemented by the processor 101 to execute the program stored in the memory 103 are the same as those mentioned in the foregoing method embodiment, and are not described herein again.
上述电子设备提到的通信总线可以是外设部件互连标准(Peripheral Component Interconnect,PCI)总线或扩展工业标准结构(Extended Industry Standard Architecture,EISA)总线等。该通信总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is shown in the figure, but it does not mean that there is only one bus or one type of bus.
通信接口用于上述电子设备与其他设备之间的通信。The communication interface is used for communication between the above electronic device and other devices.
存储器可以包括随机存取存储器(Random Access Memory,RAM),也可以包括非易失性存储器(Non-Volatile Memory,NVM),例如至少一个磁盘存储器。可选的,存储器还可以是至少一个位于远离前述处理器的存储装置。The memory may include a random access memory (RAM), and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。The above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; or may be a digital signal processing (DSP), dedicated integration. Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述实施例中应用于第一电子设备的的WiFi连接方法。The embodiment of the present application further provides a computer readable storage medium, where the computer readable storage medium stores instructions, when executed on a computer, causing the computer to execute the WiFi applied to the first electronic device in the foregoing embodiment. connection method.
通过运行本申请实施例提供的计算机程序产品,将其它电子设备待接入的WiFi网络的服务集标识和密码中的各个字符编码为IP地址,并映射为MAC地址,然后发送由各个MAC地址作为目的地址的组播帧,这样,其它电子设备可以抓取并解析组播帧获得服务器标识和密码,而不需要手动在其它电子设备上配置WiFi参数,即可实现其它电子设备快速接入WiFi网络。By running the computer program product provided by the embodiment of the present application, each character in the service set identifier and the password of the WiFi network to be accessed by other electronic devices is encoded as an IP address, and mapped to a MAC address, and then sent by each MAC address. Multicast frame of the destination address. In this way, other electronic devices can capture and parse the multicast frame to obtain the server ID and password. Instead of manually configuring the WiFi parameters on other electronic devices, other electronic devices can quickly access the WiFi network. .
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述实施例中应用于第二电子设备的WiFi连接方法。The embodiment of the present application further provides a computer readable storage medium, where the computer readable storage medium stores instructions, when executed on a computer, causing the computer to execute the WiFi connection applied to the second electronic device in the above embodiment. method.
通过运行本申请实施例提供的计算机程序产品,通过抓取并解析其它电子设备发送的组播帧,得到各个组播帧中的MAC地址,对各个MAC地址反映射得到各个IP地址,对各个IP地址反编码得到各个IP地址对应的字符,根据各个IP地址对应的字符确定待接入的WiFi网络的服务集标识和密码,而不需要手动配置WiFi参数,即可实现快速接入WiFi网络。By running the computer program product provided by the embodiment of the present application, the multicast frame sent by the other electronic device is captured and parsed, and the MAC address in each multicast frame is obtained, and each IP address is inversely mapped to obtain each IP address, and each IP address is obtained. The address is reverse-encoded to obtain the characters corresponding to the IP addresses. The service set identifier and password of the WiFi network to be accessed are determined according to the characters corresponding to the IP addresses. Instead of manually configuring the WiFi parameters, the WiFi network can be quickly accessed.
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示 这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that, in this context, relational terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply such entities or operations. There is any such actual relationship or order between them. Furthermore, the term "comprises" or "comprises" or "comprises" or any other variations thereof is intended to encompass a non-exclusive inclusion, such that a process, method, article, or device that comprises a plurality of elements includes not only those elements but also Other elements, or elements that are inherent to such a process, method, item, or device. An element that is defined by the phrase "comprising a ..." does not exclude the presence of additional equivalent elements in the process, method, item, or device that comprises the element.
本说明书中的各个实施例均采用相关的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置、电子设备以及计算机可读存储介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。The various embodiments in the present specification are described in a related manner, and the same or similar parts between the various embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, and the computer readable storage medium embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
以上所述仅为本申请的较佳实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和原则之内所作的任何修改、等同替换、改进等,均包含在本申请的保护范围内。The above description is only the preferred embodiment of the present application, and is not intended to limit the scope of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application are included in the scope of the present application.

Claims (12)

  1. 一种WiFi连接方法,其特征在于,应用于第一电子设备,所述方法包括:A WiFi connection method, which is applied to a first electronic device, the method comprising:
    针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;For each character in the first character string and the second character string, the character is encoded to obtain an IP address corresponding to the character, where the first character string is: a WiFi network to be accessed by the second electronic device The service set identifier, the second character string is: a password of a WiFi network to be accessed by the second electronic device;
    将每一字符对应的IP地址映射为MAC地址;Mapping the IP address corresponding to each character to a MAC address;
    周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。And periodically transmitting, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, and obtains the service set identifier and the Said password, accessing said WiFi network according to said service set identifier and said password.
  2. 根据权利要求1所述的方法,其特征在于,所述针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址的步骤,包括:The method according to claim 1, wherein the step of encoding the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character comprises:
    根据所述字符所在字符串的类别,确定所述字符对应的IP地址的第一预设比特位的取值;Determining, according to a category of the character string in which the character is located, a value of a first preset bit of the IP address corresponding to the character;
    根据所述字符在字符串中的顺序号,确定所述字符对应的IP地址的第二预设比特位的取值;Determining, according to the sequence number of the character in the character string, a value of a second preset bit of the IP address corresponding to the character;
    根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值,其中,所述第一预设比特位、所述第二预设比特位和所述第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。Determining, by the content of the character, a value of a third preset bit of the IP address corresponding to the character, where the first preset bit, the second preset bit, and the third The sum of the number of bits of the preset bit is determined by the mapping relationship between the IP address and the MAC address.
  3. 根据权利要求2所述的方法,其特征在于,所述第三预设比特位的数量大于等于16位;The method according to claim 2, wherein the number of the third preset bits is greater than or equal to 16 bits;
    所述根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值的步骤,包括:The determining, according to the content of the character, the value of the third preset bit of the IP address corresponding to the character, includes:
    根据第一码值的高半字节和低半字节,将所述字符编码为两个字节,其中,所述第一码值为:所述字符在预设编码规则中对应的码值;Encoding the character into two bytes according to a high nibble and a low nibble of the first code value, where the first code value is: a code value corresponding to the character in a preset encoding rule ;
    根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值。And determining, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character.
  4. 根据权利要求3所述的方法,其特征在于,所述根据第一码值的高半字节和低半字节,将所述字符编码为两个字节的步骤,包括:The method according to claim 3, wherein said step of encoding said character into two bytes according to a high nibble and a low nibble of said first code value comprises:
    根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,所述第二码值为:所述字符所在字符串中的上一字符在预设编码规则中对应的码值;Determining, according to a lower nibble of the second code value, a high nibble of the first byte of the two bytes, wherein the second code value is: a previous character in the character string of the character is in advance Set the corresponding code value in the coding rule;
    根据第一码值的高半字节,确定所述第一字节的低半字节;Determining a lower nibble of the first byte according to a high nibble of the first code value;
    根据第一码值的高半字节,确定两个字节中第二字节的高半字节;Determining a high nibble of a second byte of the two bytes according to a high nibble of the first code value;
    根据第一码值的低半字节,确定所述第二字节的低半字节;Determining a lower nibble of the second byte according to a lower nibble of the first code value;
    所述根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值的步骤,包括:And the step of determining, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character, including:
    将所述第一字节确定为所述第三预设比特位中第一预设8比特位的取值;Determining, by the first byte, a value of a first preset 8-bit in the third preset bit;
    将所述第二字节确定为所述第三预设比特位中第二预设8比特位的取值。Determining, by the second byte, a value of a second preset 8-bit in the third preset bit.
  5. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method of claim 1 further comprising:
    接收所述第二电子设备反馈的成功接入所述WiFi网络的信息,结束所述周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧的步骤。Receiving the information that the second electronic device feeds back successfully to the WiFi network, and ending the step of periodically transmitting, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address.
  6. 一种WiFi连接装置,其特征在于,应用于第一电子设备,所述装置包括:A WiFi connection device is characterized in that it is applied to a first electronic device, and the device includes:
    编码模块,用于针对第一字符串和第二字符串中的每一字符,对该字符进行编码,得到该字符对应的IP地址,其中,所述第一字符串为:第二电子设备待接入的WiFi网络的服务集标识,所述第二字符串为:所述第二电子设备待接入的WiFi网络的密码;The encoding module is configured to encode the character for each character in the first character string and the second character string to obtain an IP address corresponding to the character, where the first character string is: the second electronic device is to be a service set identifier of the accessed WiFi network, where the second character string is: a password of the WiFi network to be accessed by the second electronic device;
    映射模块,用于将每一字符对应的IP地址映射为MAC地址;a mapping module, configured to map an IP address corresponding to each character to a MAC address;
    发送模块,用于周期性向所述第二电子设备发送由映射得到的各个MAC地 址作为目的地址的组播帧,以使得所述第二电子设备抓取并解析所述组播帧,获得所述服务集标识和所述密码,根据所述服务集标识和所述密码接入所述WiFi网络。a sending module, configured to periodically send, to the second electronic device, a multicast frame that is obtained by mapping each MAC address as a destination address, so that the second electronic device captures and parses the multicast frame, to obtain the The service set identifier and the password are accessed according to the service set identifier and the password to the WiFi network.
  7. 根据权利要求6所述的装置,其特征在于,所述编码模块,包括:The apparatus according to claim 6, wherein the encoding module comprises:
    第一确定子模块,用于根据所述字符所在字符串的类别,确定所述字符对应的IP地址的第一预设比特位的取值;a first determining submodule, configured to determine, according to a category of the character string in which the character is located, a value of a first preset bit of the IP address corresponding to the character;
    第二确定子模块,用于根据所述字符在字符串中的顺序号,确定所述字符对应的IP地址的第二预设比特位的取值;a second determining submodule, configured to determine, according to the sequence number of the character in the character string, a value of a second preset bit of the IP address corresponding to the character;
    第三确定子模块,用于根据所述字符的内容,确定所述字符对应的IP地址的第三预设比特位的取值,其中,所述第一预设比特位、所述第二预设比特位和所述第三预设比特位的位数之和是由IP地址与MAC地址的映射关系确定的。a third determining submodule, configured to determine, according to the content of the character, a value of a third preset bit of the IP address corresponding to the character, where the first preset bit and the second pre The sum of the bits of the bit and the third predetermined bit is determined by the mapping relationship between the IP address and the MAC address.
  8. 根据权利要求7所述的装置,其特征在于,所述第三预设比特位的数量大于等于16位;The apparatus according to claim 7, wherein the number of the third preset bits is greater than or equal to 16 bits;
    所述第三确定子模块,包括:The third determining submodule includes:
    编码单元,用于根据第一码值的高半字节和低半字节,将所述字符编码为两个字节,其中,所述第一码值为:所述字符在预设编码规则中对应的码值;a coding unit, configured to encode the character into two bytes according to a high nibble and a low nibble of the first code value, where the first code value is: the character is in a preset encoding rule Corresponding code value;
    确定单元,用于根据编码后的两个字节,确定所述字符对应的IP地址的第三预设比特位的取值。And a determining unit, configured to determine, according to the encoded two bytes, a value of a third preset bit of the IP address corresponding to the character.
  9. 根据权利要求8所述的装置,其特征在于,所述编码单元,包括:The apparatus according to claim 8, wherein the coding unit comprises:
    第一确定子单元,用于根据第二码值的低半字节,确定两个字节中第一字节的高半字节,其中,所述第二码值为:所述字符所在字符串中的上一字符在预设编码规则中对应的码值;a first determining subunit, configured to determine a high nibble of the first byte of the two bytes according to a lower nibble of the second code value, where the second code value is: a character of the character The code value corresponding to the previous character in the string in the preset encoding rule;
    第二确定子单元,用于根据第一码值的高半字节,确定所述第一字节的低半字节;a second determining subunit, configured to determine a lower nibble of the first byte according to a high nibble of the first code value;
    第三确定子单元,用于根据第一码值的高半字节,确定两个字节中第二字节的高半字节;a third determining subunit, configured to determine a high nibble of the second byte of the two bytes according to the high nibble of the first code value;
    第四确定子单元,用于根据第一码值的低半字节,确定所述第二字节的低半字节;a fourth determining subunit, configured to determine a lower nibble of the second byte according to a lower nibble of the first code value;
    所述确定单元,包括:The determining unit includes:
    第五确定子单元,用于将所述第一字节确定为所述第三预设比特位中第一预设8比特位的取值;a fifth determining subunit, configured to determine the first byte as a value of a first preset 8-bit in the third preset bit;
    第六确定子单元,用于将所述第二字节确定为所述第三预设比特位中第二预设8比特位的取值。And a sixth determining subunit, configured to determine the second byte as a value of a second preset 8-bit in the third preset bit.
  10. 根据权利要求6所述的装置,其特征在于,所述装置还包括:The device according to claim 6, wherein the device further comprises:
    接收模块,用于接收所述第二电子设备反馈的成功接入所述WiFi网络的信息,结束所述发送模块执行周期性向所述第二电子设备发送由映射得到的各个MAC地址作为目的地址的组播帧的步骤。a receiving module, configured to receive information that the second electronic device feeds back successfully to the WiFi network, and end the sending module to periodically send each MAC address obtained by mapping to the second electronic device as a destination address. The step of multicasting frames.
  11. 一种电子设备,其特征在于,包括处理器、通信接口、存储器和通信总线,其中,处理器,通信接口,存储器通过通信总线完成相互间的通信;An electronic device, comprising: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete communication with each other through the communication bus;
    存储器,用于存放计算机程序;a memory for storing a computer program;
    处理器,用于执行存储器上所存放的程序时,实现权利要求1-5任一所述的方法步骤。The method of any one of claims 1-5 is implemented when the processor is configured to execute a program stored on the memory.
  12. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-5任一所述的方法步骤。A computer readable storage medium, wherein the computer readable storage medium stores a computer program, the computer program being executed by a processor to implement the method steps of any of claims 1-5.
PCT/CN2018/120311 2018-02-06 2018-12-11 Wifi connection method and apparatus WO2019153869A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810118969.7 2018-02-06
CN201810118969.7A CN110120987B (en) 2018-02-06 2018-02-06 WiFi connection method and device

Publications (1)

Publication Number Publication Date
WO2019153869A1 true WO2019153869A1 (en) 2019-08-15

Family

ID=67519449

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/120311 WO2019153869A1 (en) 2018-02-06 2018-12-11 Wifi connection method and apparatus

Country Status (2)

Country Link
CN (1) CN110120987B (en)
WO (1) WO2019153869A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114697258A (en) * 2022-04-11 2022-07-01 网易(杭州)网络有限公司 Data communication method, device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100214978A1 (en) * 2009-02-24 2010-08-26 Fujitsu Limited System and Method for Reducing Overhead in a Wireless Network
CN105119957A (en) * 2015-07-10 2015-12-02 普联技术有限公司 Information transmission method and device used for intelligent device
CN105515845A (en) * 2015-11-30 2016-04-20 青岛海尔智能家电科技有限公司 Data transmission method, data receiving method, data transmitting end and data receiving end
CN107371219A (en) * 2016-05-13 2017-11-21 华为终端(东莞)有限公司 WiFi collocation methods, WiFi mobile terminals and WiFi equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104065765A (en) * 2014-07-09 2014-09-24 杭州古北电子科技有限公司 WIFI data transmitting method and system and related method thereof
CN104660726B (en) * 2015-02-03 2018-11-27 普联技术有限公司 Network collocating method, the apparatus and system of smart machine
CN105101102B (en) * 2015-07-01 2019-01-25 北京奇虎科技有限公司 Multicast transmission method, information extracting method and corresponding terminal and equipment
US10355923B2 (en) * 2015-11-02 2019-07-16 Mobitv, Inc. Self-configuration of wireless connections
CN106973124A (en) * 2017-03-02 2017-07-21 深圳壹秘科技有限公司 Network connection collocation method and its electronic installation

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100214978A1 (en) * 2009-02-24 2010-08-26 Fujitsu Limited System and Method for Reducing Overhead in a Wireless Network
CN105119957A (en) * 2015-07-10 2015-12-02 普联技术有限公司 Information transmission method and device used for intelligent device
CN105515845A (en) * 2015-11-30 2016-04-20 青岛海尔智能家电科技有限公司 Data transmission method, data receiving method, data transmitting end and data receiving end
CN107371219A (en) * 2016-05-13 2017-11-21 华为终端(东莞)有限公司 WiFi collocation methods, WiFi mobile terminals and WiFi equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114697258A (en) * 2022-04-11 2022-07-01 网易(杭州)网络有限公司 Data communication method, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN110120987B (en) 2021-03-26
CN110120987A (en) 2019-08-13

Similar Documents

Publication Publication Date Title
US7356039B1 (en) Method and apparatus for describing multiple packets to hardware
US9674315B2 (en) Methods for dynamically binding header field identifiers in a network control protocol
US11606223B2 (en) Broadband remote access server (BRAS) system-based packet encapsulation
US9906491B2 (en) Improving transmission efficiency of data frames by using shorter addresses in the frame header
CN104702600B (en) A kind of configurable successively message parsing method and device
CN107750058A (en) Method, control terminal and the system of equipment access network based on wifi Beacon frames
WO2019205952A1 (en) Information processing method and apparatus
US10701524B2 (en) Multicast transmission method, information extraction method and corresponding terminal and device
WO2014180297A1 (en) Method and apparatus for processing messages
CN207766561U (en) A kind of system of control terminal and equipment access network
WO2016191990A1 (en) Packet conversion method and device
CN105893323A (en) Data reading method and data reading equipment
US10136375B2 (en) Method for service data management, apparatus, and system
EP3057256B1 (en) Method for processing stream media message, wifi chip and mobile terminal
CN110474922B (en) Communication method, PC system and access control router
WO2019153869A1 (en) Wifi connection method and apparatus
CN108989175B (en) Communication method and device
CN107835198B (en) Method and device for PPTP traversal in IPv4-IPv6 intercommunication scene and electronic equipment
WO2021031092A1 (en) Packet processing method and network device
US20140136597A1 (en) Relay enabled dynamic virtual private network
US8583822B2 (en) Method and system for minimum frame size support for a communication protocol encapsulated over Ethernet
WO2020103578A1 (en) Domain name query method, and related product
CN111614791A (en) Access device for entity link analysis and method thereof
US11259149B2 (en) Multicast method and apparatus
WO2022000766A1 (en) Transaction address locating system and method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18905508

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18905508

Country of ref document: EP

Kind code of ref document: A1