/[pengfork]/pengfork/src/modem.c
ViewVC logotype

Diff of /pengfork/src/modem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by nes, Thu Aug 29 21:18:46 2002 UTC revision 1.9 by chupa, Fri Aug 30 08:26:00 2002 UTC
# Line 297  modem_log_into_aol () Line 297  modem_log_into_aol ()
297    debug (1, "Waiting for login prompt\n");    debug (1, "Waiting for login prompt\n");
298    if (!modem_wait_for (PARAM_MODEM_LOGIN_PROMPT, 60 * 1000))    if (!modem_wait_for (PARAM_MODEM_LOGIN_PROMPT, 60 * 1000))
299      return 0;      return 0;
300    
301    debug (1, "Sending server's login\n");    debug (1, "Sending server's login\n");
302    write (fd, PARAM_MODEM_SERVER_LOGIN, strlen (PARAM_MODEM_SERVER_LOGIN));    modem_sync_write (fd, PARAM_MODEM_SERVER_LOGIN, strlen (PARAM_MODEM_SERVER_LOGIN));
303    write (fd, "\r", 1);    modem_sync_write (fd, "\r", 1);
304    tcdrain (fd);    tcdrain (fd);
305    debug (1, "Waiting for password prompt\n");    debug (1, "Waiting for password prompt\n");
306    if (!modem_wait_for (PARAM_MODEM_PASS_PROMPT, 60 * 1000))    if (!modem_wait_for (PARAM_MODEM_PASS_PROMPT, 60 * 1000))
307      return 0;      return 0;
308    debug (1, "Sending server's password\n");    debug (1, "Sending server's password\n");
309    write (fd, PARAM_MODEM_SERVER_PASS, strlen (PARAM_MODEM_SERVER_PASS));    modem_sync_write (fd, PARAM_MODEM_SERVER_PASS, strlen (PARAM_MODEM_SERVER_PASS));
310    write (fd, "\r", 1);    modem_sync_write (fd, "\r", 1);
311    tcdrain (fd);    tcdrain (fd);
312    if (!modem_wait_for ("onnected", 60 * 1000))    if (!modem_wait_for ("onnected", 60 * 1000))
313      return 0;      return 0;
# Line 370  setup_modem (rtscts) Line 371  setup_modem (rtscts)
371      {      {
372        for (i = 0; i < 5; i++)        for (i = 0; i < 5; i++)
373          {          {
374            write (fd, "\r", 1);            modem_sync_write (fd, "\r", 1);
375            usleep (10 * 1000);            usleep (10 * 1000);
376          }          }
377        tcdrain (fd);        tcdrain (fd);
# Line 446  modem_hangup () Line 447  modem_hangup ()
447       we should only do this if we have received any response from the modem       we should only do this if we have received any response from the modem
448     */     */
449    tcdrain (fd);    tcdrain (fd);
450    write (fd, "\r", 1);    modem_sync_write (fd, "\r", 1);
451    for (i = 0; !modem_data_ready (200) && i < 10; i++)    for (i = 0; !modem_data_ready (200) && i < 10; i++)
452      write (fd, "\r", 1);      modem_sync_write (fd, "\r", 1);
453    tcdrain (fd);    tcdrain (fd);
454    
455    /* drop DTR for a while, if still online */    /* drop DTR for a while, if still online */
# Line 466  modem_hangup () Line 467  modem_hangup ()
467    if (modem_carrier ())    if (modem_carrier ())
468      {      {
469        /* need to do +++ manual-disconnect stuff */        /* need to do +++ manual-disconnect stuff */
470        write (fd, "+++", 3);     /* command line mode */        modem_sync_write (fd, "+++", 3);     /* command line mode */
471        usleep (1500 * 1000);        usleep (1500 * 1000);
472        write (fd, "ATH\r", 4);   /* hang-up command */        modem_sync_write (fd, "ATH\r", 4);   /* hang-up command */
473    
474        for (i = 0; modem_carrier () && i < 5; i++)        for (i = 0; modem_carrier () && i < 5; i++)
475          usleep (100 * 1000);          usleep (100 * 1000);
# Line 545  int Line 546  int
546  modem_data_ready (timeout)  modem_data_ready (timeout)
547       int timeout;       int timeout;
548  {  {
549    fd_set read;    fd_set readfd;
550    struct timeval tv;    struct timeval tv;
551    int sel;    int sel;
552    
553    if (fd == -1)    if (fd == -1)
554      return 0;      return 0;
555    
556    FD_ZERO (&read);    FD_ZERO (&readfd);
557    
558    FD_SET (fd, &read);    FD_SET (fd, &readfd);
559    
560    tv.tv_sec = timeout / 1000;    tv.tv_sec = timeout / 1000;
561    tv.tv_usec = (timeout % 1000) * 1000;    tv.tv_usec = (timeout % 1000) * 1000;
562    
563    sel = select (fd + 1, &read, NULL, NULL, &tv);    sel = select (fd + 1, &readfd, NULL, NULL, &tv);
564    if (sel <= 0)    if (sel <= 0)
565      return 0;      return 0;
566    else    else
# Line 575  modem_send_command (command, timeout, re Line 576  modem_send_command (command, timeout, re
576  {  {
577    debug (2, "Sending: %s\n", command);    debug (2, "Sending: %s\n", command);
578    
579    write (fd, command, strlen (command));    modem_sync_write (fd, command, strlen (command));
580    write (fd, "\r", 1);    modem_sync_write (fd, "\r", 1);
581    
582    /* Get the response from the modem with/without echo enabled */    /* Get the response from the modem with/without echo enabled */
583    if (!modem_readline(response, timeout, size))    if (!modem_readline(response, timeout, size))
584      return 0;      return 0;
585    if (!strcmp (response, command))  
586      if(!strcmp (response, command))
587      {      {
       /* FIXME: echo is enabled, it should't happen */  
588        if (!modem_readline(response, timeout, size))        if (!modem_readline(response, timeout, size))
589          return 0;          return 0;
590      }      }
# Line 674  modem_readline (response, timeout, size) Line 675  modem_readline (response, timeout, size)
675    
676    return 1;    return 1;
677  }  }
678    
679    /* Simulate a synchronous write */
680    int
681    modem_sync_write(fd,string,size)
682         int fd;
683         char *string;
684         size_t size;
685    {
686      fd_set writefd;
687      struct timeval tv;
688      int sel,total,nwrote;
689      char *p;
690    
691      if (fd == -1)
692        return 0;
693    
694      FD_ZERO (&writefd);
695      total=0;
696      p=string;
697      while(total<size)
698        {
699          FD_SET (fd, &writefd);
700          
701          tv.tv_sec = 0;
702          tv.tv_usec = 1000;
703          
704          sel = select (fd + 1, NULL, &writefd, NULL, &tv);
705          if (sel <= 0)
706            return 0;
707          nwrote=write(fd, string, size-total);
708          if(nwrote<=0)
709            return 0;
710          p+=nwrote;
711          total+=nwrote;
712        }
713    
714      return 1;
715    }
716    
717  #endif /* WITH_MODEM */  #endif /* WITH_MODEM */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26