comparison packages/net/ppp/current/src/chat.c @ 1592:a9676dbe50b5

* src/chat.c: Script now returns success when it runs to completion
author nickg
date Thu, 15 Apr 2004 15:51:54 +0000
parents e0d88dc6a92f
children 5629b7c30ed2
comparison
equal deleted inserted replaced
1591:634e666b376d 1592:a9676dbe50b5
111 static cyg_io_handle_t cyg_ppp_chat_handle; 111 static cyg_io_handle_t cyg_ppp_chat_handle;
112 112
113 // String buffers 113 // String buffers
114 static char cyg_ppp_chat_buffer[CHAT_STRING_LENGTH]; 114 static char cyg_ppp_chat_buffer[CHAT_STRING_LENGTH];
115 static char cyg_ppp_chat_expect_buffer[CHAT_STRING_LENGTH]; 115 static char cyg_ppp_chat_expect_buffer[CHAT_STRING_LENGTH];
116
117 // success indicator
118 static int cyg_ppp_chat_success;
119 116
120 //===================================================================== 117 //=====================================================================
121 // Timeout alarm function 118 // Timeout alarm function
122 // 119 //
123 // The alarm is set whenever we start looking for a match, if the alarm 120 // The alarm is set whenever we start looking for a match, if the alarm
365 externC cyg_int32 cyg_ppp_chat( const char *devname, 362 externC cyg_int32 cyg_ppp_chat( const char *devname,
366 const char *script[] ) 363 const char *script[] )
367 { 364 {
368 const char *s; 365 const char *s;
369 Cyg_ErrNo err; 366 Cyg_ErrNo err;
370 367 cyg_int32 result = 1;
371 cyg_ppp_chat_success = 0; 368
372 cyg_ppp_chat_thread = cyg_thread_self(); 369 cyg_ppp_chat_thread = cyg_thread_self();
373 cyg_ppp_chat_abort_count = 0; 370 cyg_ppp_chat_abort_count = 0;
374 cyg_ppp_chat_timeout = 45; 371 cyg_ppp_chat_timeout = 45;
375 372
376 while ((err = cyg_io_lookup(devname, &cyg_ppp_chat_handle)) < 0) { 373 while ((err = cyg_io_lookup(devname, &cyg_ppp_chat_handle)) < 0) {
385 &cyg_ppp_chat_alarm, 382 &cyg_ppp_chat_alarm,
386 &cyg_ppp_chat_alarm_obj); 383 &cyg_ppp_chat_alarm_obj);
387 384
388 385
389 // Now loop over script handling the elements in turn 386 // Now loop over script handling the elements in turn
390 while( (s = *script++) != NULL && cyg_ppp_chat_success == 0 ) 387 while( (s = *script++) != NULL )
391 { 388 {
392 int what = cyg_ppp_chat_expect( s ); 389 int what = cyg_ppp_chat_expect( s );
393 390
394 db_printf("%s(%d) what %d\n",__PRETTY_FUNCTION__,__LINE__,what); 391 db_printf("%s(%d) what %d\n",__PRETTY_FUNCTION__,__LINE__,what);
395 392
396 if( what == CHAT_FAIL ) 393 if( what == CHAT_FAIL )
397 { 394 {
398 cyg_ppp_chat_success = 1; 395 result = 0;
399 break; 396 break;
400 } 397 }
401 398
402 if( (s = *script++) != NULL ) 399 if( (s = *script++) != NULL )
403 { 400 {
427 break; 424 break;
428 } 425 }
429 } 426 }
430 } 427 }
431 428
429 if (s==NULL)
430 {
431 // the script ran to completion
432 result = 1;
433 }
434
432 // Finally, wait for the serial device to drain 435 // Finally, wait for the serial device to drain
433 { 436 {
434 cyg_uint32 zero = 0; 437 cyg_uint32 zero = 0;
435 cyg_uint32 len = sizeof(zero); 438 cyg_uint32 len = sizeof(zero);
436 439
438 CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, 441 CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN,
439 &zero, &len); 442 &zero, &len);
440 443
441 } 444 }
442 445
443 return cyg_ppp_chat_success; 446 return result;
444 } 447 }
445 448
446 //===================================================================== 449 //=====================================================================
447 // End of chat.c 450 // End of chat.c
448 451