Linux PPP Internet access

Source: Internet
Author: User

This article describes how to use a CDMA modem to implement dial-up Internet access in Linux. First, you need to have a preliminary understanding of the PPP protocol. For example, you should at least know what the LCP and NCP are and what the PAP and chap are. Second, you may need to install pppd and chat tools. These two tools are installed by default in the system. If pppd is not installed, download the latest version at http://ppp.samba.org. The pppd version used by the author in this article is 2.4.1, And the chat version is 1.22.

This article uses the China Unicom mobile broadband subscription 2G traffic CDMA network card. The dialing number required for the connection is #777, the user name is card, and the password is also card. The connection server name is pdsn.

In Linux, all PPP-related configuration files are in the/etc/PPP/directory. The/etc/PPP/PAP-secrets file stores the user name and password required for the PAP authentication protocol, the/etc/PPP/chap-secrets file stores the username and password required by the CHAP authentication protocol. According to the preceding instructions, the content of the two files is as follows:

File/etc/PPP/PAP-secrets (the last line is manually added by the author ):
#/Etc/PPP/PAP-secrets
# Secrets for authentication using pap
# Client
Server
Secret
IP addresses
####### RedHat-config-network will overwrite this part !!! (BEGIN )##########
####### RedHat-config-network will overwrite this part !!! (End )############
Card
Pdsn
Card

File/etc/PPP/chap-secrets (the last line is manually added by the author ):
#/Etc/PPP/chap-secrets
# Secrets for authentication using chap
# Client
Server
Secret
IP addresses
####### RedHat-config-network will overwrite this part !!! (BEGIN )##########
####### RedHat-config-network will overwrite this part !!! (End )############
Card
Pdsn
Card

When the server requires pppd to provide user authentication information, if the negotiation adopts the PAP authentication method, pppd will obtain the user password in the/etc/PPP/PAP-secrets file; if CHAP authentication is adopted, pppd obtains the user password in the/etc/PPP/chap-secrets file.

In the/etc/PPP/peers/directory, it is the option file required for each pppd connection. Each file corresponds to a connection and does not interfere with each other. In this article, a Unicom file is created under the/etc/PPP/peers/directory, and its content is as follows:
#/Etc/PPP/peers/Unicom
# This is PPP script for use chinaunicom's CDMA Data Service
#
Ttys0
115200
Crtscts
Connect '/usr/sbin/chat-v-F/etc/PPP/chat/Unicom'
Debug
Nodetach
Ipcp-Accept-Local
Ipcp-Accept-remote
Defaultroute
User card

Here, we will explain the pppd options:
L
Ttys0
Indicates that the CDMA modem is connected to the serial port/dev/ttys0;
L
115200
Indicates the serial port baud rate;
L
Crtscts
It indicates that the series of RTS and CTS signals using modem are used for traffic control;
L
Connect '/usr/sbin/chat-v-F/etc/PPP/chat/Unicom'
Indicates the session established by using the chat program. The session is controlled through the/etc/PPP/chat/Unicom file.
L
Debug
Indicates that pppd is working in debugging mode.
L
Nodetach
Do not convert pppd to background process after startup
L
Ipcp-Accept-Local
Accept the local IP address assigned by the server
L
Ipcp-Accept-remote
Accept the Server IP address specified by the server
L
Defaultroute
Indicates that the server IP address specified by the server is used as the default route.
L
User card
Indicates that the user during authentication is card, and pppd obtains the password of the card user from the/etc/PPP/PAP-secrets or/etc/PPP/chap-secrets file accordingly.

The above is the description of/etc/PPP/peers/Unicom. In addition, the last file required is/etc/PPP/chat/Unicom, which is used to tell the chat program how to complete the connection establishment process. The file content is as follows:
#/Etc/PPP/chat/Unicom
# This is the chat script for Unicom
Abort "no carrier"
Abort "No dialtone"
Abort "error"
Abort "No answer"
Abort "busy"
Timeout 120
""
Okay atdt #777
Connect

Several abort lines mean that if the modem returns information such as busy, the chat process is canceled and the connection fails. Timeout 120 indicates that the connection timeout value is 120 seconds. Issue an AT command First, expect the modem to return an OK, then dial #777, expect the modem to return connect. If the modem returns connect, the connection is established successfully.

The preceding figure shows the four files required for dialing. Use the following command to dial:
# Pppd call Unicom

If the dial is successful, a new network interface ppp0 is generated. The server will automatically assign an IP address to ppp0. Then, you can access the Internet through this connection.

Note: The author tries to obtain larger bandwidth through Multilink PPP, but it seems that China Unicom does not support this function.

References
[1] MAN pppd (8)
[2] man chat (8)

Original address http://blog.chinaunix.net/u/270/showart_227618.html

Another reference design

3. Software Design

3.1 Linux kernel Compilation

