HelloXV1.77 Network Function Introduction

Source: Internet
Author: User
Tags network function bssid


HELLOXV1.77 's network function has been enhanced to a large extent, porting the industry's widely used LWIP protocol stack, and doing a lot of optimization work, fixed some of these bugs. At the same time, a network character interface application is implemented, which can be used to debug the Web functions. An abstract Ethernet management Framework (Ethernet framework) is implemented, which implements a standard network driver interface that masks the differences between different network drivers. This way, the driver code is different for different hardware, but it can be seamlessly attached to the Hellox kernel as long as you follow this standard set of interface specifications.

The following is a brief introduction to the V1.77 version of the network debugging program networks, on this basis, a brief introduction of the Hellox Network Driver programming method.

Network program

In character shell mode, enter network and return to enter the network application. The program provides some of the following network-related commands:

Scan command

This command is used to scan all available WiFi hotspots, provided that Wi-Fi hardware support is required. This command lists all the AP hotspots that were scanned, as follows:

[Network-view]scan

Available WiFi list:

-----------------------------

00:bssid = 20004e9c, RSSI =, SSID = ' hellox_hgw_ap ', channel = 1

01:bssid = 2000508C, RSSI =, SSID = ' celleden_map1600 ', channel = 6

If you find that the hotspot you want to connect to is not in the list above, you can perform a few more scan commands, and in many cases, a scan cannot scan to all hotspots.

ASSOC command

Assoc is used to associate with a specified WiFi hotspot. Scan only scans for available hotspots, but if you need to connect to a hotspot, you must use the Assoc command. As follows:

[Network-view]assoc Hellox_hgw_ap

The above command is used to connect to a WiFi hotspot named "Hellox_hgw_ap". Note that the WiFi hotspot must be an open unencrypted hotspot because the above command does not specify a connection password.

If you are connecting to an encrypted WiFi hotspot, you can specify the password for the connection using the/k parameter:

[Network-view]assoc hellox_hgw_ap/k0123456789012

followed by a password. Only WEP encryption is currently supported, so the password must be 13 bytes.

Again, the current value supports open unencrypted WiFi hotspots, as well as WEP-based Wi-Fi hotspots, which do not yet support WPA encryption hotspots, so if you want the connection to succeed, you must modify the configuration of the WiFi hotspot, modify it to open unencrypted, or use WEP encryption (the password is set to 13 digits).

Showint command

This command is used to display statistics on all network interfaces in the system, such as the number of messages received, the number of messages sent, etc. The following is a simple output example:

[Network_view]showint

Statistics information for interface ' Marvel_wlan_int ':

Send Frame #: 17

Success Send #: 17

Send bytes size:2946

Receive Frame #: 14

Success recv #: 14

Receive bytes size:1778

The meaning of each output field is self-explanatory.

Iflist command

The ability to enumerate all the network interfaces in the system, their corresponding IP address and other information. Unlike Showint, Iflist displays static information about the network interface (IP address/mask/default gateway, etc.), while Showint shows the dynamic information of the network interface.

Here is an example of an output from iflist:

[Network_view]iflist

--------------------------------------

Inetface Name:ma

IPv4 address:192.168.43.173

IPv4 mask:255.255.255.0

IPv4 gateway:192.168.43.1

Interface mtu:1500

--------------------------------------

Inetface Name:lo

IPv4 address:127.0.0.1

IPv4 mask:255.0.0.0

IPv4 gateway:127.0.0.1

Interface mtu:0

The above shows two network interfaces, the first of which is the WLAN interface, and the name contains only 2 bytes from the beginning.

Setif command

The Setif command modifies the static configuration parameters of the interface. For example, you can set a static IP address for a network interface in the following ways:

Setif marvel_wlan_int/a 192.168.0.100/m 255.255.255.0/g 192.168.0.1

