Lines Matching +full:full +full:- +full:speed

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
85 #define Online(dev) ((dev)->mbits & TIOCM_CD)
94 unsigned speed; /* Pre-line-discipline speed */ member
95 int fd; /* Pre-line-discipline fd */
96 int disc; /* Old line-discipline */
104 #define device2tty(d) ((d)->type == TTY_DEVICE ? (struct ttydevice *)d : NULL)
120 struct ttydevice *dev = device2tty(p->handler); in tty_Timeout()
123 timer_Stop(&dev->Timer); in tty_Timeout()
124 dev->Timer.load = SECTICKS; /* Once a second please */ in tty_Timeout()
125 timer_Start(&dev->Timer); in tty_Timeout()
126 ombits = dev->mbits; in tty_Timeout()
128 if (p->fd >= 0) { in tty_Timeout()
129 if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) { in tty_Timeout()
131 if (p->cfg.cd.necessity != CD_DEFAULT) in tty_Timeout()
133 "using ``set cd off''\n", p->link.name); in tty_Timeout()
134 timer_Stop(&dev->Timer); in tty_Timeout()
135 dev->mbits = TIOCM_CD; in tty_Timeout()
139 dev->mbits = 0; in tty_Timeout()
141 if (ombits == -1) { in tty_Timeout()
144 log_Printf(LogPHASE, "%s: %s: CD detected\n", p->link.name, p->name.full); in tty_Timeout()
145 else if (++dev->carrier_seconds >= dev->dev.cd.delay) { in tty_Timeout()
146 if (dev->dev.cd.necessity == CD_REQUIRED) in tty_Timeout()
148 p->link.name, p->name.full); in tty_Timeout()
151 p->link.name, p->name.full); in tty_Timeout()
152 dev->mbits = TIOCM_CD; /* Dodgy null-modem cable ? */ in tty_Timeout()
154 timer_Stop(&dev->Timer); in tty_Timeout()
159 p->link.name, p->name.full, dev->carrier_seconds, in tty_Timeout()
160 dev->dev.cd.delay); in tty_Timeout()
161 dev->mbits = -1; in tty_Timeout()
164 change = ombits ^ dev->mbits; in tty_Timeout()
166 if (dev->mbits & TIOCM_CD) in tty_Timeout()
167 log_Printf(LogDEBUG, "%s: offline -> online\n", p->link.name); in tty_Timeout()
169 log_Printf(LogDEBUG, "%s: online -> offline\n", p->link.name); in tty_Timeout()
170 log_Printf(LogPHASE, "%s: Carrier lost\n", p->link.name); in tty_Timeout()
171 datalink_Down(p->dl, CLOSE_NORMAL); in tty_Timeout()
172 timer_Stop(&dev->Timer); in tty_Timeout()
175 log_Printf(LogDEBUG, "%s: Still %sline\n", p->link.name, in tty_Timeout()
183 struct ttydevice *dev = device2tty(p->handler); in tty_StartTimer()
185 timer_Stop(&dev->Timer); in tty_StartTimer()
186 dev->Timer.load = SECTICKS; in tty_StartTimer()
187 dev->Timer.func = tty_Timeout; in tty_StartTimer()
188 dev->Timer.name = "tty CD"; in tty_StartTimer()
189 dev->Timer.arg = p; in tty_StartTimer()
191 p->link.name, tty_Timeout); in tty_StartTimer()
192 timer_Start(&dev->Timer); in tty_StartTimer()
198 struct ttydevice *dev = device2tty(p->handler); in tty_AwaitCarrier()
200 if (dev->dev.cd.necessity == CD_NOTREQUIRED || physical_IsSync(p)) in tty_AwaitCarrier()
203 if (dev->mbits == -1) { in tty_AwaitCarrier()
204 if (dev->Timer.state == TIMER_STOPPED) { in tty_AwaitCarrier()
205 dev->carrier_seconds = 0; in tty_AwaitCarrier()
223 return dev->real.fd != -1; in isngtty()
229 struct ttydevice *dev = device2tty(p->handler); in tty_SetAsyncParams()
236 snprintf(asyncpath, sizeof asyncpath, ".:%s", dev->hook); in tty_SetAsyncParams()
243 if (NgSendMsg(dev->cs, asyncpath, NGM_ASYNC_COOKIE, in tty_SetAsyncParams()
246 p->link.name, asyncpath); in tty_SetAsyncParams()
249 async_SetLinkParams(&p->async, mymap, hismap); in tty_SetAsyncParams()
255 struct ttydevice *dev = device2tty(p->handler); in LoadLineDiscipline()
263 unsigned speed; in LoadLineDiscipline() local
273 info = (struct nodeinfo *)reply->data; in LoadLineDiscipline()
278 /* Get the speed before loading the line discipline */ in LoadLineDiscipline()
279 speed = physical_GetSpeed(p); in LoadLineDiscipline()
281 if (ioctl(p->fd, TIOCGETD, &dev->real.disc) < 0) { in LoadLineDiscipline()
283 p->link.name); in LoadLineDiscipline()
287 if (ID0ioctl(p->fd, TIOCSETD, &ldisc) < 0) { in LoadLineDiscipline()
289 p->link.name); in LoadLineDiscipline()
294 if (ioctl(p->fd, NGIOCGINFO, info) < 0) { in LoadLineDiscipline()
295 log_Printf(LogWARN, "%s: ioctl(NGIOCGINFO): %s\n", p->link.name, in LoadLineDiscipline()
297 ID0ioctl(p->fd, TIOCSETD, &dev->real.disc); in LoadLineDiscipline()
300 snprintf(ttypath, sizeof ttypath, "%s:", info->name); in LoadLineDiscipline()
303 if (ID0NgMkSockNode(NULL, &cs, &ds) == -1) { in LoadLineDiscipline()
304 log_Printf(LogWARN, "%s: NgMkSockNode: %s\n", p->link.name, in LoadLineDiscipline()
306 ID0ioctl(p->fd, TIOCSETD, &dev->real.disc); in LoadLineDiscipline()
312 log_Printf(LogDEBUG, "%s: Set tty hotchar to 0x%02x\n", p->link.name, hot); in LoadLineDiscipline()
315 log_Printf(LogWARN, "%s: Can't set hot char\n", p->link.name); in LoadLineDiscipline()
323 log_Printf(LogDEBUG, "%s: Send mkpeer async:%s to %s:%s\n", p->link.name, in LoadLineDiscipline()
327 log_Printf(LogWARN, "%s: Can't create %s node\n", p->link.name, in LoadLineDiscipline()
336 log_Printf(LogDEBUG, "%s: Send connect %s:%s to .:%s\n", p->link.name, in LoadLineDiscipline()
340 log_Printf(LogWARN, "%s: Can't connect .:%s -> %s.%s: %s\n", in LoadLineDiscipline()
341 p->link.name, ngc.ourhook, ngc.path, ngc.peerhook, in LoadLineDiscipline()
349 p->link.name, ngc.path, strerror(errno)); in LoadLineDiscipline()
354 p->link.name, ngc.path, strerror(errno)); in LoadLineDiscipline()
359 snprintf(dev->hook, sizeof dev->hook, "%s", ngc.ourhook); in LoadLineDiscipline()
360 dev->cs = cs; in LoadLineDiscipline()
361 dev->real.fd = p->fd; in LoadLineDiscipline()
362 p->fd = ds; in LoadLineDiscipline()
363 dev->real.speed = speed; in LoadLineDiscipline()
367 physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE); in LoadLineDiscipline()
369 p->link.name); in LoadLineDiscipline()
374 ID0ioctl(p->fd, TIOCSETD, &dev->real.disc); in LoadLineDiscipline()
384 struct ttydevice *dev = device2tty(p->handler); in UnloadLineDiscipline()
387 if (!physical_SetSpeed(p, dev->real.speed)) in UnloadLineDiscipline()
388 log_Printf(LogWARN, "Couldn't reset tty speed to %d\n", dev->real.speed); in UnloadLineDiscipline()
389 dev->real.speed = 0; in UnloadLineDiscipline()
390 close(p->fd); in UnloadLineDiscipline()
391 p->fd = dev->real.fd; in UnloadLineDiscipline()
392 dev->real.fd = -1; in UnloadLineDiscipline()
393 close(dev->cs); in UnloadLineDiscipline()
394 dev->cs = -1; in UnloadLineDiscipline()
395 *dev->hook = '\0'; in UnloadLineDiscipline()
396 if (ID0ioctl(p->fd, TIOCSETD, &dev->real.disc) == 0) { in UnloadLineDiscipline()
397 physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE); in UnloadLineDiscipline()
399 p->link.name); in UnloadLineDiscipline()
402 p->link.name); in UnloadLineDiscipline()
409 struct ttydevice *dev = device2tty(p->handler); in tty_Write()
412 return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : (ssize_t)n; in tty_Write()
414 return write(p->fd, v, n); in tty_Write()
420 struct ttydevice *dev = device2tty(p->handler); in tty_Read()
424 return NgRecvData(p->fd, v, n, hook); in tty_Read()
426 return read(p->fd, v, n); in tty_Read()
434 struct ttydevice *dev = device2tty(p->handler); in tty_Raw()
438 log_Printf(LogDEBUG, "%s: Entering tty_Raw\n", p->link.name); in tty_Raw()
440 if (p->type != PHYS_DIRECT && p->fd >= 0 && !Online(dev)) in tty_Raw()
442 p->link.name, p->fd, dev->mbits); in tty_Raw()
449 tcgetattr(p->fd, &ios); in tty_Raw()
451 if (p->cfg.rts_cts) in tty_Raw()
456 if (p->type != PHYS_DEDICATED) in tty_Raw()
459 if (tcsetattr(p->fd, TCSANOW, &ios) == -1) in tty_Raw()
461 p->link.name); in tty_Raw()
465 oldflag = fcntl(p->fd, F_GETFL, 0); in tty_Raw()
468 fcntl(p->fd, F_SETFL, oldflag | O_NONBLOCK); in tty_Raw()
476 struct ttydevice *dev = device2tty(p->handler); in tty_Offline()
478 if (p->fd >= 0) { in tty_Offline()
479 timer_Stop(&dev->Timer); in tty_Offline()
480 dev->mbits &= ~TIOCM_DTR; /* XXX: Hmm, what's this supposed to do ? */ in tty_Offline()
484 tcgetattr(p->fd, &tio); in tty_Offline()
485 if (cfsetspeed(&tio, B0) == -1 || tcsetattr(p->fd, TCSANOW, &tio) == -1) in tty_Offline()
486 log_Printf(LogWARN, "%s: Unable to set physical to speed 0\n", in tty_Offline()
487 p->link.name); in tty_Offline()
495 struct ttydevice *dev = device2tty(p->handler); in tty_Cooked()
500 tcflush(p->fd, TCIOFLUSH); in tty_Cooked()
502 if (!physical_IsSync(p) && tcsetattr(p->fd, TCSAFLUSH, &dev->ios) == -1) in tty_Cooked()
504 p->link.name); in tty_Cooked()
510 if ((oldflag = fcntl(p->fd, F_GETFL, 0)) != -1) in tty_Cooked()
511 fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); in tty_Cooked()
517 struct ttydevice *dev = device2tty(p->handler); in tty_StopTimer()
519 timer_Stop(&dev->Timer); in tty_StopTimer()
525 struct ttydevice *dev = device2tty(p->handler); in tty_Free()
536 if (tcgetattr(p->fd, &ios) == -1) in tty_Speed()
545 struct ttydevice *dev = device2tty(p->handler); in tty_OpenInfo()
565 if (!strcmp(ttyp->ty_name, p->name.base)) { in tty_Slot()
571 return -1; in tty_Slot()
598 if (dev->cs >= 0) { in tty_device2iov()
599 *auxfd = dev->cs; in tty_device2iov()
604 if (dev->Timer.state != TIMER_STOPPED) { in tty_device2iov()
605 timer_Stop(&dev->Timer); in tty_device2iov()
606 dev->Timer.state = TIMER_RUNNING; in tty_device2iov()
653 dev->cs = *auxfd; in tty_iov2device()
654 (*nauxfd)--; in tty_iov2device()
656 dev->cs = -1; in tty_iov2device()
660 memcpy(&dev->dev, &basettydevice, sizeof dev->dev); in tty_iov2device()
662 physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE); in tty_iov2device()
663 if (dev->Timer.state != TIMER_STOPPED) { in tty_iov2device()
664 dev->Timer.state = TIMER_STOPPED; in tty_iov2device()
665 p->handler = &dev->dev; /* For the benefit of StartTimer */ in tty_iov2device()
668 return &dev->dev; in tty_iov2device()
681 if (p->fd < 0 || !isatty(p->fd)) in tty_Create()
685 if (*p->name.full == '\0') { in tty_Create()
686 physical_SetDevice(p, ttyname(p->fd)); in tty_Create()
688 p->link.name, p->name.full); in tty_Create()
690 log_Printf(LogDEBUG, "%s: Opened %s\n", p->link.name, p->name.full); in tty_Create()
695 /* Complete failure - parent doesn't continue trying to ``create'' */ in tty_Create()
696 close(p->fd); in tty_Create()
697 p->fd = -1; in tty_Create()
701 memcpy(&dev->dev, &basettydevice, sizeof dev->dev); in tty_Create()
702 memset(&dev->Timer, '\0', sizeof dev->Timer); in tty_Create()
703 dev->mbits = -1; in tty_Create()
705 dev->real.speed = 0; in tty_Create()
706 dev->real.fd = -1; in tty_Create()
707 dev->real.disc = -1; in tty_Create()
708 *dev->hook = '\0'; in tty_Create()
710 tcgetattr(p->fd, &ios); in tty_Create()
711 dev->ios = ios; in tty_Create()
713 if (p->cfg.cd.necessity != CD_DEFAULT) in tty_Create()
715 dev->dev.cd = p->cfg.cd; in tty_Create()
718 " iflag = %lx, oflag = %lx, cflag = %lx\n", p->link.name, p->fd, in tty_Create()
722 if (p->cfg.rts_cts) in tty_Create()
729 if (p->type != PHYS_DEDICATED) in tty_Create()
732 if (p->type != PHYS_DIRECT) { in tty_Create()
733 /* Change tty speed when we're not in -direct mode */ in tty_Create()
735 ios.c_cflag |= p->cfg.parity; in tty_Create()
736 if (cfsetspeed(&ios, UnsignedToSpeed(p->cfg.speed)) == -1) in tty_Create()
737 log_Printf(LogWARN, "%s: %s: Unable to set speed to %d\n", in tty_Create()
738 p->link.name, p->name.full, p->cfg.speed); in tty_Create()
741 if (tcsetattr(p->fd, TCSADRAIN, &ios) == -1) { in tty_Create()
743 p->link.name); in tty_Create()
744 if (p->type != PHYS_DIRECT && p->cfg.speed > 115200) in tty_Create()
745 log_Printf(LogWARN, "%.*s Perhaps the speed is unsupported\n", in tty_Create()
746 (int)strlen(p->link.name), ""); in tty_Create()
750 "cflag = %lx\n", p->link.name, (u_long)ios.c_iflag, in tty_Create()
753 oldflag = fcntl(p->fd, F_GETFL, 0); in tty_Create()
755 /* Complete failure - parent doesn't continue trying to ``create'' */ in tty_Create()
758 p->link.name, strerror(errno)); in tty_Create()
760 close(p->fd); in tty_Create()
761 p->fd = -1; in tty_Create()
765 fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); in tty_Create()
767 physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE); in tty_Create()
769 return &dev->dev; in tty_Create()