Dialing into TINI from a PC (TINI as a PPP Server) | Kickoff

Dialing into TINI from a PC (TINI as a PPP Server)

11 May

Example: Dialing into TINI from a PC (TINI as a PPP Server)

The previous example discussed how to make the TINI behave as a PPP client, where by client we mean dialing out to an ISP. Now, we’re going to make the TINI behave as a PPP server, where by server we mean answering a call placed by a PC dialing into the TINI. We are going to connect a cell phone acting as a modem to the TINI, then call the cell phone modem using our PC with a second modem and the house phone line.

This proceeds very much like the previous example, but getting the modem to answer and form a connection can be finicky. So, we’ll start by testing the process of answering an incoming call before messing with PPP. We used a Motorola, StarTAC4, model ST7868W, and its associated data connectivity kit (a package of stuff that allows you to use it as a modem). When connecting the cell phone to the TINI, we needed to put the specially modified crossover cable between the TINI and the cell phone data connectivity cable. Note that of the two cables shown in Figure 13-8a and

13-8b, only the one that had the fixed voltage spliced into it (13-8a) worked properly with the cell phone. Your cell phone may be different.

A Modem Call Answering Test: The ModemAnswerTest  class

The ModemAnswerTest class uses the answer() method from the Modem class to answer an incoming call. It exits immediately upon receiving the incoming call.

Listing 13-5: ModemAnswerTest.java

import java.io.*;

import javax.comm.*;

public class ModemAnswerTest   {

public static void main(String[] args) { Modem external = new Modem(); external.openSerialPort(args[0]); external.answer();

}

}

The program takes a single command line argument, the name of the serial port you wish to use. It can be run on a PC or a TINI. We’ll try this out using a cell phone and its associated data connectivity kit, which consists of a special serial cable that has a female DB9 connector on one end and a special connector on the other that mates with the phone. The trick: the phone we used needs to be put into the Incoming Data Only mode before it will answer under AT command control. The Incoming Data Only mode is selected under Phone Options/Data Setup selector from the keypad of the phone. The Data Setup choice will only show up in the menu if the special data connectivity cable is attached, and plugged into a computer. In the case of TINI, if we plug the data connectivity cable into our special cable, the phone instantly realizes the cable is connected. Then, from the keypad, you can select Phone Options, and Data Setup will be one of the choices. You can then change it to Incoming Data Only. If you connect the cell phone to a PC, however, the Data Setup option may only appear in the menu after you send the modem an AT command. The

difference has to do with the special cable we’re using when we connect it to a TINI. Other phones will most likely have their own quirks.

Let’s connect the phone to a TINI, using the special crossover cable that we made for TINI and the data connectivity cable for the cell phone. Then, we’ll dial the cell phone number from the modem in our PC. The object of this exercise is to see whether or not we can get the cell phone to see an incoming call, answer it, and see a CONNECT response from the modem.

To compile the program, create a separate folder and place ModemAnswerTest.java in it, as well as Modem.java. Make a bin folder in the same directory. Then type the following:

C:\> cd src

C:\> javac -bootclasspath %TINI_HOME%\bin\tiniclasses.jar

-d ..\bin ModemAnswerTest.java

C:\> cd ..

C:\> java -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency

-p %TINI_HOME%\bin\owapi_dependencies_TINI.jar

-f bin

-x %TINI_HOME%\bin\owapi_dep.txt

-o bin\ModemAnswerTest.tini

-d %TINI_HOME%\bin\tini.db

As we’ve done in previous examples, some of the command line arguments for the Java command have been shown on a separate line. Everything after java should be entered on the same line. Transfer the .tini file to your TINI stick via FTP, and via Telnet attempt the following as the root user. Once you run the program on the TINI, immediately bring up a Windows Dialup window and call the cell phone.

TINI /> downserver -s

Warning:  This will disconnect users on specified servers.

OK to proceed? (Y/N): y

[ Wed Feb 13 02:46:11 GMT 2002 ]   Message from System: Serial server stopped.

TINI /> java ModemAnswerTest.tini serial0

Sending: AT Receiving: AT

OK

Wait for 3 rings

RING RING

RING

Sending: ATA Receiving: ATA

Wait for CONNECT CONNECT

TINI />

It worked. When we dialed out from the PC, the cell phone saw the incoming call, answered it on the third ring, and waited for the CONNECT, then exited. We used the same dial-up setting that we used when we call our ISP: 8 data bits, No parity, 1 stop bit, no flow control. It should be noted that this is somewhat specific to this exact exercise. If you are using a different cell phone, or perhaps an external modem instead of a cell phone, your experience may be a bit different and there might be different or additional AT commands that you may need to do to get your phone or modem to answer and spot the CONNECT. Consult the documentation on your phone, and check out the Internet—specifically, the TINI archives. You may also want to search the Internet for information on your specific phone or modem. Once you get this step to work, you’re ready to add PPP connectivity to this.


