[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
AIX Versions 3.2 and 4 Asynchronous Communications Guide

Modem Attachment and Configuration

The following section contains information necessary to attach and configure a modem to the native ports, 8-, 64-, and 128-port adapters on AIX.

Topics covered in this section include:

Prerequisites

Creating a TTY Device on AIX for Modem Attachment

Use the System Management Interface Tool (SMIT) to define a tty port for the device attachment. Most fields are for the general device type. The only field that can affect the modem is the Enable LOGIN field with the following values:

DISABLE No getty process is run on the port. Use this setting for dial-out only modem ports.
ENABLE A getty process is run on the port. Use this setting for dial-in modems only.
SHARE A getty process is run on the port, but the getty process allows programs to dial in and out of this port without manually changing to disable or enable. Use this setting for bidirectional port usage.
DELAY A getty is run on the port in bi-directional mode, but no herald is sent until the getty process receives a keystroke from the user.

Fields specific to the 128-port asynchronous adapter:

Force Carrier or Ignore Carrier Detect disable
Perform Cooked Processing in Adapter disable
Note: * This setting is set to disabled if the 10 pin RJ-45 connector is used. This setting should be enabled if the 8 pin RJ-45 connector is used.

Attaching the Modem to the Port

The next step is to physically attach the modem to the serial adapter port using appropriate cabling. If possible, avoid placing the modem and cabling near any high line-noise sources such as florescent lighting, light switches, or uninterruptable power supply (UPS) devices. Sudden, or continuous power fluctuations can cause problems with tty ports (see troubleshooting section for more information).

Programming the Modem

Most modems require customization of their default settings in order to function properly on the system unit. The commands and settings discussed in this section configure a Hayes compatible modem with the basic parameters needed for operation on the server's serial ports.

There are two methods of configuration commonly used. They are:

Configuring the Modem with the cu Command

The cu command is the interactive and convenient way to program a modem on the server. This command is in the /usr/bin directory and is a part of bosext1.uucp.obj licensed program product.

Prerequisites:

Procedure

  1. Add the following line to the /usr/lib/uucp/Devices file verifying that the letter D (Direct) is in the leftmost position in the file and that the # in tty# is replaced with the tty device number of the modem:
    Direct tty# - Any direct
    Direct tty43 - Any direct 
    Note: Any lines in this file that start with a # (pound sign) in the leftmost position are comments only.
  2. Verify that the tty is disabled. Enter: pdisable tty#.
  3. Enter: cu -ml tty#.
  4. The message Connected is displayed.
  5. Verify that you have the attention of the modem. Enter:
    AT

    The modem should respond with OK. If it does not respond to your command, refer to troubleshooting.

  6. Enter the following commands. The modem should respond with OK after each line is entered.
    AT&F    <enter> 
    ATE1    <enter> 
    AT&D2   <enter> 
    AT&C1   <enter> 
    ATS0=1  <enter> 
    ATS9=12 <enter> 
    AT&W    <enter> 
    ~.      <enter> (terminate connection)
    AT Command Descriptions
    AT&F Recall the factory configuration as the active configuration.
    ATE1 In command state, echo characters from the keyboard to the screen. (Make sure carrier is not ON on the port or modem.)
    AT&D2 Monitor the DTR signal. When an on-to-off transition of the DTR signal occurs, the modem hangs up and enters the command state.
    AT&D3 Monitor the DTR signal. When an on-to-off transition of the DTR signal occurs, the modem hangs up and resets.
    AT&W Write the storable parameters of the current configuration to memory.
    AT&C1 Track the status of the carrier detect signal.
    ATS0=1 Autoanswer.
    ATS9=12 Carrier-detect response time. Default is 6. Possible values are 1 to 255, in tenths of seconds.
  7. Enter ONE of the following commands on the AIX command line substituting the tty device number for n.
    penable  ttyn
    pshare   ttyn
    pdelay   ttyn
    pdisable ttyn
    The modem is now configured with the basic commands needed for most AIX serial communication needs.

Configuring the Modem with a C Program

Prerequisites:

Procedure

  1. Using a text editor such as /bin/vi, enter the following C code: for example, vi motalk.c.
    /*************************************************************/
    /* Motalk - A "C" program for modem setup.                   */
    /*                                                           */
    /* NOTE: This program is supplied as an example only and     */
    /* is not officially supported by IBM.                       */
    /*                                                           */
    /*                                                           */
    /* To create: vi motalk.c <enter>                            */
    /* Usage: motalk /dev/tty? [speed]                           */
    /*                                                           */
    */*************************************************************/ 
    #include <errno.h> 
    #include <stdio.h> 
    #include <signal.h> 
    #include <fcntl.h> 
    #include <termio.h>
    FILE *fdr, *fdw;
    int fd; 
    struct termio term_save, stdin_save; 
    void Exit(int sig) 
    {
       if (fdr) fclose(fdr); 
       if (fdw) fclose(fdw); 
       ioctl(fd, TCSETA, &term_save); 
       close(fd); 
       ioctl(fileno(stdin), TCSETA, &stdin_save); 
       exit(sig); 
    }
    main(int argc, char *argv[]) 
    {
       char *b, buffer[80]; 
       int baud = 0, num; 
       struct termio term, tstdin; 
       if (argc < 2 || !strcmp(argv[1], "-?")) 
       {
          fprintf(stderr, "Usage: motalk /dev/tty? [speed]\n");
          exit(1); 
       } 
       if ((fd = open(argv[1], O_RDWR|O_NDELAY)) < 0 )
       { 
        perror(argv[1]); 
        exit(errno); 
      } 
        if (argc > 2) 
      { 
           switch(atoi(argv[2])) 
           { 
             case   300: baud = B300;
                         break; 
             case  1200: baud = B1200; 
                         break; 
             case  2400: baud = B2400; 
                         break;  
             case  4800: baud = B4800; 
                         break;  
             case  9600: baud = B9600; 
                         break; 
             case 19200: baud = B19200; 
                         break; 
             case 38400: baud = B38400; 
                         break; 
             default:    baud = 0; 
                         fprintf(stderr, "%s: %s is an unsupported baud\n", argv[0], argv[2]);
                         exit(1);
             } 
          } 
    /* Save stdin and tty state and trap some signals */ 
    ioctl(fd, TCGETA, &term_save); 
    ioctl(fileno(stdin), TCGETA, &stdin_save); 
    signal(SIGHUP, Exit); 
    signal(SIGINT, Exit); 
    signal(SIGQUIT, Exit); 
    signal(SIGTERM, Exit); 
    /* Set stdin to raw mode, no echo */ 
    ioctl(fileno(stdin), TCGETA, &tstdin); 
    tstdin.c_iflag = 0; 
    tstdin.c_lflag &= ~(ICANNON | ECHO); 
    tstdin.c_cc[VMIN] = 0; 
    tstdin.c_cc[VTIME] = 0; 
    ioctl(fileno(stdin), TCSETA, &tstdin); 
    /* Set tty state */ 
    ioctl(fd, TCGETA, &term); 
    term.c_cflag |= CLOCAL|HUPCL; 
    if (baud > 0) 
    { 
       term.c_cflag &= ~CBAUD; 
       term.c_cflag |= baud; 
    } 
    term.c_lflag &= ~ECHO; 
    term.c_cc[VMIN] = 0; 
    term.c_cc[VTIME] = 10; 
    ioctl(fd, TCSETA, &term); 
    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY); 
    /* Open tty for read and write */ 
    if ((fdr = fopen(argv[1], "r")) == NULL ) 
    { 
       perror(argv[1]); 
       exit(errno); 
    } 
    if ((fdw = fopen(argv[1], "w")) == NULL ) 
    { 
       perror(argv[1]); 
       exit(errno); 
    } 
    /* Talk to the modem */ 
    puts("Ready... Press <ctrl> C to exit"); 
    while (1) 
    { 
       if ((num = read(fileno(stdin), buffer, 80)) > 0)
                           write(fileno(fdw), buffer, num); 
       if ((num = read(fileno(fdr), buffer, 80)) > 0)
                           write(fileno(stdout), buffer, num); 
    } 
    Exit(0); 
    } 
    /* ********************************************************* */
    /* ******************** END OF PROGRAM ********************* */
    /* ********************************************************* */
  2. Compile the above program using the system's C compiler.
     cc -o motalk motalk.c
  3. Run the program using the following syntax:
     motalk /dev/ttyn # 

    Where n is the number of the tty port and # is the speed of the tty port. For example, to set port 43 for 9600 bps, the syntax would be:

     motalk /dev/tty43 9600
  4. The program should run and display Ready...press <ctrl> C to exit. Use step 6 from Method 1 to program the modem. Press Ctrl-C to stop the program when finished.

Automated Modem Configuration

To program a modem automatically with a shell script, use the UUCP cu command. Create and run the following script:

#!/bin/ksh
tty=$1
shift
speed=$1
shift
{
       while [ -n "$1" ];do
       echo "$1/r"
       sleep 2
       shift
       done
       echo '~.'
{| cu -ml $tty -s $speed

[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]