Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / networks / ppp / ModemManager / ModemManager.c
blob3ce71cc76330f9bde9225face87c641521182ecd
1 /*
2 * $Id$
3 */
5 #define DEBUG 1
6 #include <exec/types.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <math.h>
11 #include <dos/dos.h>
12 #ifdef __MORPHOS__
13 #include <dos/dostags.h>
14 #define SYS_Error SYS_Output
15 #endif
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>
25 #ifdef __MORPHOS__
26 #define ClearDynNameServ()
27 #define AddDynNameServ(a)
28 #define EndDynNameServ()
29 LONG XGET(Object * obj, ULONG attribute)
31 LONG x = 0;
33 get(obj, attribute, &x);
34 return x;
36 #else
37 #include <proto/miami.h>
38 #endif
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>
45 #include "ppp.h"
46 #include "misc.h"
48 #define SimpleText(text) TextObject, MUIA_Text_Contents, (IPTR) text, End
50 #define TIMERVALUE 5
51 #define STRSIZE 100
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;
69 BOOL exSer;
71 struct EasyBitmap{
72 struct BitMap *bm;
73 struct RastPort *rp;
74 Object *MUIbitmap;
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),
88 BMF_CLEAR,
89 tw->RPort->BitMap);
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);
102 return ebm;
105 void _CloseBitmap(struct EasyBitmap *ebm){
106 if(ebm){
107 FreeRastPort(ebm->rp);
108 FreeBitMap(ebm->bm);
109 FreeMem(ebm,sizeof(struct EasyBitmap));
112 #define CloseBitmap( ebm ) do{_CloseBitmap(ebm);ebm=NULL;}while(0)
115 struct EasyGraph{
116 struct EasyBitmap *ebm;
117 ULONG Xsize,Ysize;
118 FLOAT Max;
119 FLOAT *value;
122 void _CloseGraph(struct EasyGraph *egr){
123 if(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)){
135 egr->Xsize = x;
136 egr->Ysize = y;
137 egr->Max = 0.0;
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);
146 return egr;
149 void UpdateGraph(struct EasyGraph *egr,FLOAT value){
150 LONG i;
151 LONG h;
152 ULONG iconified=0;
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;
165 if( egr->ebm ){
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 );
179 }else{
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;
194 Forbid();
195 port = FindPort(portname);
196 if (port){
197 struct Message *M;
198 ForeachNode(&port->mp_MsgList,M){
199 if( (APTR)message == (APTR)M ){
200 // bug("SafePutToPort: message is already here !\n");
201 Permit();
202 return FALSE;
205 PutMsg(port,(struct Message *)message);
207 Permit();
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;
214 BOOL succes=FALSE;
215 if( CtrlPort = CreatePort(0,0) ){
216 if( CtrlMsg = AllocMem(sizeof(struct PPPcontrolMsg),MEMF_PUBLIC | MEMF_CLEAR)){
218 CtrlMsg->Command = command;
219 CtrlMsg->Arg = Arg;
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") ){
230 WaitPort(CtrlPort);
231 GetMsg(CtrlPort);
232 succes=TRUE;
234 FreeMem(CtrlMsg,sizeof(struct PPPcontrolMsg));
236 DeletePort(CtrlPort);
238 return succes;
241 BOOL SendRequest(void){
242 struct PPPcontrolMsg *CtrlMsg;
243 BOOL result=FALSE;
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));
255 return result;
259 void speedstr(BYTE *buf,BYTE *label,LONG s){
260 float speed= (float)s;
261 BYTE e = 'b';
262 if( speed > 1000.0 ){
263 e = 'k';
264 speed /= 1000.0;
266 if( speed > 1000.0 ){
267 e = 'M';
268 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)
276 ULONG i;
277 ULONG sig;
278 ULONG iconified=0;
280 get(application, MUIA_Application_Iconified, &iconified);
282 if( !iconified && ebm ){
284 SetRast(ebm->rp,0);
285 if( c->signal >= 0 && c->signal != 99 ){
287 sig = c->signal;
288 //sig = (ULONG)( log( (double)c->signal ) / log( 31.0 )*31.0 );
290 SetAPen(ebm->rp,2);
291 for(i=0;i<32;i++){
292 if( sig >= i){
293 Move(ebm->rp, i , 15 );
294 Draw(ebm->rp, i , 15-i/2 );
297 SetAPen(ebm->rp,1);
298 Move(ebm->rp,0,15);
299 Draw(ebm->rp,0,14);
300 Draw(ebm->rp,29,0);
301 Draw(ebm->rp,31,0);
302 Draw(ebm->rp,31,15);
303 Draw(ebm->rp,0,15);
305 DoMethod( ebm->MUIbitmap , MUIM_Draw );
308 <AcT> Network access type
309 0 GSM
310 1 Compact GSM
311 2 UTRAN
312 3 GSM with EGPRS
313 4 UTRAN with HSDPA
314 5 UTRAN with HSUPA
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" :
327 "?G"
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;
343 int result = -1;
344 int i;
346 if( c->SerUnitNum >= 0 ){
347 return;
350 for (i = 0; i < 100; i++)
352 if( Ser = OpenSerial( c->DeviceName ,i ) ){
353 if( TestModem( Ser , c ) ){
354 result = i;
355 DrainSerial( Ser );
356 CloseSerial( Ser );
357 break;
359 DrainSerial( Ser );
360 CloseSerial( Ser );
361 } else break;
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!");
377 return;
380 // check if arostcp is running
381 if( FindTask("bsdsocket.library") == NULL ){
382 set( IN_Info , MUIA_Text_Contents, (IPTR)"AROSTCP is not running!");
383 if( StartStack() ){
384 set( OUT_Info , MUIA_Text_Contents, (IPTR)"Starting AROSTCP OK");
385 }else{
386 set( OUT_Info , MUIA_Text_Contents, (IPTR)"Starting AROSTCP FAIL!");
387 return;
391 // check ppp.device
392 if( FindPort("ppp-control") ){
393 // send info request to ppp.device
394 SendRequest();
395 }else{
396 set( OUT_Info, MUIA_Text_Contents, (IPTR)"Can't find ppp.device!");
397 set( IN_Info , MUIA_Text_Contents, (IPTR)"Not configured?");
398 return;
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)"");
411 if( DialUp(Ser,c) ){
412 CloseSerial(Ser);
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...");
419 CloseSerial(Ser);
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 },
440 { TAG_DONE, 0 }
443 struct Library *MiamiBase;
444 TEXT arostcppath[256];
445 UBYTE *buff;
447 arostcppath[0]=0;
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) {
466 ClearDynNameServ();
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);
478 EndDynNameServ();
479 CloseLibrary(MiamiBase);
483 sprintf(buff,"%s/c/ifconfig %s %d.%d.%d.%d %d.%d.%d.%d",
484 arostcppath,
485 c->InterfaceName,
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",
496 arostcppath,
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 ){
520 return;
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;
534 // Connection is ok
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;
548 int main(void)
550 struct Hook DisconnectHook,ConnectHook;
551 struct EasyTimer *timer=0;
552 BYTE buf[STRSIZE];
553 buf[0]=0;
554 ULONG sigs;
555 struct PPPcontrolMsg *CtrlMsg=0;
556 struct PPPcontrolMsg *InfoMsg=0;
557 struct MsgPort *CtrlPort=0;
558 struct EasySerial *Ser=0;
559 struct Conf *c=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)){
574 NEWLIST(&c->atcl);
576 for(;;)
579 ReadConfig(c);
581 c->state = STATE_UNPLUGGED;
582 c->signal = -1;
583 c->AccessType = -1;
584 SpeedIn =0;
585 SpeedOUT = 0;
587 SetTimer( timer , 0 );
588 application = NULL;
590 // send info request to ppp.device and wait response
591 if( SendRequest() ){
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)){
620 FindModemUnit(c);
621 if( c->SerUnitNum >= 0 ){
622 if( Ser = OpenSerial( c->DeviceName ,c->SerUnitNum ) ){
623 if( TestModem( Ser , c ) ){
624 c->state = STATE_PLUGGED;
626 CloseSerial(Ser);
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,
650 GroupFrame,
651 Child, (IPTR) HGroup,
652 Child, ModemName = SimpleText("1234567890123"),
653 Child, MUISignalBM = BitmapObject,
654 MUIA_FixWidth, 32,
655 MUIA_FixHeight, 16,
656 End,
657 Child, AccessType = SimpleText("12345"),
658 End,
659 Child, (IPTR) HGroup,
660 Child, IN_Info = SimpleText("12345678901"),
661 Child, INGraphMUIbm = BitmapObject,
662 MUIA_FixWidth, 80,
663 MUIA_FixHeight, 16,
664 End,
665 End,
666 Child, (IPTR) HGroup,
667 Child, OUT_Info = SimpleText("12345678901"),
668 Child, OUTGraphMUIbm = BitmapObject,
669 MUIA_FixWidth, 80,
670 MUIA_FixHeight, 16,
671 End,
672 End,
674 End,
675 Child, (IPTR) HGroup,
676 Child, (IPTR) ( ConBut = SimpleButton(" Connect ")),
677 Child, (IPTR) (DisConBut = SimpleButton(" Disconnect ")),
678 End,
679 End,
680 End,
681 End;
683 if (application)
685 sigs = 0;
687 DoMethod(
688 window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
689 (IPTR) application, 2, MUIM_Application_ReturnID,
690 MUIV_Application_ReturnID_Quit
693 DoMethod(
694 ConBut,MUIM_Notify,MUIA_Pressed,FALSE,
695 application, (IPTR) 3,
696 MUIM_CallHook, &ConnectHook,c
699 DoMethod(
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 );
720 SendRequest();
722 UpdateModemInfo( SignalBM , c );
724 while(
725 DoMethod(
726 application, MUIM_Application_NewInput, (IPTR) &sigs
727 ) != MUIV_Application_ReturnID_Quit
730 if (sigs){
731 sigs = Wait( sigs |
732 SIGBREAKF_CTRL_C |
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" :
772 "Unknow"
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)"");
787 } else{
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 ) ){
823 CloseSerial(Ser);
824 //UpdateModemInfo( SignalBM , c );
825 } else
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;
843 } //GUI loop
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);
851 application=NULL;
852 CloseBitmap(SignalBM);
853 CloseGraph(INegr);
854 CloseGraph(OUTegr);
855 } // main loop
857 }}}}}
859 // close all
860 shutdown:
861 bug("ModemManager:ShutDown\n");
862 if(application) MUI_DisposeObject(application);
863 CloseBitmap(SignalBM);
864 CloseGraph(INegr);
865 CloseGraph(OUTegr);
866 CloseTimer(timer);
868 struct at_command *atc;
869 while( atc = (struct at_command *)RemHead( &c->atcl ) ){
870 FreeMem( atc , sizeof(struct at_command) );
873 if(CtrlPort){
874 Forbid();
875 while( GetMsg(CtrlPort) ) ReplyMsg((struct Message *)CtrlMsg);
876 DeletePort(CtrlPort);
877 Permit();
880 if( c ) FreeMem( c , sizeof(struct Conf));
881 if( CtrlMsg ) FreeMem(CtrlMsg , sizeof(struct PPPcontrolMsg));
883 return 0;