Where Marvel_wlan_int is the name of the interface (the Showint command can be displayed), followed by the IP address/subnet mask/default gateway of the interface, respectively. It is important to note that, by default, DHCP is enabled on the interface, attempting to obtain an IP address automatically. Once the static IP address is set by the above command, the DHCP function on that interface is also turned off.

If you want to reopen the DHCP feature, use the following command:

Setif marvel_wlan_int/d Enable

The following commands are used to restart the DHCP functionality on the interface:

Setif marvel_wlan_int/d Enable

The purpose of restarting the DHCP feature is to immediately make a DHCP request on the interface. By default, the DHCP function sends a DHCP request message in exponential Backoff, that is, when the interface is just enabled, a DHCP request is sent, and if no response is received, it is sent again after 2 seconds, then 4 seconds, then 8 seconds ... And so on If you want to re-issue the DHCP request on the interface immediately, use the above command restart.

ping command

This is the most commonly used diagnostic command, followed directly by the IP address. Here is a simple example of output:

[Network_view]ping 192.168.43.1

Ping 192.168.43.1 with bytes packet:

[0] Reply from 192.168.43.1,size = 64,time = (ms)

[1] Reply from 192.168.43.1,size = 64,time = (ms)

[2] Reply from 192.168.43.1,size = 64,time = (ms)

Ping Statistics:total send = 3,received = 3,0 loss.

If you want to change the default ping message length, you can add a parameter:

Ping 192.168.43.1/l 1024

The above command is a ping message length of 1024 bytes. By default, three messages are continuously ping and then end. If you want to ping more messages, use the following command:

Ping 192.168.43.1/c 1000

The above command can ping1000 a message. Of course, the L parameter and the C parameter can be used together.

Hellox Network Driver Authoring method

Hellox implements a thread-polling-based Ethernet driver framework that has a thread called Eth_thread that periodically polls the NIC driver (every 100ms) in an attempt to receive a data frame. If a suitable data frame arrives, Eth_thread will submit the data frame to the IP layer for processing.

Therefore, to implement an Ethernet driver, you need to follow the Hellox Ethernet driver framework, specifically, to implement the following functions:

initialization function

The prototype is as follows, this function is called by Hellox when the Ethernet driver is loaded, and is used to complete the initialization function of the hardware. Of course, if initialization is not required, it can be written in the following form:

Static BOOL Int_init (__ethernet_interface*pint)

{

Returntrue;

}

The initialization of the hardware can also be placed in the driver's entry function, which is mentioned below.

Message sending function

The prototype is as follows:

Static BOOL Sendframe (__ethernet_interface*pint);

The Ethernet driver framework calls this function when the IP layer attempts to send a message. The data frames sent are already ready at the IP level (including the source MAC address/Destination MAC address, etc.) and stored in a buffer of the pint object (code below), the driver only needs to be sent.

typedef struct tag__ethernet_interface{

Char Ethname[max_eth_name_len +1];

Char Ethmac[eth_mac_len];

Char sendbuff[eth_default_mtu];//sending buffer.

int buffsize;

__eth_interface_state ifstate;

LPVOID Pl3interface;

LPVOID pintextension; Privateinformation.

......

}__ethernet_interface;

Where Sendbuff is the buffer that holds the data frame to be sent, buffsize is the length of the data frame and must be less than ETH_DEFAULT_MTU (1500).

In the Sendframe function, you only need to manipulate the hardware, send the contents of the Sendbuff to the physical network, and then return.

Data frame receive function

The function is prototyped as follows, and is periodically called by the Hellox Ethernet management framework to determine if there is a data frame arriving:

static struct Pbuf*recvframe (__ethernet_interface* pInt);

In this function, the hardware determines that a data frame arrives, you need to create a pbuf, copy the data frame from the hardware buffer into the PBUF, and return to the PBUF. For example, the following example code:

static struct Pbuf*marvel_recvframe (__ethernet_interface* pInt)

