163b73463SBrian Somers /* 263b73463SBrian Somers * Written by Eivind Eklund <eivind@yes.no> 363b73463SBrian Somers * for Yes Interactive 463b73463SBrian Somers * 563b73463SBrian Somers * Copyright (C) 1998, Yes Interactive. All rights reserved. 663b73463SBrian Somers * 763b73463SBrian Somers * Redistribution and use in any form is permitted. Redistribution in 863b73463SBrian Somers * source form should include the above copyright and this set of 963b73463SBrian Somers * conditions, because large sections american law seems to have been 1063b73463SBrian Somers * created by a bunch of jerks on drugs that are now illegal, forcing 1163b73463SBrian Somers * me to include this copyright-stuff instead of placing this in the 1263b73463SBrian Somers * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund' 1363b73463SBrian Somers * may not be used to endorse or promote products derived from this 1463b73463SBrian Somers * software without specific prior written permission. 1563b73463SBrian Somers * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1663b73463SBrian Somers * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1763b73463SBrian Somers * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1863b73463SBrian Somers * 19ecd5172aSBrian Somers * $Id: physical.c,v 1.1.2.3 1998/02/02 19:33:39 brian Exp $ 2063b73463SBrian Somers * 2163b73463SBrian Somers */ 2263b73463SBrian Somers 2363b73463SBrian Somers #include <sys/param.h> 2463b73463SBrian Somers #include <sys/tty.h> 2563b73463SBrian Somers #include <sys/uio.h> 2663b73463SBrian Somers 2763b73463SBrian Somers #include <assert.h> 2863b73463SBrian Somers #include <stdio.h> 2963b73463SBrian Somers #include <string.h> 3063b73463SBrian Somers #include <unistd.h> 3163b73463SBrian Somers 3263b73463SBrian Somers 3363b73463SBrian Somers /* XXX Name space pollution from vars.h */ 3463b73463SBrian Somers #include <netinet/in.h> 3563b73463SBrian Somers #include <alias.h> 3663b73463SBrian Somers #include "defs.h" 3763b73463SBrian Somers #include "command.h" 3863b73463SBrian Somers #include "loadalias.h" 3963b73463SBrian Somers 4063b73463SBrian Somers /* XXX Name space pollution from hdlc.h */ 4163b73463SBrian Somers #include "mbuf.h" 4263b73463SBrian Somers 4363b73463SBrian Somers /* Name space pollution for physical.h */ 4463b73463SBrian Somers #include "hdlc.h" 4563b73463SBrian Somers #include "timer.h" 4663b73463SBrian Somers #include "throughput.h" 476140ba11SBrian Somers #include "fsm.h" 486140ba11SBrian Somers #include "lcp.h" 496140ba11SBrian Somers #include "async.h" 508c07a7b2SBrian Somers #include "link.h" 5163b73463SBrian Somers 5263b73463SBrian Somers #include "physical.h" 5363b73463SBrian Somers 5463b73463SBrian Somers #include "vars.h" 5563b73463SBrian Somers 5663b73463SBrian Somers /* External calls - should possibly be moved inline */ 5763b73463SBrian Somers extern int IntToSpeed(int); 5863b73463SBrian Somers 5963b73463SBrian Somers 6063b73463SBrian Somers int 6163b73463SBrian Somers Physical_GetFD(struct physical *phys) { 6263b73463SBrian Somers return phys->fd; 6363b73463SBrian Somers } 6463b73463SBrian Somers 6563b73463SBrian Somers int 6663b73463SBrian Somers Physical_IsATTY(struct physical *phys) { 6763b73463SBrian Somers return isatty(phys->fd); 6863b73463SBrian Somers } 6963b73463SBrian Somers 7063b73463SBrian Somers int 7163b73463SBrian Somers Physical_IsSync(struct physical *phys) { 7263b73463SBrian Somers return phys->speed == 0; 7363b73463SBrian Somers } 7463b73463SBrian Somers 7563b73463SBrian Somers int 7663b73463SBrian Somers Physical_FD_ISSET(struct physical *phys, fd_set *set) { 7763b73463SBrian Somers return phys->fd >= 0 && FD_ISSET(phys->fd, set); 7863b73463SBrian Somers } 7963b73463SBrian Somers 8063b73463SBrian Somers void 8163b73463SBrian Somers Physical_FD_SET(struct physical *phys, fd_set *set) { 8263b73463SBrian Somers assert(phys->fd >= 0); 8363b73463SBrian Somers FD_SET(phys->fd, set); 8463b73463SBrian Somers } 8563b73463SBrian Somers 8663b73463SBrian Somers 8763b73463SBrian Somers /* XXX-ML - must be moved into the physical struct */ 8863b73463SBrian Somers const char *Physical_GetDevice(struct physical *phys) { 8963b73463SBrian Somers return VarDevice; 9063b73463SBrian Somers } 9163b73463SBrian Somers 9263b73463SBrian Somers /* XXX-ML - must be moved into the physical struct */ 9363b73463SBrian Somers void 9463b73463SBrian Somers Physical_SetDevice(struct physical *phys, const char *new_device_list) { 9563b73463SBrian Somers strncpy(VarDeviceList, new_device_list, sizeof VarDeviceList - 1); 9663b73463SBrian Somers VarDeviceList[sizeof VarDeviceList - 1] = '\0'; 9763b73463SBrian Somers } 9863b73463SBrian Somers 9963b73463SBrian Somers 10063b73463SBrian Somers int 10163b73463SBrian Somers Physical_SetSpeed(struct physical *phys, int speed) { 10263b73463SBrian Somers if (IntToSpeed(speed) != B0) { 10363b73463SBrian Somers phys->speed = speed; 10463b73463SBrian Somers return 1; 10563b73463SBrian Somers } else { 10663b73463SBrian Somers return 0; 10763b73463SBrian Somers } 10863b73463SBrian Somers } 10963b73463SBrian Somers 11063b73463SBrian Somers void 11163b73463SBrian Somers Physical_SetSync(struct physical *phys) { 11263b73463SBrian Somers phys->speed = 0; 11363b73463SBrian Somers } 11463b73463SBrian Somers 11563b73463SBrian Somers 11663b73463SBrian Somers int 11763b73463SBrian Somers Physical_SetRtsCts(struct physical *phys, int enable) { 11863b73463SBrian Somers assert(enable == 0 || enable == 1); 11963b73463SBrian Somers 12063b73463SBrian Somers phys->rts_cts = enable; 12163b73463SBrian Somers return 1; 12263b73463SBrian Somers } 12363b73463SBrian Somers 12463b73463SBrian Somers void 12563b73463SBrian Somers Physical_SetDedicated(struct physical *phys, int enable) { 12663b73463SBrian Somers assert(enable == 0 || enable == 1); 12763b73463SBrian Somers 12863b73463SBrian Somers phys->is_dedicated = enable; 12963b73463SBrian Somers } 13063b73463SBrian Somers 13163b73463SBrian Somers void 13263b73463SBrian Somers Physical_SetDirect(struct physical *phys, int enable) { 13363b73463SBrian Somers assert(enable == 0 || enable == 1); 13463b73463SBrian Somers 13563b73463SBrian Somers phys->is_direct = enable; 13663b73463SBrian Somers } 13763b73463SBrian Somers 13863b73463SBrian Somers int 13963b73463SBrian Somers Physical_IsDirect(struct physical *phys) { 14063b73463SBrian Somers return phys->is_direct; 14163b73463SBrian Somers } 14263b73463SBrian Somers 14363b73463SBrian Somers int 14463b73463SBrian Somers Physical_IsDedicated(struct physical *phys) { 14563b73463SBrian Somers return phys->is_dedicated; 14663b73463SBrian Somers } 14763b73463SBrian Somers 14863b73463SBrian Somers 14963b73463SBrian Somers void 15063b73463SBrian Somers Physical_DupAndClose(struct physical *phys) { 15163b73463SBrian Somers int nmodem; 15263b73463SBrian Somers 15363b73463SBrian Somers nmodem = dup(phys->fd); 15463b73463SBrian Somers close(phys->fd); 15563b73463SBrian Somers phys->fd = nmodem; 15663b73463SBrian Somers } 15763b73463SBrian Somers 15863b73463SBrian Somers /* Encapsulation for a read on the FD. Avoids some exposure, and 15963b73463SBrian Somers concentrates control. */ 16063b73463SBrian Somers ssize_t 16163b73463SBrian Somers Physical_Read(struct physical *phys, void *buf, size_t nbytes) { 16263b73463SBrian Somers return read(phys->fd, buf, nbytes); 16363b73463SBrian Somers } 16463b73463SBrian Somers 16563b73463SBrian Somers ssize_t 16663b73463SBrian Somers Physical_Write(struct physical *phys, const void *buf, size_t nbytes) { 16763b73463SBrian Somers return write(phys->fd, buf, nbytes); 16863b73463SBrian Somers } 169ecd5172aSBrian Somers 170ecd5172aSBrian Somers int 171ecd5172aSBrian Somers Physical_ReportProtocolStatus(struct cmdargs const *arg) 172ecd5172aSBrian Somers { 173ecd5172aSBrian Somers link_ReportProtocolStatus(&pppVars.physical->link); 174ecd5172aSBrian Somers return 0; 175ecd5172aSBrian Somers } 176