Linux uses PPPD and PPP programs for 3G/4G dialing

Source: Internet
Author: User

Test environment: Linux marsboard 3.4.90 #9 SMP PREEMPT Thu Mar 3 18:28:43 CST armv7l armv7l armv7l gnu/linux (note: A20 Core Board)

Communication module, loaded into ttyusb* equipment;

Target: Use the communication module for 3G4G dial-up connection to the Internet

Method: Use PPPD and PPP programs to make dial-up Connections

Prerequisite: PPP, PPPD two programs installed

Summary: The Chat-script dial script for the file PPP involved (the situation needs to be adjusted for non-communication devices, this is not considered here, most of them can be used),

Steps:

1, create the PPP program dial script, the contents are as follows: (There are two, one for mobile, Unicom and telecom 4G, one is only for telecom 3G)

# for Mobile, Unicom and telecom 4G, filename chat-script

#!/bin/sh

EXEC chat-v \
TIMEOUT 5 \
ABORT "BUSY" \
ABORT "ERROR" \
ABORT "NO CARRIER" \
"\rat \"
Ok ' at+cgdcont=1, ' IP ', ' CMNET ' \
OK ' atdt*99# ' \
CONNECT ' \

-----------------different scripts to be split, there are no files in the file-----------------------------------------

#  for telecom 3G, filename chat-script-ct3g

#!/bin/sh
EXEC chat-v \
TIMEOUT 5 \
ABORT "BUSY" \
ABORT "ERROR" \
ABORT "NO CARRIER" \
"\rat \"
Ok ' at+cgdcont=1, ' IP ', ' CMNET ' \
OK ' atdt#777 ' \
CONNECT ' \

2. Create two dial-up scripts, ppp-on for dial-up Connections Ppp-off user disconnects

# file Ppp-on

#! /bin/sh

# string Number $/baud rate $3chat script
PPPD modem-d-detach Lock $ kdebug 4 file/etc/ppp/options crtscts noipdefault netmask 255.255.255.0 defaultroute con Nect

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

# file Ppp-off

#!/bin/sh
######################################################################
#
# determine the device to be terminated.
#
if ["$" = ""]; Then
device=ppp0
else
device=$1
fi

######################################################################
#
# If The ppp0 PID file is present and the program is running. Stop it.
if [-r/var/run/$DEVICE. pid]; Then
kill-int ' cat/var/run/$DEVICE. PID '
#
# If The kill did not work then there are no process running for this
# PID. It may also mean, that the lock file would be a left. Wish
# To delete the lock file at the same time.
IF [! "$?" = "0"]; Then
rm-f/var/run/$DEVICE. PID
echo "error:removed stale pid file"
Exit 1
fi
#
# Success. Let PPPD and its own junk.
echo "PPP link to $DEVICE terminated."
Exit 0
fi
#
# The PPP process is not a running for ppp0
echo "ERROR:PPP link isn't active on $DEVICE"
Exit 1

3. How to use

Give execute permission to the four script files above and execute with root permission

./PPP-OF/DEV/TTYUSB1 115200 Chat-script (Specific path)

Use Ifconfig to view the results of dialing

4, attached to the script you wrote, which calls the above dial-up script

#! /bin/sh
Wr= "/home/marsboard/pppd-net"

# string Number $ baud rate $3chat script $4 ppp-on log
${wr}/ppp-on $ ${wr}/$3 > ${wr}/$4 &
Sleep 8

# Get dialing information from the ppp-on log
Interfacename= "Using Interface"
Addressipname= "Local IP address"
Gatewayname= "Remote IP address"

interface= ' grep "$INTERFACENAME" ${wr}/$4|awk ' {print $} '
addressip= ' grep ' $ADDRESSIPNAME ' ${wr}/$4|awk ' {print $4} '
gatewayip= ' grep "$GATEWAYNAME" ${wr}/$4|awk ' {print $4} '

# Determine if dial is successful
For n in ' seq 3 '
Do
Ping-c 1 ${addressip}-I ${interface} >/dev/null 2>&1
If [$?-eq 0]
Then
echo "PPP successed!!"
echo "${interface}, ${addressip}, ${gatewayip}"
Return
Fi
Done
echo "PPP failed!!"

Linux uses PPPD and PPP programs for 3G/4G dialing

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.