{

struct Eth_packet *rx_pkt =&pgmarvel_priv->rx_pkt;

struct Pbuf *p, *q;

U16 len = 0;

int l = 0;

char *buffer = NULL;

P= NULL;

/*obtain the size of the packet and put it into the "Len" variable. */

Len= lbs_rev_pkt ();

if (Len > 0) {

Buffer= rx_pkt->data;

/*we allocate a pbuf chain of pbufs from the pool. */

p= Pbuf_alloc (Pbuf_raw, Len, Pbuf_pool);

if (P! = NULL) {

for (q = p; Q! = NULL; q = q->next) {

memcpy ((u8_t*) q->payload, (u8_t*) &buffer[l], Q->len);

L= L + q->len;

}

}

Else

{

}

}

return p;

}

If the hardware determines that no data frame arrives, only null is required.

control functions for specific functions

The prototype is as follows:

Static BOOL Eth_ctrl (__ethernet_interface*pint,dword dwoperation,lpvoid pData);

For some Ethernet specific control functions, such as setting the MTU size, modification rate, WIFI scanning ap/attached AP, etc., through this function. Dwoperation refers to the action required.

If there is no special need, you may not need to implement the function. The recommended implementation is to implement an empty function that returns true only, such as:

Static Boolmarvel_ctrl (__ethernet_interface* Pint,dword dwoperation,lpvoid pData)

{

Returntrue;

}

Implementing the Driver Entry function

After implementing the above functions, you also need to implement an Ethernet driver entry function, which is called by the Hellox Ethernet management framework to load the Ethernet driver. In the entry function, you need to do a series of work:

1. initialize the hardware;

2. called Addethernetinterface, register the Ethernet interface with the system.

Here is an implementation example:

BOOL marvel_initialize (LPVOID pData)

{

__ethernet_interface*pmarvelint = NULL;

Char Mac[eth_mac_len];

Initialize the hardware, get the MAC address of the hardware, and store it in the Mac array.

Call Addethernetinterface, register the interface.

Pmarvelint= Ethernetmanager.addethernetinterface (

Marvel_eth_name,//Ethernet name, arbitrary string, cannot contain spaces.

&mac[0],//mac address.

NULL,//parameter of the initialization function.

Int_init,//interface initialization function, corresponding to the above Int_init function

Sendframe,//Data frame send function

Recvframe,//Data frame receive function

Eth_ctrl); Control functions.

if (null== pmarvelint)

{

Returnfalse;

}

Returntrue;

}

When calling Addethernetinterface, you need to use the four operation functions implemented above as parameters. After the call succeeds, an Ethernet object pointer is returned, which can be saved for later uninstallation of the Ethernet interface.

Add an entry in the Ethernet drive entry array

The final step is to add an entry in the Ethernet Driver entry function array to tell the operating system that the Ethernet driver exists. When the operating system is initialized, the driver entry function is called and the driver is loaded. The entry function array is in the Network/ethernet/ethentry.c file, and here is an example:

__ethernet_driver_entryethernetdriverentry[] =

{

#ifdef __cfg_net_marvellan

{Marvel_initialize,null},

#endif

Please add your Ethernet driver ' s entry here.

{Null,null}

};

Where Marvel_initialize is the driver entry function, NULL is the parameter of the entry function and can be any pointer. Note that the first network interface in the array is automatically set to the default network interface, the interface where the default gateway is located, or the interface where the default route is Hellox.

So the Ethernet driver is written to completion. It is recommended that the code for the Ethernet driver be stored in the Driver/stm32 directory. The Ethernet driver can be loaded by recompiling the Hellox.

After the Ethernet driver is loaded successfully, the network program can be consumed for diagnosis and debugging. You can enable code-level debugging if the command-level diagnostics do not identify the problem. Specifically, in the Ethif.h file, turn on the Ethernet Debug Switch (__eth_debug), recompile and load the run, to output more detailed information during the operation of the network.

The code for Hellox V1.77 can be downloaded from github:

Github.com/hellox-project/hellox_stm32

Have any questions, welcome to join QQ Group discussion: 38467832


HelloXV1.77 Network Function Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.