Embedded system resources are limited, so it is impossible to compile programs on the embedded system. You need to compile the program into binary code recognized by the embedded system on a PC, and then transplant it to it. The cross-compiling environment is a tool used to compile the identifiable code of embedded systems on a PC. The cross-compilation environment used here is arm-Linux. To compile PPP support into the Linux kernel, enter make menuconfig in the kernel directory, select Network Device Support, and select [*] All PPP options, save and exit compilation.

3.2 PPP transplantation [1]

Point-to-Point Protocol (PPP) is a standard method for transmitting multi-protocol data packets over point-to-point connections. The CDMA wireless connection method used in this paper requires the support of PPP protocol, the version used here is PPP-2.4.1 and rp-PPPoE-3.7. The compilation method is to compile in the established cross-compilation environment, generate executable files such as pppd and chat, and write them into the/bin directory of the file system ramdisk. Write three dialing script files in the file system/PPP directory.

The first script file is chap-secrets:

"Card" * "card"

The cards are the user name and password respectively. * indicates that there is no limit on the server.

The second script file is CDMA 1:

Ttys0 # connect the CDMA modem to serial port 1

19200 # CDMA baud rate

Nocrtscts # Do not use modem's RTS and CTS signal line flow control

Connect '/bin/chat-v-F/etc/PPP/chat/CDMA' # Use the chat program to complete the session creation process, sessions should be controlled through the/etc/PPP/chat/CDMA 2 File

Debuf # indicates that pppd works in debugging mode

Nodetach # indicates that pppd is not allowed to be transferred to the background for work.

Ipcp-Accept-local # indicates accepting the local IP address assigned by the server

Ipcp-Accept-remote # indicates accepting the Server IP address specified by the server

Defaultroute # sets the IP address specified by the server as the default route.

User card # indicates the user name card during authentication. pppd obtains the password from the chat-secrets file based on the user name.

The third script file is CDMA 2:

Abort "no carrier"

Abort "No dialtone"

Abort "error"

Abort "no answer"

Abort "busy"

Timeout 120

""

Okay atdt #777

Connect

The code above indicates that if no carrier or other returned information is displayed during the modem dialing process, the chat process is canceled and the connection fails. If the value of timeout 120 is used, the connection times out, atdt #777 indicates dialing to #777.

After setting, enter pppd in the development board environment. If garbled characters appear, the PPP port is migrated correctly. Enter the dialing command pppd call CDMA 1 to generate a new network interface ppp0, and the server automatically assigns an IP address. At this time, the transplantation and Setup of PPP are complete, that is to say, an embedded system that can access the Internet has been created.

3.3 email sending program design [2]

To send images collected by the image acquisition terminal to an email, they must be sent as attachments. In the process of sending an email, you must encrypt the email address, user password, and attachment content. The base64 encryption method is used here. The base64 algorithm is based on three bytes. When the remaining number of characters is less than three bytes, 0 should be used for filling, take 6 digits of data in sequence and add two zeros to form a new 8-bit code. Because 3*8 = 4*6, in this way, the input of three bytes will become the output of four bytes, And the length will increase by 1/3. Correspondingly, the output character uses '=', so one to two '=' may appear at the end of the encoded text '.

The email sending program goes through the following processes [3]:

(1) socket (INT domain, int type, int Protocol );

This function creates a new socket to create a new communication port and obtain the file descriptor. The parameter domain in the function determines a protocol family, which is defined as af_inet. Type specifies the socket type, where sock_stream is used, and protocol is generally 0. The default protocol is used.

(2) connect (INT sockfd, struct sockaddr * address, size_t address_len );

After a socket is called to establish a transmission port, call the connect function to establish a connection line connected to the remote server.

(3) Recv (INT sockfd, void * Buf, int Len, unsigned int flags );

This function is used to receive information from the set interface. Socket uses the set interface connected by connect. Buf is a pointer to the memory block for storing received messages. Len indicates the size of the memory block, flags is an operation flag.

(4) base64_code (); // encrypt the login information or attachment content

(5) Send (INT sockfd, const void * MSG, int Len, unsigned int flags );

This function is used to transmit data to other programs through a set of interfaces. Sockfd is the socked descriptor used to transmit data. MSG is a pointer to the data to be sent. Len is the length of the data in bytes, and flags is usually set to 0.

To send an attachment file, you must set the number of bytes read each time and the number of bytes sent each time in advance, and send the attachment in batch read encoding. Program Execution Process 3:

 

Figure 3 data transmission process

 

4. Summary

Experiments show that data is sent over CDMA wireless networks at a stable speed. Sometimes the transmission fails due to network reasons, but the success rate is high, and the frame drop phenomenon of received image data is not obvious. This method can be used for industrial site monitoring, Home monitoring systems, and remote data collection. Because images are sent to emails, the operation cost is low and there is a large promotion space.

Innovations in this article: Currently, many researches have been made on GPRS-based wireless data transmission methods. The high performance of CDMA networks has gradually attracted the attention of researchers, in this paper, a system combined with embedded systems is designed in combination with CDMA networks to send the collected on-site images to emails as attachments.

 

This article from: (www.91linux.com) detailed source reference: http://www.91linux.com/html/article/network/pppoe/2010/1008/20881.html

Related Article

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.