136285Sbrian/* 236285Sbrian * Written by Eivind Eklund <eivind@yes.no> 336285Sbrian * for Yes Interactive 436285Sbrian * 536285Sbrian * Copyright (C) 1998, Yes Interactive. All rights reserved. 636285Sbrian * 736285Sbrian * Redistribution and use in any form is permitted. Redistribution in 836285Sbrian * source form should include the above copyright and this set of 936285Sbrian * conditions, because large sections american law seems to have been 1036285Sbrian * created by a bunch of jerks on drugs that are now illegal, forcing 1136285Sbrian * me to include this copyright-stuff instead of placing this in the 1236285Sbrian * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund' 1336285Sbrian * may not be used to endorse or promote products derived from this 1436285Sbrian * software without specific prior written permission. 1536285Sbrian * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1636285Sbrian * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1736285Sbrian * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1836285Sbrian * 1950479Speter * $FreeBSD$ 2036285Sbrian * 2136285Sbrian */ 2236285Sbrian 2346686Sbrianstruct datalink; 2436285Sbrianstruct bundle; 2546686Sbrianstruct iovec; 2646686Sbrianstruct physical; 2746686Sbrianstruct bundle; 2846686Sbrianstruct ccp; 2946686Sbrianstruct cmdargs; 3036285Sbrian 3153684Sbrian/* Device types (don't use zero, it'll be confused with NULL in physical2iov */ 3249472Sbrian#define I4B_DEVICE 1 3349472Sbrian#define TTY_DEVICE 2 3449472Sbrian#define TCP_DEVICE 3 3549472Sbrian#define UDP_DEVICE 4 3652942Sbrian#define ETHER_DEVICE 5 3752942Sbrian#define EXEC_DEVICE 6 3865862Sbrian#define ATM_DEVICE 7 3993418Sbrian#define NG_DEVICE 8 4046686Sbrian 4149472Sbrian/* Returns from awaitcarrier() */ 4249472Sbrian#define CARRIER_PENDING 1 4349472Sbrian#define CARRIER_OK 2 4449472Sbrian#define CARRIER_LOST 3 4549472Sbrian 4651699Sbrian/* A cd ``necessity'' value */ 4753733Sbrian#define CD_VARIABLE 0 4853733Sbrian#define CD_REQUIRED 1 4953733Sbrian#define CD_NOTREQUIRED 2 5053733Sbrian#define CD_DEFAULT 3 5151699Sbrian 5253733Sbrianstruct cd { 5353733Sbrian unsigned necessity : 2; /* A CD_ value */ 5453733Sbrian int delay; /* Wait this many seconds after login script */ 5553733Sbrian}; 5653733Sbrian 5746686Sbrianstruct device { 5846686Sbrian int type; 5946686Sbrian const char *name; 6078410Sbrian u_short mtu; 6153733Sbrian struct cd cd; 6247061Sbrian 6349472Sbrian int (*awaitcarrier)(struct physical *); 6452942Sbrian int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *); 6546686Sbrian int (*raw)(struct physical *); 6646686Sbrian void (*offline)(struct physical *); 6746686Sbrian void (*cooked)(struct physical *); 6893418Sbrian void (*setasyncparams)(struct physical *, u_int32_t, u_int32_t); 6947061Sbrian void (*stoptimer)(struct physical *); 7047061Sbrian void (*destroy)(struct physical *); 7147061Sbrian ssize_t (*read)(struct physical *, void *, size_t); 7247061Sbrian ssize_t (*write)(struct physical *, const void *, size_t); 7353684Sbrian void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *); 74134789Sbrian unsigned (*speed)(struct physical *); 7546686Sbrian const char *(*openinfo)(struct physical *); 7696582Sbrian int (*slot)(struct physical *); 7746686Sbrian}; 7846686Sbrian 7936285Sbrianstruct physical { 8036285Sbrian struct link link; 8158028Sbrian struct fdescriptor desc; 8236285Sbrian int type; /* What sort of PHYS_* link are we ? */ 8336285Sbrian struct async async; /* Our async state */ 8436285Sbrian struct hdlc hdlc; /* Our hdlc state */ 8558038Sbrian int fd; /* File descriptor for this device */ 8636285Sbrian struct mbuf *out; /* mbuf that suffered a short write */ 8736285Sbrian int connect_count; 8836285Sbrian struct datalink *dl; /* my owner */ 8936285Sbrian 9036285Sbrian struct { 9145264Sbrian u_char buf[MAX_MRU]; /* Our input data buffer */ 9245264Sbrian size_t sz; 9345264Sbrian } input; 9445264Sbrian 9545264Sbrian struct { 9647682Sbrian char full[DEVICE_LEN]; /* Our current device name */ 9736285Sbrian char *base; 9836285Sbrian } name; 9936285Sbrian 100202192Sed int Utmp; /* Are we in utmp ? */ 10136467Sbrian pid_t session_owner; /* HUP this when closing the link */ 10236285Sbrian 10347061Sbrian struct device *handler; /* device specific handler */ 10447061Sbrian 10546686Sbrian struct { 10646686Sbrian unsigned rts_cts : 1; /* Is rts/cts enabled ? */ 107132818Sglebius unsigned nonstandard_pppoe : 1; /* Is PPPoE mode nonstandard */ 108132818Sglebius unsigned pppoe_configured : 1; /* temporary hack */ 10946686Sbrian unsigned parity; /* What parity is enabled? (tty flags) */ 11046686Sbrian unsigned speed; /* tty speed */ 11136285Sbrian 11246102Sbrian char devlist[LINE_LEN]; /* NUL separated list of devices */ 11346102Sbrian int ndev; /* number of devices in list */ 11453733Sbrian struct cd cd; 11536285Sbrian } cfg; 11636285Sbrian}; 11736285Sbrian 11836285Sbrian#define field2phys(fp, name) \ 119173710Sjb ((struct physical *)((char *)fp - (uintptr_t)(&((struct physical *)0)->name))) 12036285Sbrian 12136285Sbrian#define link2physical(l) \ 12236285Sbrian ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) 12336285Sbrian 12436285Sbrian#define descriptor2physical(d) \ 12536285Sbrian ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) 12636285Sbrian 12752942Sbrian#define PHYSICAL_NOFORCE 1 12852942Sbrian#define PHYSICAL_FORCE_ASYNC 2 12952942Sbrian#define PHYSICAL_FORCE_SYNC 3 13052942Sbrian#define PHYSICAL_FORCE_SYNCNOACF 4 13147061Sbrian 13246686Sbrianextern struct physical *physical_Create(struct datalink *, int); 133134789Sbrianextern int physical_Open(struct physical *); 13446686Sbrianextern int physical_Raw(struct physical *); 135134789Sbrianextern unsigned physical_GetSpeed(struct physical *); 136134789Sbrianextern int physical_SetSpeed(struct physical *, unsigned); 13746686Sbrianextern int physical_SetParity(struct physical *, const char *); 13846686Sbrianextern int physical_SetRtsCts(struct physical *, int); 13946686Sbrianextern void physical_SetSync(struct physical *); 14046686Sbrianextern int physical_ShowStatus(struct cmdargs const *); 14146686Sbrianextern void physical_Offline(struct physical *); 14246686Sbrianextern void physical_Close(struct physical *); 14346686Sbrianextern void physical_Destroy(struct physical *); 14446686Sbrianextern struct physical *iov2physical(struct datalink *, struct iovec *, int *, 14552942Sbrian int, int, int *, int *); 14652942Sbrianextern int physical2iov(struct physical *, struct iovec *, int *, int, int *, 14753684Sbrian int *); 14853684Sbrianextern const char *physical_LockedDevice(struct physical *); 14946686Sbrianextern void physical_ChangedPid(struct physical *, pid_t); 15046686Sbrian 15136285Sbrianextern int physical_IsSync(struct physical *); 15278410Sbrianextern u_short physical_DeviceMTU(struct physical *); 15336285Sbrianextern const char *physical_GetDevice(struct physical *); 15436285Sbrianextern void physical_SetDeviceList(struct physical *, int, const char *const *); 15546686Sbrianextern void physical_SetDevice(struct physical *, const char *); 15636285Sbrian 15736285Sbrianextern ssize_t physical_Read(struct physical *, void *, size_t); 15836285Sbrianextern ssize_t physical_Write(struct physical *, const void *, size_t); 15958028Sbrianextern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *, 16046686Sbrian fd_set *, int *, int); 16158028Sbrianextern int physical_IsSet(struct fdescriptor *, const fd_set *); 16258028Sbrianextern void physical_DescriptorRead(struct fdescriptor *, struct bundle *, 16352942Sbrian const fd_set *); 16436285Sbrianextern void physical_Login(struct physical *, const char *); 16536285Sbrianextern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *, 16636285Sbrian fd_set *); 16736285Sbrianextern int physical_SetMode(struct physical *, int); 16838544Sbrianextern void physical_DeleteQueue(struct physical *); 16947461Sbrianextern void physical_SetupStack(struct physical *, const char *, int); 17047061Sbrianextern void physical_StopDeviceTimer(struct physical *); 171134789Sbrianextern unsigned physical_MaxDeviceSize(void); 17249472Sbrianextern int physical_AwaitCarrier(struct physical *); 17352942Sbrianextern void physical_SetDescriptor(struct physical *); 17493418Sbrianextern void physical_SetAsyncParams(struct physical *, u_int32_t, u_int32_t); 17596582Sbrianextern int physical_Slot(struct physical *); 176134789Sbrianextern int physical_SetPPPoEnonstandard(struct physical *, int); 177