[En-Nut-Discussion] CHAT problem after hangup

Richard Tóth riso at dorm.utc.sk
Wed Jan 17 13:08:26 CET 2007


Hello all,

  i  want  to  make a permanent gprs connection, therefore i must deal with hangup and redialing the
  connection.
  but,  i  have a problem with chat after i hang up the connection. the modem responses good, but it
  seems, that the chat doesn't receive all the data, that the modem sends.

  any idea?

  debug console:
-------------------------------------------------------------------------------
PPP Client Sample - Nut/OS 4.2.1
Open uart...done
Chat trace flags=0x01

HEAP 26787 bytes RAM free
Connecting...Expect '', got ''
Send 'AT'
Expect 'OK', got 'AT\x0D\x0D\x0AOK'
Send 'AT+CGDCONT=1,"IP","internet"'
Expect 'OK', got 'AT+CGDCONT=1,"IP","internet"\x0D\x0D\x0AOK'
Send 'ATD*99***1#'
Expect 'CONNECT', got 'ATD*99***1#\x0D\x0D\x0ACONNECT'
done
Configure PPP...
[LCP-LOWERUP]
PPP<(20)[LCP-001(16)][CONFREQ][OPT(12)][ACCM=0x000A0000][MAGIC=0x78563412]
PPP>(32)[LCP-032(28)][CONFREQ][OPT(24)][MRU=1600][AUTH=0xC023][MAGIC=0x0C3C65C9][ACCM=0x00000000][PCOMP][ACOMP]
PPP<(32)[LCP-032(28)][CONFACK][OPT(24)][MRU=1600][AUTH=0xC023][MAGIC=0x0C3C65C9][ACCM=0x00000000][PCOMP][ACOMP]
PPP>(20)[LCP-001(16)][CONFACK][OPT(12)][ACCM=0x000A0000][MAGIC=0x78563412]
PPP<(10)[PAP-003(6)][CONFREQ][OPT(2)]
PPP>(43)[PAP-003(39)][CONFACK]
[IPCP-LOWERUP]
PPP<(26)[IPCP-004(22)][CONFREQ][OPT(18)][ADDR=0.0.0.0][DNS1=0.0.0.0][DNS2=0.0.0.0]
PPP>(26)[IPCP-004(22)][CONFNAK][OPT(18)][ADDR=10.254.6.131][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP<(26)[IPCP-005(22)][CONFREQ][OPT(18)][ADDR=10.254.6.131][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP>(14)[IPCP-011(10)][CONFREQ][OPT(6)][ADDR=10.0.0.1]
PPP<(14)[IPCP-011(10)][CONFACK][OPT(6)][ADDR=10.0.0.1]
PPP>(20)[IPCP-005(16)][CONFNAK][OPT(12)][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP<(26)[IPCP-006(22)][CONFREQ][OPT(18)][ADDR=10.254.6.131][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP>(20)[IPCP-006(16)][CONFNAK][OPT(12)][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP<(26)[IPCP-007(22)][CONFREQ][OPT(18)][ADDR=10.254.6.131][DNS1=194.154.230.66][DNS2=194.154.230.74]
PPP>(26)[IPCP-007(22)][CONFACK][OPT(18)][ADDR=10.254.6.131][DNS1=194.154.230.66][DNS2=194.154.230.74]done
     Local IP: 10.254.6.131
    Remote IP: 10.0.0.1
  Primary DNS: 194.154.230.66
Secondary DNS: 194.154.230.74
Creating socket...done

Socket     Typ Local                  Remote                 State
    0x16cc UDP   5000

Sending data...
PPP<(45)rc=0

PPP>(73)
Sending data...
PPP<(45)rc=0

PPP>(73)
Sending data...
PPP<(45)rc=0

PPP>(73)
[LCP-CLOSE]
[IPCP-LOWERDOWN]
PPP<(8)[LCP-007(4)][TERMREQ]
PPP>(8)[LCP-007(4)][TERMACK]
[IPCP-CLOSE]
***********************************************
here is the reconeect for second time
***********************************************
Open uart...
[IPCP-OPEN]
[LCP-OPEN]done
Chat trace flags=0x01

HEAP 25141 bytes RAM free
Connecting...Expect '', got ''
Send 'AT'
Expect 'OK', got 'A' TIMEOUT
no connect, reason = 3
Connecting...Expect '', got ''
Send 'AT'
Expect 'OK', got '' TIMEOUT
no connect, reason = 3
Connecting...Expect '', got ''
Send 'AT'
Expect 'OK', got 'A' TIMEOUT
no connect, reason = 3
Connecting...Expect '', got ''
Send 'AT'
Expect 'OK', got '  
-------------------------------------------------------------------------------
the modem sends AT OK, but chat catch only A or nothing.



code:
-------------------------------------------------------------------------------
#define PPPUSER     ""
#define PPPPASS     ""
#define PPPCHAT         "TIMEOUT 5 '' AT OK AT+CGDCONT=1,\"IP\",\"internet\" OK ATD*99***1# CONNECT"

#define PPPDEV      devAhdlc0
//#define PPPDEV      devUart0
#define PPPCOM      "uart0"
#define PPPSPEED    57600
#define PPPRXTO     1000

#define DBGDEV      devDebug1
#define DBGCOM      "uart1"
#define DBGSPEED    115200

#define RXBUFFSIZE  8192

#include <cfg/os.h>
#include <dev/debug.h>
#include <dev/ahdlcavr.h>
#include <dev/uartavr.h>
#include <dev/ppp.h>
#include <dev/chat.h>
#include <dev/board.h>

#include <sys/version.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/socket.h>

#include <sys/timer.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <net/if_var.h>
#include <net/route.h>

#ifdef NUTDEBUG
#include <net/netdebug.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>

PPPDCB *dcb;
UDPSOCKET *sock;

prog_char vbanner_P[] = "\n\nPPP Client Sample - Nut/OS %s\n";
prog_char mem_fmt_P[] = "\nHEAP %u bytes RAM free\r\n";

char tab[] = "Ahoooooooj.\r\n"; 


static void HFree(void)
{
        fprintf_P(stdout, mem_fmt_P, NutHeapAvailable());
}

// PPP client application entry.
int main(void)
{
    int pppcom;
    u_long lctl;
    int rc;

    NutRegisterDevice(&DBGDEV, 0, 0);
    
    if(freopen("uart1", "w", stdout) == 0) 
        {
        for(;;);
    }
    
    lctl = DBGSPEED;
    _ioctl(_fileno(stdout), UART_SETSPEED, &lctl);

    printf_P(vbanner_P, NutVersionString());

    NutRegisterDevice(&PPPDEV, 0, 0);
        NutRegisterDevice(&devPpp, 0, 0);

        for(;;)
        {
            printf("Open uart...");
            if ((pppcom = _open("ppp:" PPPCOM "/" PPPUSER "/" PPPPASS, _O_RDWR | _O_BINARY)) == -1) 
                {
                printf("Failed to open " PPPCOM "\n");
                for (;;);
            }
            puts("done");
        
            lctl = PPPSPEED;
            _ioctl(pppcom, UART_SETSPEED, &lctl);
            
                lctl = UART_RTSENABLED | UART_CTSENABLED;
                _ioctl(pppcom, UART_SETFLOWCONTROL, &lctl);
                        
            lctl = PPPRXTO;
            _ioctl(pppcom, UART_SETREADTIMEOUT, &lctl);
        
#ifdef NUTDEBUG
                NutTraceTcp(stdout, 0);
            NutTracePPP(stdout, 1);
            NutTraceChat(stdout, 1);
#endif
        
                HFree();
                
            // PPP connection loop.
            for (;;) 
                {
                printf("Connecting...");
                
                rc = NutChat(pppcom, PPPCHAT);
                if (rc != 0) 
                        {
                    printf("no connect, reason = %d\n", rc);
                    continue;
                }
                puts("done");
        
                printf("Configure PPP...");
                rc = NutNetIfConfig("ppp", 0, 0, 0);
                if (rc != 0) 
                        {
                    puts("failed");
                                        
                    continue;
                }
                puts("done");
        
                dcb = devPpp.dev_dcb;
                NutDnsConfig2(0, 0, dcb->dcb_ip_dns1, dcb->dcb_ip_dns2);
                NutIpRouteAdd(0, 0, dcb->dcb_remote_ip, &devPpp);
        
                printf("     Local IP: %s\n", inet_ntoa(dcb->dcb_local_ip));
                printf("    Remote IP: %s\n", inet_ntoa(dcb->dcb_remote_ip));
                printf("  Primary DNS: %s\n", inet_ntoa(dcb->dcb_ip_dns1));
                printf("Secondary DNS: %s\n", inet_ntoa(dcb->dcb_ip_dns2));
                
                printf("Creating socket...");
                        sock = NutUdpCreateSocket(5000);
                        if (sock != 0)
                        {
                                printf("done\n");
                                NutDumpSocketList(stdout);
                                int i, rt;
                                for (i = 0; i < 3; i++) 
                                {
                                        printf("\nSending data...");
                                        rt = NutUdpSendTo(sock, inet_addr("158.193.83.88"), 5000, tab, strlen(tab));
                                        printf("rc=%d\n", rt);
                                        NutSleep(1000);
                                }
                        }
                        else
                        {
                                printf("failed\n");
                        }
                        
                        _ioctl(pppcom, LCP_CLOSE, 0);
                        NutSleep(2000);                 
                        _close(pppcom);
                        break;
            }
    }
}
-------------------------------------------------------------------------------


-- 
Greetings,                         
 Risko 

 ICQ: 223531718
 http://www.risko.org




More information about the En-Nut-Discussion mailing list