Th
e PPPServer class

To make the TINI stick act as a PPP server, waiting for an incoming call and establishing a PPP connection, we will make a program that answers incoming calls, creates a PPP object, and implements the PPPEventListener. This class is called PPPServer. We’ll show it in its entirety below, and then work our way through it. It’s very similar to our previous example, PPPClient.

Listing 13-6: PPPServer.java

import java.io.*;

import javax.comm.*;

import com.dalsemi.tininet.ppp.*;

public class PPPServer implements PPPEventListener {

static SerialPort serialPort = null;

static PPP ppp;

public void pppEvent (PPPEvent e) {

switch(e.getEventType()) {

case PPPEvent.STARTING:

System.out.println(“PPP sent the STARTING event!”);

ppp.up(serialPort);

break;

case PPPEvent.UP:

System.out.println(“PPP sent the UP event!”);

ppp.addInterface(“ppp0”);

break;

case PPPEvent.AUTHENTICATION_REQUEST:

//We don’t have to do anything here, because

//We’re dialing out TO a server. break;

case PPPEvent.STOPPED:

System.out.println(“PPP sent the STOPPED event!”);

ppp.close();

break;

case PPPEvent.CLOSED:

System.out.println(“PPP sent the CLOSED event!”);

ppp.down(); ppp.removeEventListener(this); serialPort.close(); System.exit(0);

break;

default:

break;

}

}

public static void main(String[] args) { Modem external = new Modem(); external.openSerialPort(“serial0”); serialPort = external.serialPort; PPPServer ourListener = new PPPServer(); ppp = new PPP();

byte[] localAddress = new byte[] {(byte)192, (byte)168, (byte)10, (byte)9}; byte[] remoteAddress = new byte[] {(byte)192, (byte)168, (byte)10, (byte)12}; try {

ppp.close(); ppp.addEventListener(ourListener); ppp.setLocalAddress(localAddress); ppp.setRemoteAddress(remoteAddress); ppp.setACCM(0×00000000); ppp.setAuthenticate(false); ppp.setDefaultInterface(true);

} catch(Exception e) { System.out.println(e);

System.out.println(“The ppp methods failed”);

serialPort.close(); System.exit(0);

}

if (external.answer()) {

ppp.open();

} else {

System.out.println(“The dialer failed!”);

serialPort.close(); System.exit(0);

}

while(true) {

//run forever…

}

}

}

We first import the necessary libraries, one of which is TINI specific. We also declare our class, and declare two member variables, serialPort and ppp.

import java.io.*;

import javax.comm.*;

import com.dalsemi.tininet.ppp.*;

public class PPPServer implements PPPEventListener {

static SerialPort serialPort = null;

static PPP ppp;

Next, we have the pppEvent() method, which is required for imlementation of the PPPEventListener. There is no difference between this and the version we used in PPPClient. It takes a pppEvent() as an argument. The method itself consists simply of a switch statement that implements the PPP finite state machine that we discussed earlier in this chapter. Each possible pppEvent() is handled by a case in the switch statement, and each of these corresponds to a state in our FSM. Note, again, that we don’t do anything in the AUTHENTICATION_REQUEST state. As a server, this means that whoever calls in gets logged in without any kind of username or password authentication!  This isn’t good, and we’re going to fix this in the next example, but for now we’re keeping it simple.

public void pppEvent (PPPEvent e) {

switch(e.getEventType()) {

case PPPEvent.STARTING:

System.out.println(“PPP sent the STARTING event!”);

ppp.up(serialPort);

break;

case PPPEvent.UP:

System.out.println(“PPP sent the UP event!”);

ppp.addInterface(“ppp0”);

break;

case PPPEvent.AUTHENTICATION_REQUEST:

//We don’t have to do anything here, because

//We’re dialing out TO a server.

break;

case PPPEvent.STOPPED:

System.out.println(“PPP sent the STOPPED event!”);

ppp.close();

break;

case PPPEvent.CLOSED:

System.out.println(“PPP sent the CLOSED event!”);

ppp.down(); ppp.removeEventListener(this); serialPort.close(); System.exit(0);

break;

default:

break;

}

}

Finally, we have our main() method. It takes no arguments. We start by creating a

Modem object, opening a serial port, and creating our event listener.

public static void main(String[] args) { Modem external = new Modem(); external.openSerialPort(“serial0”); serialPort = external.serialPort; PPPServer ourListener = new PPPServer();

Next, we create our PPP object, which starts the PPP connection process. We now have to set values for the local and remote IP address for their respective PPP interfaces because we are now the server, and the client calling in will be expecting us to assign  one. We made up these numbers. If you choose to insert different ones, make sure they are on a different network than any other interfaces your TINI or PC may have.

ppp = new PPP();

byte[] localAddress = new byte[] {(byte)192, (byte)168, (byte)10, (byte)9};

byte[] remoteAddress = new byte[] {(byte)192, (byte)168, (byte)10, (byte)12};

We now add our event listener, set up a bunch of PPP connection parameters, and set PPP as our default interface. We also leave the setAuthenticate() method set to false, because we aren’t doing any authentication on the client calling in.

try { ppp.addEventListener(ourListener); ppp.setLocalAddress(localAddress); ppp.setRemoteAddress(remoteAddress); ppp.setACCM(0×00000000); ppp.setAuthenticate(false);

ppp.setDefaultInterface(true);

} catch(Exception e) { System.out.println(e);

System.out.println(“The ppp methods failed”);

serialPort.close(); System.exit(0);

}

We call the answer method from the Modem class. It will wait for three rings, answer the call, then wait for the CONNECT. If the CONNECT comes, it will call the open() method, which starts us moving through the PPP FSM.

if (external.answer()) {

ppp.open();

} else {

System.out.println(“The dialer failed!”);

serialPort.close(); System.exit(0);

}

while(true) {

//run forever…

}

}

}

