Lines Matching refs:dl

88   struct datalink *dl = (struct datalink *)v;  in datalink_OpenTimeout()  local
90 timer_Stop(&dl->dial.timer); in datalink_OpenTimeout()
91 if (dl->state == DATALINK_OPENING) in datalink_OpenTimeout()
92 log_Printf(LogCHAT, "%s: Redial timer expired.\n", dl->name); in datalink_OpenTimeout()
96 datalink_StartDialTimer(struct datalink *dl, int Timeout) in datalink_StartDialTimer() argument
100 timer_Stop(&dl->dial.timer); in datalink_StartDialTimer()
103 dl->dial.timer.load = result ? result * SECTICKS : 1; in datalink_StartDialTimer()
104 dl->dial.timer.func = datalink_OpenTimeout; in datalink_StartDialTimer()
105 dl->dial.timer.name = "dial"; in datalink_StartDialTimer()
106 dl->dial.timer.arg = dl; in datalink_StartDialTimer()
107 timer_Start(&dl->dial.timer); in datalink_StartDialTimer()
108 if (dl->state == DATALINK_OPENING) in datalink_StartDialTimer()
110 dl->name, result); in datalink_StartDialTimer()
115 datalink_HangupDone(struct datalink *dl) in datalink_HangupDone() argument
117 if (dl->physical->type == PHYS_DEDICATED && !dl->bundle->CleaningUp && in datalink_HangupDone()
118 dl->physical->fd != -1) { in datalink_HangupDone()
120 datalink_LoginDone(dl); in datalink_HangupDone()
124 chat_Finish(&dl->chat); in datalink_HangupDone()
125 physical_Close(dl->physical); in datalink_HangupDone()
126 dl->phone.chosen = "N/A"; in datalink_HangupDone()
128 if (dl->cbcp.required) { in datalink_HangupDone()
129 log_Printf(LogPHASE, "Call peer back on %s\n", dl->cbcp.fsm.phone); in datalink_HangupDone()
130 dl->cfg.callback.opmask = 0; in datalink_HangupDone()
131 strncpy(dl->cfg.phone.list, dl->cbcp.fsm.phone, in datalink_HangupDone()
132 sizeof dl->cfg.phone.list - 1); in datalink_HangupDone()
133 dl->cfg.phone.list[sizeof dl->cfg.phone.list - 1] = '\0'; in datalink_HangupDone()
134 dl->phone.alt = dl->phone.next = NULL; in datalink_HangupDone()
135 dl->reconnect_tries = dl->cfg.reconnect.max; in datalink_HangupDone()
136 dl->dial.tries = dl->cfg.dial.max; in datalink_HangupDone()
137 dl->dial.incs = 0; in datalink_HangupDone()
138 dl->script.run = 1; in datalink_HangupDone()
139 dl->script.packetmode = 1; in datalink_HangupDone()
140 if (!physical_SetMode(dl->physical, PHYS_BACKGROUND)) in datalink_HangupDone()
142 bundle_LinksRemoved(dl->bundle); in datalink_HangupDone()
144 if (dl->cbcp.fsm.delay < dl->cfg.dial.timeout) in datalink_HangupDone()
145 dl->cbcp.fsm.delay = dl->cfg.dial.timeout; in datalink_HangupDone()
146 datalink_StartDialTimer(dl, dl->cbcp.fsm.delay); in datalink_HangupDone()
147 cbcp_Down(&dl->cbcp); in datalink_HangupDone()
148 datalink_NewState(dl, DATALINK_OPENING); in datalink_HangupDone()
149 if (bundle_Phase(dl->bundle) == PHASE_DEAD || in datalink_HangupDone()
150 bundle_Phase(dl->bundle) == PHASE_TERMINATE) in datalink_HangupDone()
151 bundle_NewPhase(dl->bundle, PHASE_ESTABLISH); in datalink_HangupDone()
152 } else if (dl->bundle->CleaningUp || in datalink_HangupDone()
153 (dl->physical->type == PHYS_DIRECT) || in datalink_HangupDone()
154 ((!dl->dial.tries || (dl->dial.tries < 0 && !dl->reconnect_tries)) && in datalink_HangupDone()
155 !(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)))) { in datalink_HangupDone()
156 datalink_NewState(dl, DATALINK_CLOSED); in datalink_HangupDone()
157 dl->dial.tries = -1; in datalink_HangupDone()
158 dl->dial.incs = 0; in datalink_HangupDone()
159 dl->reconnect_tries = 0; in datalink_HangupDone()
160 bundle_LinkClosed(dl->bundle, dl); in datalink_HangupDone()
161 if (!dl->bundle->CleaningUp && in datalink_HangupDone()
162 !(dl->physical->type & (PHYS_DIRECT|PHYS_BACKGROUND|PHYS_FOREGROUND))) in datalink_HangupDone()
163 datalink_StartDialTimer(dl, datalink_GetDialTimeout(dl)); in datalink_HangupDone()
165 datalink_NewState(dl, DATALINK_OPENING); in datalink_HangupDone()
166 if (bundle_Phase(dl->bundle) == PHASE_DEAD || in datalink_HangupDone()
167 bundle_Phase(dl->bundle) == PHASE_TERMINATE) in datalink_HangupDone()
168 bundle_NewPhase(dl->bundle, PHASE_ESTABLISH); in datalink_HangupDone()
169 if (dl->dial.tries < 0) { in datalink_HangupDone()
170 datalink_StartDialTimer(dl, dl->cfg.reconnect.timeout); in datalink_HangupDone()
171 dl->dial.tries = dl->cfg.dial.max; in datalink_HangupDone()
172 dl->dial.incs = 0; in datalink_HangupDone()
173 dl->reconnect_tries--; in datalink_HangupDone()
175 dl->name, dl->cfg.reconnect.max - dl->reconnect_tries, in datalink_HangupDone()
176 dl->cfg.reconnect.max); in datalink_HangupDone()
177 bundle_Notify(dl->bundle, EX_RECONNECT); in datalink_HangupDone()
179 if (dl->phone.next == NULL) in datalink_HangupDone()
180 datalink_StartDialTimer(dl, datalink_GetDialTimeout(dl)); in datalink_HangupDone()
182 datalink_StartDialTimer(dl, dl->cfg.dial.next_timeout); in datalink_HangupDone()
183 bundle_Notify(dl->bundle, EX_REDIAL); in datalink_HangupDone()
189 datalink_ChoosePhoneNumber(struct datalink *dl) in datalink_ChoosePhoneNumber() argument
193 if (dl->phone.alt == NULL) { in datalink_ChoosePhoneNumber()
194 if (dl->phone.next == NULL) { in datalink_ChoosePhoneNumber()
195 strncpy(dl->phone.list, dl->cfg.phone.list, sizeof dl->phone.list - 1); in datalink_ChoosePhoneNumber()
196 dl->phone.list[sizeof dl->phone.list - 1] = '\0'; in datalink_ChoosePhoneNumber()
197 if (*dl->phone.list == '\0') in datalink_ChoosePhoneNumber()
199 dl->phone.next = dl->phone.list; in datalink_ChoosePhoneNumber()
201 dl->phone.alt = strsep(&dl->phone.next, ":"); in datalink_ChoosePhoneNumber()
203 phone = strsep(&dl->phone.alt, "|"); in datalink_ChoosePhoneNumber()
204 dl->phone.chosen = *phone ? phone : "[NONE]"; in datalink_ChoosePhoneNumber()
211 datalink_LoginDone(struct datalink *dl) in datalink_LoginDone() argument
213 chat_Finish(&dl->chat); in datalink_LoginDone()
215 if (!dl->script.packetmode) { in datalink_LoginDone()
216 dl->dial.tries = -1; in datalink_LoginDone()
217 dl->dial.incs = 0; in datalink_LoginDone()
218 datalink_NewState(dl, DATALINK_READY); in datalink_LoginDone()
219 } else if (!physical_Raw(dl->physical)) { in datalink_LoginDone()
220 dl->dial.tries = 0; in datalink_LoginDone()
222 if (dl->script.run) { in datalink_LoginDone()
223 datalink_NewState(dl, DATALINK_LOGOUT); in datalink_LoginDone()
224 if (!chat_Setup(&dl->chat, dl->cfg.script.logout, NULL)) in datalink_LoginDone()
227 physical_StopDeviceTimer(dl->physical); in datalink_LoginDone()
228 if (dl->physical->type == PHYS_DEDICATED) in datalink_LoginDone()
230 physical_Close(dl->physical); in datalink_LoginDone()
231 datalink_HangupDone(dl); in datalink_LoginDone()
234 dl->dial.tries = -1; in datalink_LoginDone()
235 dl->dial.incs = 0; in datalink_LoginDone()
237 hdlc_Init(&dl->physical->hdlc, &dl->physical->link.lcp); in datalink_LoginDone()
238 async_Setup(&dl->physical->async); in datalink_LoginDone()
240 lcp_Setup(&dl->physical->link.lcp, dl->state == DATALINK_READY ? in datalink_LoginDone()
241 0 : dl->physical->link.lcp.cfg.openmode); in datalink_LoginDone()
242 ccp_Setup(&dl->physical->link.ccp); in datalink_LoginDone()
244 datalink_NewState(dl, DATALINK_LCP); in datalink_LoginDone()
245 fsm_Up(&dl->physical->link.lcp.fsm); in datalink_LoginDone()
246 fsm_Open(&dl->physical->link.lcp.fsm); in datalink_LoginDone()
254 struct datalink *dl = descriptor2datalink(d); in datalink_UpdateSet() local
258 switch (dl->state) { in datalink_UpdateSet()
260 if ((dl->physical->type & (PHYS_DIRECT|PHYS_DEDICATED|PHYS_BACKGROUND| in datalink_UpdateSet()
262 !dl->bundle->CleaningUp) in datalink_UpdateSet()
269 datalink_Up(dl, 1, 1); in datalink_UpdateSet()
275 if (dl->dial.timer.state != TIMER_RUNNING) { in datalink_UpdateSet()
276 if (--dl->dial.tries < 0) in datalink_UpdateSet()
277 dl->dial.tries = 0; in datalink_UpdateSet()
278 if (physical_Open(dl->physical) >= 0) { in datalink_UpdateSet()
279 log_WritePrompts(dl, "%s: Entering terminal mode on %s\r\n" in datalink_UpdateSet()
280 "Type `~?' for help\r\n", dl->name, in datalink_UpdateSet()
281 dl->physical->name.full); in datalink_UpdateSet()
282 if (dl->script.run) { in datalink_UpdateSet()
283 datalink_NewState(dl, DATALINK_DIAL); in datalink_UpdateSet()
284 if (!chat_Setup(&dl->chat, dl->cfg.script.dial, in datalink_UpdateSet()
285 *dl->cfg.script.dial ? in datalink_UpdateSet()
286 datalink_ChoosePhoneNumber(dl) : "")) in datalink_UpdateSet()
288 if (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) && in datalink_UpdateSet()
289 dl->cfg.dial.max) in datalink_UpdateSet()
291 dl->name, dl->cfg.dial.max - dl->dial.tries, in datalink_UpdateSet()
292 dl->cfg.dial.max); in datalink_UpdateSet()
294 datalink_NewState(dl, DATALINK_CARRIER); in datalink_UpdateSet()
297 if (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) && in datalink_UpdateSet()
298 dl->cfg.dial.max) in datalink_UpdateSet()
300 dl->cfg.dial.max - dl->dial.tries, dl->cfg.dial.max); in datalink_UpdateSet()
304 if (dl->bundle->CleaningUp || in datalink_UpdateSet()
305 (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) && in datalink_UpdateSet()
306 dl->cfg.dial.max && dl->dial.tries == 0)) { in datalink_UpdateSet()
307 datalink_NewState(dl, DATALINK_CLOSED); in datalink_UpdateSet()
308 dl->reconnect_tries = 0; in datalink_UpdateSet()
309 dl->dial.tries = -1; in datalink_UpdateSet()
310 log_WritePrompts(dl, "Failed to open %s\n", in datalink_UpdateSet()
311 dl->physical->name.full); in datalink_UpdateSet()
312 bundle_LinkClosed(dl->bundle, dl); in datalink_UpdateSet()
314 if (!dl->bundle->CleaningUp) { in datalink_UpdateSet()
317 timeout = datalink_StartDialTimer(dl, datalink_GetDialTimeout(dl)); in datalink_UpdateSet()
318 bundle_Notify(dl->bundle, EX_REDIAL); in datalink_UpdateSet()
319 log_WritePrompts(dl, "Failed to open %s, pause %d seconds\n", in datalink_UpdateSet()
320 dl->physical->name.full, timeout); in datalink_UpdateSet()
328 switch (physical_AwaitCarrier(dl->physical)) { in datalink_UpdateSet()
334 if (dl->script.run) { in datalink_UpdateSet()
335 datalink_NewState(dl, DATALINK_LOGIN); in datalink_UpdateSet()
336 if (!chat_Setup(&dl->chat, dl->cfg.script.login, NULL)) in datalink_UpdateSet()
339 datalink_LoginDone(dl); in datalink_UpdateSet()
343 physical_Offline(dl->physical); /* Is this required ? */ in datalink_UpdateSet()
344 if (dl->script.run) { in datalink_UpdateSet()
345 datalink_NewState(dl, DATALINK_HANGUP); in datalink_UpdateSet()
346 if (!chat_Setup(&dl->chat, dl->cfg.script.hangup, NULL)) in datalink_UpdateSet()
350 datalink_HangupDone(dl); in datalink_UpdateSet()
359 result = descriptor_UpdateSet(&dl->chat.desc, r, w, e, n); in datalink_UpdateSet()
360 switch (dl->chat.state) { in datalink_UpdateSet()
363 switch(dl->state) { in datalink_UpdateSet()
365 datalink_HangupDone(dl); in datalink_UpdateSet()
368 datalink_NewState(dl, DATALINK_CARRIER); in datalink_UpdateSet()
371 datalink_NewState(dl, DATALINK_HANGUP); in datalink_UpdateSet()
372 physical_Offline(dl->physical); in datalink_UpdateSet()
373 if (!chat_Setup(&dl->chat, dl->cfg.script.hangup, NULL)) in datalink_UpdateSet()
377 dl->phone.alt = NULL; in datalink_UpdateSet()
378 datalink_LoginDone(dl); in datalink_UpdateSet()
385 switch(dl->state) { in datalink_UpdateSet()
387 datalink_HangupDone(dl); in datalink_UpdateSet()
392 datalink_NewState(dl, DATALINK_HANGUP); in datalink_UpdateSet()
393 physical_Offline(dl->physical); in datalink_UpdateSet()
394 if (!chat_Setup(&dl->chat, dl->cfg.script.hangup, NULL)) in datalink_UpdateSet()
407 result = descriptor_UpdateSet(&dl->chap.desc, r, w, e, n) + in datalink_UpdateSet()
408 descriptor_UpdateSet(&dl->physical->desc, r, w, e, n); in datalink_UpdateSet()
415 datalink_RemoveFromSet(struct datalink *dl, fd_set *r, fd_set *w, fd_set *e) in datalink_RemoveFromSet() argument
417 return physical_RemoveFromSet(dl->physical, r, w, e); in datalink_RemoveFromSet()
423 struct datalink *dl = descriptor2datalink(d); in datalink_IsSet() local
425 switch (dl->state) { in datalink_IsSet()
434 return descriptor_IsSet(&dl->chat.desc, fdset); in datalink_IsSet()
441 return descriptor_IsSet(&dl->chap.desc, fdset) ? 1 : in datalink_IsSet()
442 descriptor_IsSet(&dl->physical->desc, fdset); in datalink_IsSet()
450 struct datalink *dl = descriptor2datalink(d); in datalink_Read() local
452 switch (dl->state) { in datalink_Read()
461 descriptor_Read(&dl->chat.desc, bundle, fdset); in datalink_Read()
469 if (descriptor_IsSet(&dl->chap.desc, fdset)) in datalink_Read()
470 descriptor_Read(&dl->chap.desc, bundle, fdset); in datalink_Read()
471 if (descriptor_IsSet(&dl->physical->desc, fdset)) in datalink_Read()
472 descriptor_Read(&dl->physical->desc, bundle, fdset); in datalink_Read()
481 struct datalink *dl = descriptor2datalink(d); in datalink_Write() local
484 switch (dl->state) { in datalink_Write()
493 if ((result = descriptor_Write(&dl->chat.desc, bundle, fdset)) == -1) { in datalink_Write()
494 datalink_ComeDown(dl, CLOSE_NORMAL); in datalink_Write()
504 if (descriptor_IsSet(&dl->chap.desc, fdset)) in datalink_Write()
505 switch (descriptor_Write(&dl->chap.desc, bundle, fdset)) { in datalink_Write()
507 datalink_ComeDown(dl, CLOSE_NORMAL); in datalink_Write()
512 if (descriptor_IsSet(&dl->physical->desc, fdset)) in datalink_Write()
513 switch (descriptor_Write(&dl->physical->desc, bundle, fdset)) { in datalink_Write()
515 datalink_ComeDown(dl, CLOSE_NORMAL); in datalink_Write()
527 datalink_ComeDown(struct datalink *dl, int how) in datalink_ComeDown() argument
532 datalink_DontHangup(dl); in datalink_ComeDown()
534 datalink_StayDown(dl); in datalink_ComeDown()
536 stayonline = dl->stayonline; in datalink_ComeDown()
537 dl->stayonline = 0; in datalink_ComeDown()
539 if (dl->state >= DATALINK_READY && stayonline) { in datalink_ComeDown()
540 physical_StopDeviceTimer(dl->physical); in datalink_ComeDown()
541 datalink_NewState(dl, DATALINK_READY); in datalink_ComeDown()
542 } else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) { in datalink_ComeDown()
543 physical_Offline(dl->physical); in datalink_ComeDown()
544 if (dl->script.run && dl->state != DATALINK_OPENING) { in datalink_ComeDown()
545 if (dl->state == DATALINK_LOGOUT) { in datalink_ComeDown()
546 datalink_NewState(dl, DATALINK_HANGUP); in datalink_ComeDown()
547 if (!chat_Setup(&dl->chat, dl->cfg.script.hangup, NULL)) in datalink_ComeDown()
550 datalink_NewState(dl, DATALINK_LOGOUT); in datalink_ComeDown()
551 if (!chat_Setup(&dl->chat, dl->cfg.script.logout, NULL)) in datalink_ComeDown()
555 datalink_HangupDone(dl); in datalink_ComeDown()
563 struct datalink *dl = (struct datalink *)v; in datalink_LayerStart() local
566 (*dl->parent->LayerStart)(dl->parent->object, fp); in datalink_LayerStart()
573 struct datalink *dl = (struct datalink *)v; in datalink_LayerUp() local
574 struct lcp *lcp = &dl->physical->link.lcp; in datalink_LayerUp()
577 datalink_GotAuthname(dl, ""); in datalink_LayerUp()
581 if (bundle_Phase(dl->bundle) != PHASE_NETWORK) in datalink_LayerUp()
582 bundle_NewPhase(dl->bundle, PHASE_AUTHENTICATE); in datalink_LayerUp()
583 log_Printf(LogPHASE, "%s: his = %s, mine = %s\n", dl->name, in datalink_LayerUp()
587 auth_StartReq(&dl->pap); in datalink_LayerUp()
589 auth_StartReq(&dl->chap.auth); in datalink_LayerUp()
591 datalink_AuthOk(dl); in datalink_LayerUp()
593 (*dl->parent->LayerUp)(dl->parent->object, &dl->physical->link.ccp.fsm); in datalink_LayerUp()
597 datalink_AuthReInit(struct datalink *dl) in datalink_AuthReInit() argument
599 auth_StopTimer(&dl->pap); in datalink_AuthReInit()
600 auth_StopTimer(&dl->chap.auth); in datalink_AuthReInit()
601 chap_ReInit(&dl->chap); in datalink_AuthReInit()
605 datalink_GotAuthname(struct datalink *dl, const char *name) in datalink_GotAuthname() argument
607 strncpy(dl->peer.authname, name, sizeof dl->peer.authname - 1); in datalink_GotAuthname()
608 dl->peer.authname[sizeof dl->peer.authname - 1] = '\0'; in datalink_GotAuthname()
612 datalink_NCPUp(struct datalink *dl) in datalink_NCPUp() argument
614 int ccpok = ccp_SetOpenMode(&dl->physical->link.ccp); in datalink_NCPUp()
616 if (dl->physical->link.lcp.want_mrru && dl->physical->link.lcp.his_mrru) { in datalink_NCPUp()
618 switch (mp_Up(&dl->bundle->ncp.mp, dl)) { in datalink_NCPUp()
624 auth_Select(dl->bundle, dl->peer.authname); in datalink_NCPUp()
625 bundle_CalculateBandwidth(dl->bundle); in datalink_NCPUp()
629 dl->physical->link.ccp.fsm.open_mode = OPEN_PASSIVE; /* override */ in datalink_NCPUp()
630 bundle_CalculateBandwidth(dl->bundle); in datalink_NCPUp()
633 datalink_AuthNotOk(dl); in datalink_NCPUp()
636 } else if (bundle_Phase(dl->bundle) == PHASE_NETWORK) { in datalink_NCPUp()
637 log_Printf(LogPHASE, "%s: Already in NETWORK phase\n", dl->name); in datalink_NCPUp()
638 datalink_NewState(dl, DATALINK_OPEN); in datalink_NCPUp()
639 bundle_CalculateBandwidth(dl->bundle); in datalink_NCPUp()
640 (*dl->parent->LayerUp)(dl->parent->object, &dl->physical->link.lcp.fsm); in datalink_NCPUp()
643 dl->bundle->ncp.mp.peer = dl->peer; in datalink_NCPUp()
644 ncp_SetLink(&dl->bundle->ncp, &dl->physical->link); in datalink_NCPUp()
645 auth_Select(dl->bundle, dl->peer.authname); in datalink_NCPUp()
649 fsm_Up(&dl->physical->link.ccp.fsm); in datalink_NCPUp()
650 fsm_Open(&dl->physical->link.ccp.fsm); in datalink_NCPUp()
652 datalink_NewState(dl, DATALINK_OPEN); in datalink_NCPUp()
653 bundle_NewPhase(dl->bundle, PHASE_NETWORK); in datalink_NCPUp()
654 (*dl->parent->LayerUp)(dl->parent->object, &dl->physical->link.lcp.fsm); in datalink_NCPUp()
658 datalink_CBCPComplete(struct datalink *dl) in datalink_CBCPComplete() argument
660 datalink_NewState(dl, DATALINK_LCP); in datalink_CBCPComplete()
661 datalink_AuthReInit(dl); in datalink_CBCPComplete()
662 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_CBCPComplete()
666 datalink_CBCPFailed(struct datalink *dl) in datalink_CBCPFailed() argument
668 cbcp_Down(&dl->cbcp); in datalink_CBCPFailed()
669 datalink_CBCPComplete(dl); in datalink_CBCPFailed()
673 datalink_AuthOk(struct datalink *dl) in datalink_AuthOk() argument
675 if ((dl->physical->link.lcp.his_callback.opmask & in datalink_AuthOk()
677 dl->physical->link.lcp.want_callback.opmask & in datalink_AuthOk()
679 !(dl->physical->link.lcp.want_callback.opmask & in datalink_AuthOk()
682 datalink_NewState(dl, DATALINK_CBCP); in datalink_AuthOk()
683 cbcp_Up(&dl->cbcp); in datalink_AuthOk()
684 } else if (dl->physical->link.lcp.want_callback.opmask) { in datalink_AuthOk()
686 log_Printf(LogPHASE, "%s: Shutdown and await peer callback\n", dl->name); in datalink_AuthOk()
687 datalink_NewState(dl, DATALINK_LCP); in datalink_AuthOk()
688 datalink_AuthReInit(dl); in datalink_AuthOk()
689 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_AuthOk()
691 switch (dl->physical->link.lcp.his_callback.opmask) { in datalink_AuthOk()
693 datalink_NCPUp(dl); in datalink_AuthOk()
697 auth_SetPhoneList(dl->peer.authname, dl->cbcp.fsm.phone, in datalink_AuthOk()
698 sizeof dl->cbcp.fsm.phone); in datalink_AuthOk()
699 if (*dl->cbcp.fsm.phone == '\0' || !strcmp(dl->cbcp.fsm.phone, "*")) { in datalink_AuthOk()
700 log_Printf(LogPHASE, "%s: %s cannot be called back\n", dl->name, in datalink_AuthOk()
701 dl->peer.authname); in datalink_AuthOk()
702 *dl->cbcp.fsm.phone = '\0'; in datalink_AuthOk()
704 char *ptr = strchr(dl->cbcp.fsm.phone, ','); in datalink_AuthOk()
707 log_Printf(LogPHASE, "%s: Calling peer back on %s\n", dl->name, in datalink_AuthOk()
708 dl->cbcp.fsm.phone); in datalink_AuthOk()
709 dl->cbcp.required = 1; in datalink_AuthOk()
711 dl->cbcp.fsm.delay = 0; in datalink_AuthOk()
712 datalink_NewState(dl, DATALINK_LCP); in datalink_AuthOk()
713 datalink_AuthReInit(dl); in datalink_AuthOk()
714 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_AuthOk()
718 strncpy(dl->cbcp.fsm.phone, dl->physical->link.lcp.his_callback.msg, in datalink_AuthOk()
719 sizeof dl->cbcp.fsm.phone - 1); in datalink_AuthOk()
720 dl->cbcp.fsm.phone[sizeof dl->cbcp.fsm.phone - 1] = '\0'; in datalink_AuthOk()
721 log_Printf(LogPHASE, "%s: Calling peer back on %s\n", dl->name, in datalink_AuthOk()
722 dl->cbcp.fsm.phone); in datalink_AuthOk()
723 dl->cbcp.required = 1; in datalink_AuthOk()
724 dl->cbcp.fsm.delay = 0; in datalink_AuthOk()
725 datalink_NewState(dl, DATALINK_LCP); in datalink_AuthOk()
726 datalink_AuthReInit(dl); in datalink_AuthOk()
727 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_AuthOk()
732 dl->name); in datalink_AuthOk()
733 datalink_NewState(dl, DATALINK_LCP); in datalink_AuthOk()
734 datalink_AuthReInit(dl); in datalink_AuthOk()
735 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_AuthOk()
741 datalink_AuthNotOk(struct datalink *dl) in datalink_AuthNotOk() argument
743 datalink_NewState(dl, DATALINK_LCP); in datalink_AuthNotOk()
744 datalink_AuthReInit(dl); in datalink_AuthNotOk()
745 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_AuthNotOk()
752 struct datalink *dl = (struct datalink *)v; in datalink_LayerDown() local
755 switch (dl->state) { in datalink_LayerDown()
757 peerid_Init(&dl->peer); in datalink_LayerDown()
758 fsm2initial(&dl->physical->link.ccp.fsm); in datalink_LayerDown()
759 datalink_NewState(dl, DATALINK_LCP); /* before parent TLD */ in datalink_LayerDown()
760 (*dl->parent->LayerDown)(dl->parent->object, fp); in datalink_LayerDown()
764 if (!dl->cbcp.required) in datalink_LayerDown()
765 cbcp_Down(&dl->cbcp); in datalink_LayerDown()
769 timer_Stop(&dl->pap.authtimer); in datalink_LayerDown()
770 timer_Stop(&dl->chap.auth.authtimer); in datalink_LayerDown()
772 datalink_NewState(dl, DATALINK_LCP); in datalink_LayerDown()
773 datalink_AuthReInit(dl); in datalink_LayerDown()
781 struct datalink *dl = (struct datalink *)v; in datalink_LayerFinish() local
785 (*dl->parent->LayerFinish)(dl->parent->object, fp); in datalink_LayerFinish()
786 datalink_ComeDown(dl, CLOSE_NORMAL); in datalink_LayerFinish()
794 struct datalink *dl; in datalink_Create() local
796 dl = (struct datalink *)malloc(sizeof(struct datalink)); in datalink_Create()
797 if (dl == NULL) in datalink_Create()
798 return dl; in datalink_Create()
800 dl->desc.type = DATALINK_DESCRIPTOR; in datalink_Create()
801 dl->desc.UpdateSet = datalink_UpdateSet; in datalink_Create()
802 dl->desc.IsSet = datalink_IsSet; in datalink_Create()
803 dl->desc.Read = datalink_Read; in datalink_Create()
804 dl->desc.Write = datalink_Write; in datalink_Create()
806 dl->state = DATALINK_CLOSED; in datalink_Create()
808 *dl->cfg.script.dial = '\0'; in datalink_Create()
809 *dl->cfg.script.login = '\0'; in datalink_Create()
810 *dl->cfg.script.logout = '\0'; in datalink_Create()
811 *dl->cfg.script.hangup = '\0'; in datalink_Create()
812 *dl->cfg.phone.list = '\0'; in datalink_Create()
813 *dl->phone.list = '\0'; in datalink_Create()
814 dl->phone.next = NULL; in datalink_Create()
815 dl->phone.alt = NULL; in datalink_Create()
816 dl->phone.chosen = "N/A"; in datalink_Create()
817 dl->stayonline = 0; in datalink_Create()
818 dl->script.run = 1; in datalink_Create()
819 dl->script.packetmode = 1; in datalink_Create()
820 mp_linkInit(&dl->mp); in datalink_Create()
822 dl->bundle = bundle; in datalink_Create()
823 dl->next = NULL; in datalink_Create()
825 memset(&dl->dial.timer, '\0', sizeof dl->dial.timer); in datalink_Create()
827 dl->dial.tries = 0; in datalink_Create()
828 dl->cfg.dial.max = 1; in datalink_Create()
829 dl->cfg.dial.next_timeout = DIAL_NEXT_TIMEOUT; in datalink_Create()
830 dl->cfg.dial.timeout = DIAL_TIMEOUT; in datalink_Create()
831 dl->cfg.dial.inc = 0; in datalink_Create()
832 dl->cfg.dial.maxinc = 10; in datalink_Create()
834 dl->reconnect_tries = 0; in datalink_Create()
835 dl->cfg.reconnect.max = 0; in datalink_Create()
836 dl->cfg.reconnect.timeout = RECONNECT_TIMEOUT; in datalink_Create()
838 dl->cfg.callback.opmask = 0; in datalink_Create()
839 dl->cfg.cbcp.delay = 0; in datalink_Create()
840 *dl->cfg.cbcp.phone = '\0'; in datalink_Create()
841 dl->cfg.cbcp.fsmretry = DEF_FSMRETRY; in datalink_Create()
843 dl->name = strdup(name); in datalink_Create()
844 peerid_Init(&dl->peer); in datalink_Create()
845 dl->parent = &bundle->fsm; in datalink_Create()
846 dl->fsmp.LayerStart = datalink_LayerStart; in datalink_Create()
847 dl->fsmp.LayerUp = datalink_LayerUp; in datalink_Create()
848 dl->fsmp.LayerDown = datalink_LayerDown; in datalink_Create()
849 dl->fsmp.LayerFinish = datalink_LayerFinish; in datalink_Create()
850 dl->fsmp.object = dl; in datalink_Create()
852 if ((dl->physical = physical_Create(dl, type)) == NULL) { in datalink_Create()
853 free(dl->name); in datalink_Create()
854 free(dl); in datalink_Create()
858 pap_Init(&dl->pap, dl->physical); in datalink_Create()
859 chap_Init(&dl->chap, dl->physical); in datalink_Create()
860 cbcp_Init(&dl->cbcp, dl->physical); in datalink_Create()
862 memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ in datalink_Create()
863 chat_Init(&dl->chat, dl->physical); in datalink_Create()
866 dl->name, datalink_State(dl)); in datalink_Create()
868 return dl; in datalink_Create()
874 struct datalink *dl; in datalink_Clone() local
876 dl = (struct datalink *)malloc(sizeof(struct datalink)); in datalink_Clone()
877 if (dl == NULL) in datalink_Clone()
878 return dl; in datalink_Clone()
880 dl->desc.type = DATALINK_DESCRIPTOR; in datalink_Clone()
881 dl->desc.UpdateSet = datalink_UpdateSet; in datalink_Clone()
882 dl->desc.IsSet = datalink_IsSet; in datalink_Clone()
883 dl->desc.Read = datalink_Read; in datalink_Clone()
884 dl->desc.Write = datalink_Write; in datalink_Clone()
886 dl->state = DATALINK_CLOSED; in datalink_Clone()
888 memcpy(&dl->cfg, &odl->cfg, sizeof dl->cfg); in datalink_Clone()
889 mp_linkInit(&dl->mp); in datalink_Clone()
890 *dl->phone.list = '\0'; in datalink_Clone()
891 dl->phone.next = NULL; in datalink_Clone()
892 dl->phone.alt = NULL; in datalink_Clone()
893 dl->phone.chosen = "N/A"; in datalink_Clone()
894 dl->bundle = odl->bundle; in datalink_Clone()
895 dl->next = NULL; in datalink_Clone()
896 memset(&dl->dial.timer, '\0', sizeof dl->dial.timer); in datalink_Clone()
897 dl->dial.tries = 0; in datalink_Clone()
898 dl->reconnect_tries = 0; in datalink_Clone()
899 dl->name = strdup(name); in datalink_Clone()
900 peerid_Init(&dl->peer); in datalink_Clone()
901 dl->parent = odl->parent; in datalink_Clone()
902 memcpy(&dl->fsmp, &odl->fsmp, sizeof dl->fsmp); in datalink_Clone()
903 dl->fsmp.object = dl; in datalink_Clone()
905 if ((dl->physical = physical_Create(dl, PHYS_INTERACTIVE)) == NULL) { in datalink_Clone()
906 free(dl->name); in datalink_Clone()
907 free(dl); in datalink_Clone()
910 pap_Init(&dl->pap, dl->physical); in datalink_Clone()
911 dl->pap.cfg = odl->pap.cfg; in datalink_Clone()
913 chap_Init(&dl->chap, dl->physical); in datalink_Clone()
914 dl->chap.auth.cfg = odl->chap.auth.cfg; in datalink_Clone()
916 memcpy(&dl->physical->cfg, &odl->physical->cfg, sizeof dl->physical->cfg); in datalink_Clone()
917 memcpy(&dl->physical->link.lcp.cfg, &odl->physical->link.lcp.cfg, in datalink_Clone()
918 sizeof dl->physical->link.lcp.cfg); in datalink_Clone()
919 memcpy(&dl->physical->link.ccp.cfg, &odl->physical->link.ccp.cfg, in datalink_Clone()
920 sizeof dl->physical->link.ccp.cfg); in datalink_Clone()
921 memcpy(&dl->physical->async.cfg, &odl->physical->async.cfg, in datalink_Clone()
922 sizeof dl->physical->async.cfg); in datalink_Clone()
924 cbcp_Init(&dl->cbcp, dl->physical); in datalink_Clone()
926 memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ in datalink_Clone()
927 chat_Init(&dl->chat, dl->physical); in datalink_Clone()
930 dl->name, datalink_State(dl)); in datalink_Clone()
932 return dl; in datalink_Clone()
936 datalink_Destroy(struct datalink *dl) in datalink_Destroy() argument
940 if (dl->state != DATALINK_CLOSED) { in datalink_Destroy()
942 datalink_State(dl)); in datalink_Destroy()
943 switch (dl->state) { in datalink_Destroy()
947 chat_Finish(&dl->chat); /* Gotta blat the timers ! */ in datalink_Destroy()
952 chat_Destroy(&dl->chat); in datalink_Destroy()
953 timer_Stop(&dl->dial.timer); in datalink_Destroy()
954 result = dl->next; in datalink_Destroy()
955 physical_Destroy(dl->physical); in datalink_Destroy()
956 free(dl->name); in datalink_Destroy()
957 free(dl); in datalink_Destroy()
963 datalink_Up(struct datalink *dl, int runscripts, int packetmode) in datalink_Up() argument
965 if (!Enabled(dl->bundle, OPT_FORCE_SCRIPTS) && in datalink_Up()
966 (dl->physical->type & (PHYS_DIRECT|PHYS_DEDICATED))) in datalink_Up()
970 switch (dl->state) { in datalink_Up()
972 if (bundle_Phase(dl->bundle) == PHASE_DEAD || in datalink_Up()
973 bundle_Phase(dl->bundle) == PHASE_TERMINATE) in datalink_Up()
974 bundle_NewPhase(dl->bundle, PHASE_ESTABLISH); in datalink_Up()
975 datalink_NewState(dl, DATALINK_OPENING); in datalink_Up()
976 dl->reconnect_tries = in datalink_Up()
977 dl->physical->type == PHYS_DIRECT ? 0 : dl->cfg.reconnect.max; in datalink_Up()
978 dl->dial.tries = dl->cfg.dial.max; in datalink_Up()
979 dl->script.run = runscripts; in datalink_Up()
980 dl->script.packetmode = packetmode; in datalink_Up()
984 if (!dl->script.run && runscripts) in datalink_Up()
985 dl->script.run = 1; in datalink_Up()
991 if (!dl->script.packetmode && packetmode) { in datalink_Up()
992 dl->script.packetmode = 1; in datalink_Up()
993 if (dl->state == DATALINK_READY) { in datalink_Up()
994 dl->script.run = 0; in datalink_Up()
995 datalink_NewState(dl, DATALINK_CARRIER); in datalink_Up()
1003 datalink_Close(struct datalink *dl, int how) in datalink_Close() argument
1006 switch (dl->state) { in datalink_Close()
1008 peerid_Init(&dl->peer); in datalink_Close()
1009 fsm2initial(&dl->physical->link.ccp.fsm); in datalink_Close()
1015 datalink_AuthReInit(dl); in datalink_Close()
1017 datalink_DontHangup(dl); in datalink_Close()
1019 datalink_StayDown(dl); in datalink_Close()
1020 fsm_Close(&dl->physical->link.lcp.fsm); in datalink_Close()
1024 datalink_ComeDown(dl, how); in datalink_Close()
1029 datalink_Down(struct datalink *dl, int how) in datalink_Down() argument
1032 switch (dl->state) { in datalink_Down()
1034 peerid_Init(&dl->peer); in datalink_Down()
1035 fsm2initial(&dl->physical->link.ccp.fsm); in datalink_Down()
1041 fsm2initial(&dl->physical->link.lcp.fsm); in datalink_Down()
1042 if (dl->state == DATALINK_OPENING) in datalink_Down()
1047 datalink_ComeDown(dl, how); in datalink_Down()
1052 datalink_StayDown(struct datalink *dl) in datalink_StayDown() argument
1054 dl->dial.tries = -1; in datalink_StayDown()
1055 dl->reconnect_tries = 0; in datalink_StayDown()
1056 dl->stayonline = 0; in datalink_StayDown()
1060 datalink_DontHangup(struct datalink *dl) in datalink_DontHangup() argument
1062 dl->dial.tries = -1; in datalink_DontHangup()
1063 dl->reconnect_tries = 0; in datalink_DontHangup()
1064 dl->stayonline = dl->state >= DATALINK_LCP ? 1 : 0; in datalink_DontHangup()
1271 datalink_State(struct datalink *dl) in datalink_State() argument
1273 if (dl->state >= sizeof states / sizeof states[0]) in datalink_State()
1275 return states[dl->state]; in datalink_State()
1279 datalink_NewState(struct datalink *dl, unsigned state) in datalink_NewState() argument
1281 if (state != dl->state) { in datalink_NewState()
1283 log_Printf(LogPHASE, "%s: %s -> %s\n", dl->name, datalink_State(dl), in datalink_NewState()
1285 dl->state = state; in datalink_NewState()
1287 log_Printf(LogERROR, "%s: Can't enter state %d !\n", dl->name, state); in datalink_NewState()
1295 struct datalink *dl, *cdl; in iov2datalink() local
1299 dl = (struct datalink *)iov[(*niov)++].iov_base; in iov2datalink()
1300 dl->name = iov[*niov].iov_base; in iov2datalink()
1302 if (dl->name[DATALINK_MAXNAME-1]) { in iov2datalink()
1303 dl->name[DATALINK_MAXNAME-1] = '\0'; in iov2datalink()
1304 if (strlen(dl->name) == DATALINK_MAXNAME - 1) in iov2datalink()
1305 log_Printf(LogWARN, "Datalink name truncated to \"%s\"\n", dl->name); in iov2datalink()
1312 if (!strcasecmp(dl->name, cdl->name)) { in iov2datalink()
1313 if ((pname = datalink_NextName(dl)) == NULL) { in iov2datalink()
1326 log_Printf(LogPHASE, "Rename link %s to %s\n", oname, dl->name); in iov2datalink()
1329 dl->name = strdup(dl->name); in iov2datalink()
1334 dl->desc.type = DATALINK_DESCRIPTOR; in iov2datalink()
1335 dl->desc.UpdateSet = datalink_UpdateSet; in iov2datalink()
1336 dl->desc.IsSet = datalink_IsSet; in iov2datalink()
1337 dl->desc.Read = datalink_Read; in iov2datalink()
1338 dl->desc.Write = datalink_Write; in iov2datalink()
1340 mp_linkInit(&dl->mp); in iov2datalink()
1341 *dl->phone.list = '\0'; in iov2datalink()
1342 dl->phone.next = NULL; in iov2datalink()
1343 dl->phone.alt = NULL; in iov2datalink()
1344 dl->phone.chosen = "N/A"; in iov2datalink()
1346 dl->bundle = bundle; in iov2datalink()
1347 dl->next = NULL; in iov2datalink()
1348 memset(&dl->dial.timer, '\0', sizeof dl->dial.timer); in iov2datalink()
1349 dl->dial.tries = 0; in iov2datalink()
1350 dl->reconnect_tries = 0; in iov2datalink()
1351 dl->parent = &bundle->fsm; in iov2datalink()
1352 dl->fsmp.LayerStart = datalink_LayerStart; in iov2datalink()
1353 dl->fsmp.LayerUp = datalink_LayerUp; in iov2datalink()
1354 dl->fsmp.LayerDown = datalink_LayerDown; in iov2datalink()
1355 dl->fsmp.LayerFinish = datalink_LayerFinish; in iov2datalink()
1356 dl->fsmp.object = dl; in iov2datalink()
1358 dl->physical = iov2physical(dl, iov, niov, maxiov, fd, auxfd, nauxfd); in iov2datalink()
1360 if (!dl->physical) { in iov2datalink()
1361 free(dl->name); in iov2datalink()
1362 free(dl); in iov2datalink()
1363 dl = NULL; in iov2datalink()
1365 copy = dl->pap.cfg.fsm; in iov2datalink()
1366 pap_Init(&dl->pap, dl->physical); in iov2datalink()
1367 dl->pap.cfg.fsm = copy; in iov2datalink()
1369 copy = dl->chap.auth.cfg.fsm; in iov2datalink()
1370 chap_Init(&dl->chap, dl->physical); in iov2datalink()
1371 dl->chap.auth.cfg.fsm = copy; in iov2datalink()
1373 cbcp_Init(&dl->cbcp, dl->physical); in iov2datalink()
1375 memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ in iov2datalink()
1376 chat_Init(&dl->chat, dl->physical); in iov2datalink()
1379 dl->name, datalink_State(dl)); in iov2datalink()
1382 return dl; in iov2datalink()
1386 datalink2iov(struct datalink *dl, struct iovec *iov, int *niov, int maxiov, in datalink2iov() argument
1392 if (dl) { in datalink2iov()
1393 timer_Stop(&dl->dial.timer); in datalink2iov()
1395 cbcp_Down(&dl->cbcp); in datalink2iov()
1396 timer_Stop(&dl->pap.authtimer); in datalink2iov()
1397 timer_Stop(&dl->chap.auth.authtimer); in datalink2iov()
1402 if (dl) { in datalink2iov()
1403 free(dl->name); in datalink2iov()
1404 free(dl); in datalink2iov()
1409 iov[*niov].iov_base = (void *)dl; in datalink2iov()
1410 iov[(*niov)++].iov_len = sizeof *dl; in datalink2iov()
1411 iov[*niov].iov_base = dl ? realloc(dl->name, DATALINK_MAXNAME) : NULL; in datalink2iov()
1414 link_fd = physical2iov(dl ? dl->physical : NULL, iov, niov, maxiov, auxfd, in datalink2iov()
1417 if (link_fd == -1 && dl) { in datalink2iov()
1418 free(dl->name); in datalink2iov()
1419 free(dl); in datalink2iov()
1426 datalink_Rename(struct datalink *dl, const char *name) in datalink_Rename() argument
1428 free(dl->name); in datalink_Rename()
1429 dl->physical->link.name = dl->name = strdup(name); in datalink_Rename()
1433 datalink_NextName(struct datalink *dl) in datalink_NextName() argument
1438 n = strlen(dl->name); in datalink_NextName()
1444 if (!isdigit(dl->name[f])) in datalink_NextName()
1446 n = sprintf(name, "%.*s-", dl->name[f] == '-' ? f : f + 1, dl->name); in datalink_NextName()
1447 sprintf(name + n, "%d", atoi(dl->name + f + 1) + 1); in datalink_NextName()
1448 oname = dl->name; in datalink_NextName()
1449 dl->name = name; in datalink_NextName()
1455 datalink_SetMode(struct datalink *dl, int mode) in datalink_SetMode() argument
1457 if (!physical_SetMode(dl->physical, mode)) in datalink_SetMode()
1459 if (dl->physical->type & (PHYS_DIRECT|PHYS_DEDICATED)) in datalink_SetMode()
1460 dl->script.run = 0; in datalink_SetMode()
1461 if (dl->physical->type == PHYS_DIRECT) in datalink_SetMode()
1462 dl->reconnect_tries = 0; in datalink_SetMode()
1464 dl->state <= DATALINK_READY) in datalink_SetMode()
1465 datalink_Up(dl, 1, 1); in datalink_SetMode()
1470 datalink_GetDialTimeout(struct datalink *dl) in datalink_GetDialTimeout() argument
1472 int result = dl->cfg.dial.timeout + dl->dial.incs * dl->cfg.dial.inc; in datalink_GetDialTimeout()
1474 if (dl->dial.incs < dl->cfg.dial.maxinc) in datalink_GetDialTimeout()
1475 dl->dial.incs++; in datalink_GetDialTimeout()