6 #include <exec/types.h>
13 #include <dos/dostags.h>
14 #define SYS_Error SYS_Output
16 #include <intuition/gadgetclass.h>
17 #include <intuition/icclass.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/muimaster.h>
21 #include <proto/dos.h>
22 #include <proto/graphics.h>
23 #include <clib/alib_protos.h>
24 #include <proto/muimaster.h>
26 #define ClearDynNameServ()
27 #define AddDynNameServ(a)
28 #define EndDynNameServ()
29 LONG
XGET(Object
* obj
, ULONG attribute
)
33 get(obj
, attribute
, &x
);
37 #include <proto/miami.h>
39 #include <utility/hooks.h>
40 #include <libraries/mui.h>
41 #include <aros/debug.h>
42 #include <sys/socket.h>
43 #include <netinet/in.h>
48 #define SimpleText(text) TextObject, MUIA_Text_Contents, (IPTR) text, End
53 #define STATE_UNPLUGGED 0
54 #define STATE_PLUGGED 1
55 #define STATE_OPENDEV 2
56 #define STATE_NETWORK 3
57 #define STATE_CLOSEDEV 4
59 Object
*application
=0,*window
,*DisConBut
,*ConBut
;
60 Object
*ModemName
,*AccessType
;
61 Object
*IN_Info
,*OUT_Info
;
63 struct EasyBitmap
*SignalBM
=0;
65 UBYTE
*PortName
= "ModemManager";
66 const TEXT version_string
[] = "$VER: ModemManager 1.3 (30.9.2012)";
68 ULONG exPhase
,exstate
;
77 struct EasyBitmap
*MakeBitmap(ULONG x
,ULONG y
,Object
*MUIwindow
,Object
*MUIbitmap
){
78 struct EasyBitmap
*ebm
=NULL
;
79 struct Window
*tw
=NULL
;
81 if( MUIwindow
&& MUIbitmap
){
82 if( ebm
= AllocMem( sizeof(struct EasyBitmap
),MEMF_CLEAR
|MEMF_PUBLIC
)){
84 tw
=(struct Window
*)XGET( MUIwindow
, MUIA_Window_Window
);
86 ebm
->bm
= AllocBitMap(x
,y
,
87 GetBitMapAttr(tw
->RPort
->BitMap
, BMA_DEPTH
),
90 ebm
->rp
= CreateRastPort();
91 ebm
->rp
->BitMap
= ebm
->bm
;
92 ebm
->MUIbitmap
= MUIbitmap
;
93 set( MUIbitmap
, MUIA_FixWidth
, x
);
94 set( MUIbitmap
, MUIA_FixHeight
, y
);
95 set( MUIbitmap
, MUIA_Bitmap_Width
, x
);
96 set( MUIbitmap
, MUIA_Bitmap_Height
, y
);
97 set( MUIbitmap
, MUIA_Bitmap_Transparent
, 0 );
98 set( MUIbitmap
, MUIA_Bitmap_Bitmap
, ebm
->bm
);
99 DoMethod( MUIbitmap
, MUIM_Draw
);
105 void _CloseBitmap(struct EasyBitmap
*ebm
){
107 FreeRastPort(ebm
->rp
);
109 FreeMem(ebm
,sizeof(struct EasyBitmap
));
112 #define CloseBitmap( ebm ) do{_CloseBitmap(ebm);ebm=NULL;}while(0)
116 struct EasyBitmap
*ebm
;
122 void _CloseGraph(struct EasyGraph
*egr
){
124 CloseBitmap( egr
->ebm
);
125 if( egr
->value
) FreeMem( egr
->value
, sizeof(FLOAT
) * egr
->Xsize
);
126 FreeMem(egr
,sizeof(struct EasyGraph
));
129 #define CloseGraph( x ) do{_CloseGraph(x);x=NULL;}while(0)
131 struct EasyGraph
*MakeGraph(ULONG x
,ULONG y
,Object
*MUIwindow
,Object
*MUIbitmap
){
132 struct EasyGraph
*egr
=NULL
;
133 if( MUIwindow
&& MUIbitmap
){
134 if( egr
= AllocMem( sizeof(struct EasyGraph
),MEMF_CLEAR
|MEMF_PUBLIC
)){
138 if( egr
->value
= AllocMem( sizeof(FLOAT
) * x
,MEMF_CLEAR
|MEMF_PUBLIC
)){
139 if( egr
->ebm
= MakeBitmap(x
,y
,MUIwindow
,MUIbitmap
) ){
140 SetRast(egr
->ebm
->rp
,0);
141 DoMethod( egr
->ebm
->MUIbitmap
, MUIM_Draw
);
142 }else CloseGraph(egr
);
149 void UpdateGraph(struct EasyGraph
*egr
,FLOAT value
){
154 get(application
, MUIA_Application_Iconified
, &iconified
);
156 if( !iconified
&& egr
){
158 for( i
= egr
->Xsize
-1 ; i
> 0 ; i
-- ){
159 egr
->value
[i
] = egr
->value
[i
-1];
162 egr
->value
[0] = value
;
163 if( value
> egr
->Max
) egr
->Max
= value
;
167 SetRast(egr
->ebm
->rp
,0);
168 SetAPen(egr
->ebm
->rp
,1);
169 Move(egr
->ebm
->rp
, 0 , egr
->Ysize
-1 );
170 Draw(egr
->ebm
->rp
, egr
->Xsize
-1 , egr
->Ysize
-1 );
171 SetAPen(egr
->ebm
->rp
,2);
173 if( egr
->Max
!= 0.0 ){
174 for( i
=0 ; i
< egr
->Xsize
; i
++ ){
175 h
= (LONG
)( egr
->value
[i
] / egr
->Max
* (FLOAT
)( egr
->Ysize
- 2 ) );
176 if(i
==0) Move(egr
->ebm
->rp
, i
, (egr
->Ysize
-2) - h
);
177 else Draw(egr
->ebm
->rp
, i
, (egr
->Ysize
-2) - h
);
180 Move(egr
->ebm
->rp
, 0 , egr
->Ysize
-2 );
181 Draw(egr
->ebm
->rp
, egr
->Xsize
-1 , egr
->Ysize
-2 );
184 DoMethod( egr
->ebm
->MUIbitmap
, MUIM_Draw
);
191 BOOL
SafePutToPort(struct PPPcontrolMsg
*message
, STRPTR portname
)
193 struct MsgPort
*port
;
195 port
= FindPort(portname
);
198 ForeachNode(&port
->mp_MsgList
,M
){
199 if( (APTR
)message
== (APTR
)M
){
200 // bug("SafePutToPort: message is already here !\n");
205 PutMsg(port
,(struct Message
*)message
);
208 return(port
? TRUE
: FALSE
);
211 BOOL
SendCtrlMsg(ULONG command
,IPTR Arg
,struct Conf
*c
){
212 struct PPPcontrolMsg
*CtrlMsg
=0;
213 struct MsgPort
*CtrlPort
=0;
215 if( CtrlPort
= CreatePort(0,0) ){
216 if( CtrlMsg
= AllocMem(sizeof(struct PPPcontrolMsg
),MEMF_PUBLIC
| MEMF_CLEAR
)){
218 CtrlMsg
->Command
= command
;
221 CtrlMsg
->DeviceName
= c
->DeviceName
;
222 CtrlMsg
->UnitNum
= c
->SerUnitNum
;
223 CtrlMsg
->username
= c
->username
;
224 CtrlMsg
->password
= c
->password
;
226 CtrlMsg
->Msg
.mn_Node
.ln_Type
= NT_MESSAGE
;
227 CtrlMsg
->Msg
.mn_Length
= sizeof(struct PPPcontrolMsg
);
228 CtrlMsg
->Msg
.mn_ReplyPort
= CtrlPort
;
229 if( SafePutToPort(CtrlMsg
, "ppp-control") ){
234 FreeMem(CtrlMsg
,sizeof(struct PPPcontrolMsg
));
236 DeletePort(CtrlPort
);
241 BOOL
SendRequest(void){
242 struct PPPcontrolMsg
*CtrlMsg
;
245 if( CtrlMsg
= AllocMem(sizeof(struct PPPcontrolMsg
),MEMF_PUBLIC
| MEMF_CLEAR
)){
246 bug("ModemManager:send info request\n");
247 CtrlMsg
->Command
= PPP_CTRL_INFO_REQUEST
;
248 CtrlMsg
->Arg
= (IPTR
)PortName
;
249 CtrlMsg
->Msg
.mn_Node
.ln_Type
= NT_MESSAGE
;
250 CtrlMsg
->Msg
.mn_Length
= sizeof(struct PPPcontrolMsg
);
251 CtrlMsg
->Msg
.mn_ReplyPort
= 0;
252 if( SafePutToPort(CtrlMsg
, "ppp-control") ) result
=TRUE
;
253 FreeMem(CtrlMsg
, sizeof(struct PPPcontrolMsg
));
259 void speedstr(BYTE
*buf
,BYTE
*label
,LONG s
){
260 float speed
= (float)s
;
262 if( speed
> 1000.0 ){
266 if( speed
> 1000.0 ){
270 snprintf( buf
, STRSIZE
, speed
== (ULONG
)speed
? "%s %.0f %c/s" :"%s %.2f %c/s" , label
, speed
, e
);
273 // draw triangular signal meter and show modem name etc..
274 void UpdateModemInfo(struct EasyBitmap
*ebm
,struct Conf
*c
)
280 get(application
, MUIA_Application_Iconified
, &iconified
);
282 if( !iconified
&& ebm
){
285 if( c
->signal
>= 0 && c
->signal
!= 99 ){
288 //sig = (ULONG)( log( (double)c->signal ) / log( 31.0 )*31.0 );
293 Move(ebm
->rp
, i
, 15 );
294 Draw(ebm
->rp
, i
, 15-i
/2 );
305 DoMethod( ebm
->MUIbitmap
, MUIM_Draw
);
308 <AcT> Network access type
315 6 UTRAN with HSDPA and HSUPA ???
318 set( AccessType
, MUIA_Text_Contents
,
319 c
->AccessType
== -1 ? "" :
320 c
->AccessType
== 0 ? "GSM" :
321 c
->AccessType
== 1 ? "GPRS" :
322 c
->AccessType
== 2 ? "3G" :
323 c
->AccessType
== 3 ? "EDGE" :
324 c
->AccessType
== 4 ? "3.5G" :
325 c
->AccessType
== 5 ? "3.75G" :
326 c
->AccessType
== 6 ? "3.8G" :
329 set( ModemName
, MUIA_Text_Contents
, c
->modemmodel
);
333 static void DisconnectFunc(struct Hook
*hook
, Object
*app
, APTR
*arg
)
336 struct Conf
*c
= *arg
;
337 SendCtrlMsg( PPP_CTRL_SETPHASE
, PPP_PHASE_TERMINATE
, c
);
341 void FindModemUnit(struct Conf
*c
){
342 struct EasySerial
*Ser
=0;
346 if( c
->SerUnitNum
>= 0 ){
350 for (i
= 0; i
< 100; i
++)
352 if( Ser
= OpenSerial( c
->DeviceName
,i
) ){
353 if( TestModem( Ser
, c
) ){
363 c
->SerUnitNum
= result
;
367 static void ConnectFunc(struct Hook
*hook
, Object
*app
, APTR
*arg
)
369 struct Conf
*c
= *arg
;
370 struct EasySerial
*Ser
=0;
372 if( c
->state
== STATE_PLUGGED
){
374 // is interfacename configured?
375 if( c
->InterfaceName
[0] == 0 ){
376 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"ppp Interface not configured!");
380 // check if arostcp is running
381 if( FindTask("bsdsocket.library") == NULL
){
382 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"AROSTCP is not running!");
384 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"Starting AROSTCP OK");
386 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"Starting AROSTCP FAIL!");
392 if( FindPort("ppp-control") ){
393 // send info request to ppp.device
396 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"Can't find ppp.device!");
397 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Not configured?");
401 if( c
->SerUnitNum
>=0 ){
402 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Open Serial Device...");
403 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
404 if( Ser
= OpenSerial( c
->DeviceName
,c
->SerUnitNum
) ){
405 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Modem Test...");
406 //set( OUT_Info , MUIA_Text_Contents, (IPTR)"");
407 if( TestModem( Ser
, c
) ){
408 UpdateModemInfo( SignalBM
, c
);
409 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"DialUp...");
410 //set( OUT_Info , MUIA_Text_Contents, (IPTR)"");
413 if( SendCtrlMsg( PPP_CTRL_OPEN_SERIAL
, 0 , c
)){
414 c
->state
= STATE_OPENDEV
;
415 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"OK,Starting PPP...");
420 }else c
->state
= STATE_UNPLUGGED
;
421 }else c
->state
= STATE_UNPLUGGED
;
423 if( c
->state
!= STATE_OPENDEV
){
424 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"ERROR");
430 #define FILEBUFFSIZE 4000
432 void ConfNetWork(struct PPPcontrolMsg
*msg
,struct Conf
*c
){
434 struct TagItem tags
[] =
436 { SYS_Input
, (IPTR
)NULL
},
437 { SYS_Output
, (IPTR
)NULL
},
438 { SYS_Error
, (IPTR
)NULL
},
439 { SYS_Asynch
, (IPTR
)FALSE
},
443 struct Library
*MiamiBase
;
444 TEXT arostcppath
[256];
448 GetVar( "SYS/Packages/AROSTCP" , arostcppath
, 256 , LV_VAR
);
450 bug("\n###########################################################\n");
451 bug("PPP is ONLINE !\n");
452 bug("Local IP address %d.%d.%d.%d\n",msg
->LocalIP
[0],msg
->LocalIP
[1],msg
->LocalIP
[2],msg
->LocalIP
[3]);
453 bug("Remote IP address %d.%d.%d.%d\n",msg
->RemoteIP
[0],msg
->RemoteIP
[1],msg
->RemoteIP
[2],msg
->RemoteIP
[3]);
455 if( buff
= AllocMem( FILEBUFFSIZE
, MEMF_CLEAR
|MEMF_PUBLIC
) ){
457 bug("Primary DNS address %d.%d.%d.%d\n", msg
->PrimaryDNS
[0],msg
->PrimaryDNS
[1],
458 msg
->PrimaryDNS
[2],msg
->PrimaryDNS
[3] );
459 bug("Secondary DNS address %d.%d.%d.%d\n", msg
->SecondaryDNS
[0],msg
->SecondaryDNS
[1],
460 msg
->SecondaryDNS
[2],msg
->SecondaryDNS
[3] );
462 // Register nameservers with TCP/IP stack
463 if( FindTask("bsdsocket.library") != NULL
) {
464 MiamiBase
= OpenLibrary("miami.library", 0);
465 if(MiamiBase
!= NULL
) {
467 struct sockaddr_in ns_addr
;
469 ns_addr
.sin_len
= sizeof(ns_addr
);
470 ns_addr
.sin_family
= AF_INET
;
472 memcpy(&ns_addr
.sin_addr
.s_addr
, msg
->PrimaryDNS
, 4);
473 AddDynNameServ((struct sockaddr
*)&ns_addr
);
475 memcpy(&ns_addr
.sin_addr
.s_addr
, msg
->SecondaryDNS
, 4);
476 AddDynNameServ((struct sockaddr
*)&ns_addr
);
479 CloseLibrary(MiamiBase
);
483 sprintf(buff
,"%s/c/ifconfig %s %d.%d.%d.%d %d.%d.%d.%d",
486 msg
->LocalIP
[0],msg
->LocalIP
[1],
487 msg
->LocalIP
[2],msg
->LocalIP
[3],
488 msg
->RemoteIP
[0],msg
->RemoteIP
[1],
489 msg
->RemoteIP
[2],msg
->RemoteIP
[3] );
491 bug("Executing command:\"%s\"\n",buff
);
492 if( SystemTagList( buff
, tags
) != 0 )
493 bug("command FAIL !!!!\n");
495 sprintf(buff
,"%s/c/route add default %d.%d.%d.%d",
497 msg
->RemoteIP
[0],msg
->RemoteIP
[1],
498 msg
->RemoteIP
[2],msg
->RemoteIP
[3] );
500 bug("Executing command:\"%s\"\n",buff
);
501 if(SystemTagList( buff
, tags
) != 0 )
502 bug("command FAIL !!!!\n");
504 bug("\n############################################################*\n");
506 FreeMem( buff
, FILEBUFFSIZE
);
510 void HandleMessage(struct PPPcontrolMsg
*InfoMsg
,struct Conf
*c
){
511 if( InfoMsg
->Msg
.mn_Length
== sizeof(struct PPPcontrolMsg
)
512 && InfoMsg
->Command
== PPP_CTRL_INFO
514 if( exPhase
!= InfoMsg
->Phase
|| exSer
!= InfoMsg
->Ser
|| exstate
!= c
->state
){
515 exPhase
= InfoMsg
->Phase
; exSer
= InfoMsg
->Ser
; exstate
= c
->state
;
516 bug("ModemManager:handlemsg phase=%d,ser=%d,state=%d\n",exPhase
,exSer
,exstate
);
518 // TERMINATE phase in progress ,dont do nothing
519 if( InfoMsg
->Phase
== PPP_PHASE_TERMINATE
){
523 // PPP initializing is ready
524 if( c
->state
== STATE_OPENDEV
&& InfoMsg
->Phase
== PPP_PHASE_NETWORK
){
525 ConfNetWork( InfoMsg
,c
);
526 c
->state
= STATE_NETWORK
;
529 // serial connection is lost (device unplugged)
530 if( c
->state
!= STATE_UNPLUGGED
&& (! InfoMsg
->Ser
) ){
531 c
->state
= STATE_PLUGGED
;
535 if( InfoMsg
->Phase
== PPP_PHASE_NETWORK
&& InfoMsg
->Ser
){
536 c
->state
= STATE_NETWORK
;
539 // net connection is lost
540 if( c
->state
== STATE_NETWORK
&& InfoMsg
->Phase
!= PPP_PHASE_NETWORK
){
541 // SendCtrlMsg( PPP_CTRL_CLOSE_SERIAL , 0 , c );
542 c
->state
= STATE_PLUGGED
;
550 struct Hook DisconnectHook
,ConnectHook
;
551 struct EasyTimer
*timer
=0;
555 struct PPPcontrolMsg
*CtrlMsg
=0;
556 struct PPPcontrolMsg
*InfoMsg
=0;
557 struct MsgPort
*CtrlPort
=0;
558 struct EasySerial
*Ser
=0;
561 struct EasyGraph
*INegr
=0;
562 struct EasyGraph
*OUTegr
=0;
564 Object
*INGraphMUIbm
,*OUTGraphMUIbm
,*MUISignalBM
;
566 ULONG SpeedIn
=0,SpeedOUT
=0;
568 if( ! FindPort(PortName
)){
569 if( timer
=OpenTimer() ){
570 if( CtrlPort
= CreatePort(PortName
,0) ){
571 if( CtrlMsg
= AllocMem(sizeof(struct PPPcontrolMsg
),MEMF_PUBLIC
| MEMF_CLEAR
)){
572 if( c
= AllocMem(sizeof(struct Conf
),MEMF_PUBLIC
| MEMF_CLEAR
)){
581 c
->state
= STATE_UNPLUGGED
;
587 SetTimer( timer
, 0 );
590 // send info request to ppp.device and wait response
592 bug("ModemManager:wait response\n");
593 sigs
= Wait( SIGBREAKF_CTRL_C
|
594 (1L<< CtrlPort
->mp_SigBit
)
597 while( InfoMsg
= (struct PPPcontrolMsg
*)GetMsg(CtrlPort
) ){
598 HandleMessage(InfoMsg
,c
);
599 ReplyMsg((struct Message
*)InfoMsg
);
602 if (sigs
& SIGBREAKF_CTRL_C
) goto shutdown
;
605 SetTimer( timer
, 1 );
606 bug("ModemManager:wait until %s unit %d open.\n",c
->DeviceName
,c
->SerUnitNum
);
607 while(c
->state
== STATE_UNPLUGGED
)
609 sigs
= Wait( SIGBREAKF_CTRL_C
|
610 (1L<< CtrlPort
->mp_SigBit
) |
611 (1L<< timer
->TimeMsg
->mp_SigBit
)
614 // handle incoming messages
615 while( InfoMsg
= (struct PPPcontrolMsg
*)GetMsg(CtrlPort
) )
616 ReplyMsg((struct Message
*)InfoMsg
);
618 // Check if modem is plugged in.
619 if(GetMsg(timer
->TimeMsg
)){
621 if( c
->SerUnitNum
>= 0 ){
622 if( Ser
= OpenSerial( c
->DeviceName
,c
->SerUnitNum
) ){
623 if( TestModem( Ser
, c
) ){
624 c
->state
= STATE_PLUGGED
;
629 SetTimer( timer
, 5 );
632 if (sigs
& SIGBREAKF_CTRL_C
) goto shutdown
;
635 bug("ModemManager:Open GUI window\n");
637 DisconnectHook
.h_Entry
= HookEntry
;
638 DisconnectHook
.h_SubEntry
= (HOOKFUNC
) DisconnectFunc
;
639 ConnectHook
.h_Entry
= HookEntry
;
640 ConnectHook
.h_SubEntry
= (HOOKFUNC
) ConnectFunc
;
642 application
= ApplicationObject
,
643 MUIA_Application_Title
, (IPTR
) "ModemManager",
644 SubWindow
, window
= WindowObject
,
645 MUIA_Window_Title
, (IPTR
) "ModemManager",
646 MUIA_Window_Activate
,TRUE
,
647 WindowContents
, (IPTR
) VGroup
,
649 Child
, (IPTR
) VGroup
,
651 Child
, (IPTR
) HGroup
,
652 Child
, ModemName
= SimpleText("1234567890123"),
653 Child
, MUISignalBM
= BitmapObject
,
657 Child
, AccessType
= SimpleText("12345"),
659 Child
, (IPTR
) HGroup
,
660 Child
, IN_Info
= SimpleText("12345678901"),
661 Child
, INGraphMUIbm
= BitmapObject
,
666 Child
, (IPTR
) HGroup
,
667 Child
, OUT_Info
= SimpleText("12345678901"),
668 Child
, OUTGraphMUIbm
= BitmapObject
,
675 Child
, (IPTR
) HGroup
,
676 Child
, (IPTR
) ( ConBut
= SimpleButton(" Connect ")),
677 Child
, (IPTR
) (DisConBut
= SimpleButton(" Disconnect ")),
688 window
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
689 (IPTR
) application
, 2, MUIM_Application_ReturnID
,
690 MUIV_Application_ReturnID_Quit
694 ConBut
,MUIM_Notify
,MUIA_Pressed
,FALSE
,
695 application
, (IPTR
) 3,
696 MUIM_CallHook
, &ConnectHook
,c
700 DisConBut
,MUIM_Notify
,MUIA_Pressed
,FALSE
,
701 application
, (IPTR
) 3,
702 MUIM_CallHook
, &DisconnectHook
,c
706 set(window
,MUIA_Window_Open
,TRUE
);
707 set(DisConBut
,MUIA_Disabled
,TRUE
);
708 set( ConBut
,MUIA_Disabled
,TRUE
);
710 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"");
711 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
713 SignalBM
= MakeBitmap(32,16,window
,MUISignalBM
);
714 INegr
= MakeGraph(80,16,window
,INGraphMUIbm
);
715 OUTegr
= MakeGraph(80,16,window
,OUTGraphMUIbm
);
716 set( INGraphMUIbm
, MUIA_ShowMe
, FALSE
);
717 set( OUTGraphMUIbm
, MUIA_ShowMe
, FALSE
);
719 SetTimer( timer
, 1 );
722 UpdateModemInfo( SignalBM
, c
);
726 application
, MUIM_Application_NewInput
, (IPTR
) &sigs
727 ) != MUIV_Application_ReturnID_Quit
733 (1L<< CtrlPort
->mp_SigBit
) |
734 (1L<< timer
->TimeMsg
->mp_SigBit
)
737 while( InfoMsg
= (struct PPPcontrolMsg
*)GetMsg(CtrlPort
) ){
738 //bug("ModemManager: received info message num %d\n",InfoMsg->num);
740 HandleMessage(InfoMsg
,c
);
742 if( c
->state
== STATE_UNPLUGGED
){
743 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Unplugged");
744 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
745 set(DisConBut
, MUIA_Disabled
, TRUE
);
746 set( ConBut
, MUIA_Disabled
, TRUE
);
748 else if( c
->state
== STATE_PLUGGED
){
749 set( INGraphMUIbm
, MUIA_ShowMe
, FALSE
);
750 set( OUTGraphMUIbm
, MUIA_ShowMe
, FALSE
);
751 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"");
752 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
753 set(DisConBut
, MUIA_Disabled
, TRUE
);
754 set( ConBut
, MUIA_Disabled
, FALSE
);
756 else if( c
->state
== STATE_OPENDEV
&& ! InfoMsg
->Ser
){
757 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"OpenDevice:");
758 snprintf( buf
, STRSIZE
, "%s unit %d",c
->DeviceName
,c
->SerUnitNum
);
759 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)buf
);
760 set(DisConBut
, MUIA_Disabled
, FALSE
);
761 set( ConBut
, MUIA_Disabled
, TRUE
);
764 else if( c
->state
== STATE_OPENDEV
){
765 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Connection in progress:");
766 UBYTE phase
= InfoMsg
->Phase
;
768 set( OUT_Info
, MUIA_Text_Contents
,
769 (IPTR
)( phase
== PPP_PHASE_CONFIGURATION
? "LCP configuration" :
770 phase
== PPP_PHASE_AUTHENTICATION
? "Authentication" :
771 phase
== PPP_PHASE_PROTOCOL_CONF
? "Protocol configuration" :
775 set(DisConBut
, MUIA_Disabled
, FALSE
);
776 set( ConBut
, MUIA_Disabled
, TRUE
);
777 //set(window,MUIA_Window_Title,(IPTR)c->modemmodel);
779 else if( c
->state
== STATE_NETWORK
){
780 if( InfoMsg
->Phase
== PPP_PHASE_TERMINATE
){
781 set(DisConBut
, MUIA_Disabled
, TRUE
);
782 set( ConBut
, MUIA_Disabled
, TRUE
);
783 set( INGraphMUIbm
, MUIA_ShowMe
, FALSE
);
784 set( OUTGraphMUIbm
, MUIA_ShowMe
, FALSE
);
785 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"Terminate...");
786 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
788 SpeedIn
= InfoMsg
->SpeedIn
;
789 SpeedOUT
= InfoMsg
->SpeedOut
;
791 speedstr(buf
," In",SpeedIn
);
792 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)buf
);
793 speedstr(buf
,"Out",SpeedOUT
);
794 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)buf
);
796 set(DisConBut
, MUIA_Disabled
, FALSE
);
797 set( ConBut
, MUIA_Disabled
, TRUE
);
799 set( INGraphMUIbm
, MUIA_ShowMe
, TRUE
);
800 set( OUTGraphMUIbm
, MUIA_ShowMe
, TRUE
);
804 ReplyMsg((struct Message
*)InfoMsg
);
805 //bug("ModemManager: ReplyMsg OK\n");
809 if(GetMsg(timer
->TimeMsg
)){
811 if( c
->state
== STATE_NETWORK
){
812 speedstr(buf
," In",SpeedIn
);
813 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)buf
);
814 speedstr(buf
,"Out",SpeedOUT
);
815 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)buf
);
816 UpdateGraph(INegr
,(FLOAT
)SpeedIn
);
817 UpdateGraph(OUTegr
,(FLOAT
)SpeedOUT
);
820 // test if modem is unplugged
821 if( c
->state
== STATE_PLUGGED
){
822 if( Ser
= OpenSerial( c
->DeviceName
,c
->SerUnitNum
) ){
824 //UpdateModemInfo( SignalBM , c );
826 c
->state
= STATE_UNPLUGGED
;
829 if( c
->state
== STATE_PLUGGED
){
830 set( OUT_Info
, MUIA_Text_Contents
, (IPTR
)"");
831 set( IN_Info
, MUIA_Text_Contents
, (IPTR
)"");
832 set(DisConBut
, MUIA_Disabled
, TRUE
);
833 set( ConBut
, MUIA_Disabled
, FALSE
);
836 SetTimer( timer
, TIMERVALUE
);
839 if (sigs
& SIGBREAKF_CTRL_C
) goto shutdown
;
842 if( c
->state
== STATE_UNPLUGGED
) break;
845 // MUIV_Application_ReturnID_Quit ?
846 if( c
->state
!= STATE_UNPLUGGED
) break;
848 bug("ModemManager:Device Unplugged -> Close GUI window\n");
849 SetTimer( timer
, 0 );
850 MUI_DisposeObject(application
);
852 CloseBitmap(SignalBM
);
861 bug("ModemManager:ShutDown\n");
862 if(application
) MUI_DisposeObject(application
);
863 CloseBitmap(SignalBM
);
868 struct at_command
*atc
;
869 while( atc
= (struct at_command
*)RemHead( &c
->atcl
) ){
870 FreeMem( atc
, sizeof(struct at_command
) );
875 while( GetMsg(CtrlPort
) ) ReplyMsg((struct Message
*)CtrlMsg
);
876 DeletePort(CtrlPort
);
880 if( c
) FreeMem( c
, sizeof(struct Conf
));
881 if( CtrlMsg
) FreeMem(CtrlMsg
, sizeof(struct PPPcontrolMsg
));