Once the connection is established, this program loops forever. If you’re in a Telnet window, simply form a connection right over the top of this or close that Telnet window and open another one. In this new Telnet window, you can now access the client with ftp and ping.

You can run applications under Slush that communicate with the client and they will use the IP interface established by PPPServer. To stop PPPServer, you will need to use the kill command. Let’s try running it.

Again, use a TINI connected to a PC via Ethernet. Connect the TINI to a modem (a cell phone in our case) via the specially made crossover cable and the cell phone’s data connectivity cable. To compile the program, create a separate folder and place PPPServer.java in it, as well as Modem.java. Make a bin folder in the same directory. Then type the following:

C:\> cd src

C:\> javac -bootclasspath %TINI_HOME%\bin\tiniclasses.jar

-d ..\bin PPPServer.java

C:\> cd ..

C:\> java -classpath %TINI_HOME%\bin\tini.jar;. BuildDependency

-p %TINI_HOME%\bin\owapi_dependencies_TINI.jar

-f bin

-x %TINI_HOME%\bin\owapi_dep.txt

-o bin\PPPServer.tini

-d %TINI_HOME%\bin\tini.db

As we’ve done in previous examples, some of the command line arguments for the java command have been shown on a separate line. Everything after java should be entered on the same line. Transfer the .tini file to your TINI stick via FTP, and via telnet attempt the following as the root user:

TINI /> downserver -s

Warning:  This will disconnect users on specified servers.

OK to proceed? (Y/N): y

[ Wed Feb 13 03:56:21 GMT 2002 ]   Message from System: Serial server stopped.

TINI /> java PPPServer.tini

Sending: AT Receiving: AT

OK

Wait for 3 rings

RING RING RING

Sending: ATA Receiving: ATA

Wait for CONNECT CONNECT

PPP sent the STARTING event! PPP sent the UP event!

Then, log into the same TINI via telnet either right on top of the current process, or in a different window. Run ipconfig –x:

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

Interface 2 is active.

Name          : ppp0 (default)

Type          : Point-to-Point Protocol

IP Address    : 198.168.10.9

Subnet Mask   : 255.255.255.0

Gateway       : 0.0.0.0

Interface 3 is not active.

It worked! You have a PPP connection with the PC, the TINI on 192.168.10.9 and the PC on 192.168.10.12. You can now log into the TINI using Telnet and FTP by referring to it as 192.168.10.9 and you will connect over the PPP interface, and if you refer to the TINI as 192.168.0.5, you will connect over the Ethernet interface.

The same comments we made about PPPClient apply here. We need to be the root user to do this, and we always need to start by shutting  down the serial server with the downserver –s command, or, disable the server by modifying the etc/.startup file, with the line setenv SerialServer  disable. To stop the PPPServer, you will have to use the kill command, and kill the PPPServer process.

And if things didn’t work for you? There are a number of things that can go wrong. You should power cycle the modem before running the program, make sure that any processes from previous PPPClient or PPPServer attempts are killed, and always shut down the serial server (or disable it). You may also want to double check to see that the connection preferences of your PC dial up adapter (data bits, parity, stop bits, flow control) match those being set in the program. With respect to compilation and TINIconvertor,  always use a separate directory in which the only java files are PPPServer.java  and Modem.java. Beyond this, if you’ve tested the modem answering process with the previous examples, but the PPP still doesn’t work, consider browsing the TINI archives on the web. There is a wealth of information about PPP out there. If everything above worked, but when you did the ipconfig –x  you did not see the ppp0 interface, try the last resort: clear the heap, reload the TINI firmware (tini.tbin, slush.tbin) and try again.

Random Posts

Comments are closed.