The PPPCommand.java code

11 May

The PPPCommand.java code
The PPPCommmand.java code provides an implementation for the Slushcommand and PPPEventListener interfaces. The code  can be broken down into roughly three categories.

1. Code that implements the SlushCommand interface for the command ppp and its command line parameters.

2. Code that implements the PPPEventListener, implementing the FSM that we discussed earlier.

3. Misc utility methods.

•  closePPP()

•  closeSerialPort()

•  openSerialPort()

•  createIPFromString()

•  waitForCall()

•  waitFor()

•  ATCommand()

•  login()

•  an inner class called ModemCommand()

We’re not going to dive into the details of the code itself, beyond identifying some slight modifications we had to make in our experiments to get it to work. There are four changes you have to make in order to use the ppp command.

1.   Early in the PPPCommand.java file there is an inner class called ModemCommand. A ModemCommand object called dialSequence is later created. You must modify this to contain the phone number of your ISP. We also

found that it’s helpful to increase the timeout value from 30 to 60.

2.   In the execute() method, where the program decides whether or not to call a server, you must add the line ppp.setDefaultInterface(true); right after the line ppp.setPassword(password);

3.   In the waitForCall() method, after the first waitFor(“RING”,  null, 0);

line, add two more just like it.

4.   In the waitForCall() method, in the line

if (!atCommand(new  ModemCommand(“ATA\r”,  “CONNECT”,   25)))

change the timeout value of 25, to 120.

With those changes, rebuild Slush to include the PPPCommand class, so the command ppp is implemented. Detailed instructions for this are in Chapter 7.

TINI as a PPP client using the Slush command ppp

We’re now going to assume that you’ve succeeded in making the changes to Slush described in the previous section, and that you’ve succeeded at getting the PPPClient program to work on a TINI. So we know we’ve got a cable that works with your modem, and dialing strings that work, etc. Connect a modem to TINI serial0, Telnet into the TINI via Ethernet, and do the following commands. Be sure to substitute

your username and password, where you see the words username and password in the results below. (These are the username and password required by your ISP)

TINI /> downserver -s

Warning:  This will disconnect users on specified servers.

OK to proceed? (Y/N): y

[ Wed Feb 13 09:12:01 GMT 2002 ]   Message from System: Serial server stopped.

TINI /> ppp -d -x 0 -u username –p password

PPP connection established

TINI /> ipconfig -x Interface 0 is active. Name       : eth0

Type         : Ethernet

IP Address   : 192.168.0.5

Subnet Mask  : 255.255.255.0

Gateway      : 0.0.0.0

Interface 1 is active. Name      : lo

Type         : Local Loopback

IP Address   : 127.0.0.1

Subnet Mask  : 255.0.0.0

Gateway      : 0.0.0.0

Interface 2 is active.

Name         : ppp0 (default)

Type         : Point-to-Point Protocol

IP Address   : xxx.xxx.xx.xxx

Subnet Mask  : 255.255.255.0

Gateway      : 0.0.0.0

Interface 3 is not active.

TINI />  ppp   -c

PPP   connection closed

It pays to use a modem that has a speaker, because that will give you some feedback as to where you are in the dialing process. There can be a long pause (~1 minute) between issuing the command and getting the PPP connection established message. Where you see xxx.xxx.xx.xxx in the results, your server assigned IP address will appear. The ppp –c command is used to shut down the PPP connection. We only showed this here because you need to shut down the connection before we open it again, which is what we’re going to do in the next section.

Random Posts

Comments are closed.