11558Srgrimes/* 293492Sphk * Written by Eivind Eklund <eivind@yes.no> 393492Sphk * for Yes Interactive 493492Sphk * 51558Srgrimes * Copyright (C) 1998, Yes Interactive. All rights reserved. 693492Sphk * 793492Sphk * Redistribution and use in any form is permitted. Redistribution in 893492Sphk * source form should include the above copyright and this set of 993492Sphk * conditions, because large sections american law seems to have been 1093492Sphk * created by a bunch of jerks on drugs that are now illegal, forcing 111558Srgrimes * me to include this copyright-stuff instead of placing this in the 121558Srgrimes * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund' 131558Srgrimes * may not be used to endorse or promote products derived from this 141558Srgrimes * software without specific prior written permission. 151558Srgrimes * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 161558Srgrimes * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 171558Srgrimes * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 181558Srgrimes * 1993492Sphk */ 2093492Sphk 2193492Sphkstruct datalink; 221558Srgrimesstruct bundle; 2393492Sphkstruct iovec; 241558Srgrimesstruct physical; 251558Srgrimesstruct bundle; 2693492Sphkstruct ccp; 271558Srgrimesstruct cmdargs; 281558Srgrimes 291558Srgrimes/* Device types (don't use zero, it'll be confused with NULL in physical2iov */ 301558Srgrimes#define I4B_DEVICE 1 311558Srgrimes#define TTY_DEVICE 2 321558Srgrimes#define TCP_DEVICE 3 331558Srgrimes#define UDP_DEVICE 4 3496049Sfenner#define ETHER_DEVICE 5 3596049Sfenner#define EXEC_DEVICE 6 3696049Sfenner#define ATM_DEVICE 7 3796049Sfenner#define NG_DEVICE 8 3896049Sfenner 3996049Sfenner/* Returns from awaitcarrier() */ 4096049Sfenner#define CARRIER_PENDING 1 4196049Sfenner#define CARRIER_OK 2 4296049Sfenner#define CARRIER_LOST 3 4396049Sfenner 4496049Sfenner/* A cd ``necessity'' value */ 4596049Sfenner#define CD_VARIABLE 0 4696049Sfenner#define CD_REQUIRED 1 4796049Sfenner#define CD_NOTREQUIRED 2 4896049Sfenner#define CD_DEFAULT 3 4996049Sfenner 5096049Sfennerstruct cd { 5196049Sfenner unsigned necessity : 2; /* A CD_ value */ 5296049Sfenner int delay; /* Wait this many seconds after login script */ 5396049Sfenner}; 5496049Sfenner 5596049Sfennerstruct device { 5696049Sfenner int type; 5796049Sfenner const char *name; 5896049Sfenner u_short mtu; 5996049Sfenner struct cd cd; 6096049Sfenner 611558Srgrimes int (*awaitcarrier)(struct physical *); 621558Srgrimes int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *); 6395183Scharnier int (*raw)(struct physical *); 6495183Scharnier void (*offline)(struct physical *); 6595183Scharnier void (*cooked)(struct physical *); 6696049Sfenner void (*setasyncparams)(struct physical *, u_int32_t, u_int32_t); 6794580Smarcel void (*stoptimer)(struct physical *); 6894580Smarcel void (*destroy)(struct physical *); 6996025Smux ssize_t (*read)(struct physical *, void *, size_t); 7094580Smarcel ssize_t (*write)(struct physical *, const void *, size_t); 7194580Smarcel void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *); 7293492Sphk unsigned (*speed)(struct physical *); 7393492Sphk const char *(*openinfo)(struct physical *); 7496025Smux int (*slot)(struct physical *); 75234069Srmh}; 7696049Sfenner 7794580Smarcelstruct physical { 7894580Smarcel struct link link; 7994580Smarcel struct fdescriptor desc; 8096049Sfenner int type; /* What sort of PHYS_* link are we ? */ 8193492Sphk struct async async; /* Our async state */ 8293492Sphk struct hdlc hdlc; /* Our hdlc state */ 831558Srgrimes int fd; /* File descriptor for this device */ 8497746Smarcel struct mbuf *out; /* mbuf that suffered a short write */ 8597746Smarcel int connect_count; 8697746Smarcel struct datalink *dl; /* my owner */ 87142533Sobrien 88142533Sobrien struct { 89142533Sobrien u_char buf[MAX_MRU]; /* Our input data buffer */ 90142359Sobrien size_t sz; 91133814Sru } input; 92133814Sru 93244320Spjd struct { 9494580Smarcel char full[DEVICE_LEN]; /* Our current device name */ 9596049Sfenner char *base; 9696049Sfenner } name; 97196528Slulf 98196528Slulf int Utmp; /* Are we in utmp ? */ 99196528Slulf pid_t session_owner; /* HUP this when closing the link */ 10093492Sphk 10194580Smarcel struct device *handler; /* device specific handler */ 102142359Sobrien 1031558Srgrimes struct { 10493717Smarcel unsigned rts_cts : 1; /* Is rts/cts enabled ? */ 10593492Sphk unsigned nonstandard_pppoe : 1; /* Is PPPoE mode nonstandard */ 106142359Sobrien unsigned pppoe_configured : 1; /* temporary hack */ 1071558Srgrimes unsigned parity; /* What parity is enabled? (tty flags) */ 108142359Sobrien unsigned speed; /* tty speed */ 10993492Sphk 110150818Smaxim char devlist[LINE_LEN]; /* NUL separated list of devices */ 111150818Smaxim int ndev; /* number of devices in list */ 11293717Smarcel struct cd cd; 113142359Sobrien } cfg; 11493717Smarcel}; 11593717Smarcel 11693717Smarcel#define field2phys(fp, name) \ 11793492Sphk ((struct physical *)((char *)fp - (uintptr_t)(&((struct physical *)0)->name))) 11893492Sphk 119142359Sobrien#define link2physical(l) \ 120142359Sobrien ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) 121142359Sobrien 122142359Sobrien#define descriptor2physical(d) \ 12396049Sfenner ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) 124142359Sobrien 125142359Sobrien#define PHYSICAL_NOFORCE 1 126142359Sobrien#define PHYSICAL_FORCE_ASYNC 2 127142533Sobrien#define PHYSICAL_FORCE_SYNC 3 128142533Sobrien#define PHYSICAL_FORCE_SYNCNOACF 4 129142359Sobrien 130142533Sobrienextern struct physical *physical_Create(struct datalink *, int); 131142533Sobrienextern int physical_Open(struct physical *); 132142359Sobrienextern int physical_Raw(struct physical *); 133142533Sobrienextern unsigned physical_GetSpeed(struct physical *); 134142359Sobrienextern int physical_SetSpeed(struct physical *, unsigned); 135142359Sobrienextern int physical_SetParity(struct physical *, const char *); 13695039Sphkextern int physical_SetRtsCts(struct physical *, int); 1371558Srgrimesextern void physical_SetSync(struct physical *); 1381558Srgrimesextern int physical_ShowStatus(struct cmdargs const *); 13996049Sfennerextern void physical_Offline(struct physical *); 14096049Sfennerextern void physical_Close(struct physical *); 14196049Sfennerextern void physical_Destroy(struct physical *); 14296049Sfennerextern struct physical *iov2physical(struct datalink *, struct iovec *, int *, 14396049Sfenner int, int, int *, int *); 14496049Sfennerextern int physical2iov(struct physical *, struct iovec *, int *, int, int *, 14596049Sfenner int *); 14696049Sfennerextern const char *physical_LockedDevice(struct physical *); 14796049Sfennerextern void physical_ChangedPid(struct physical *, pid_t); 148150105Srwatson 149150105Srwatsonextern int physical_IsSync(struct physical *); 150147506Sdwhiteextern u_short physical_DeviceMTU(struct physical *); 15196049Sfennerextern const char *physical_GetDevice(struct physical *); 15296049Sfennerextern void physical_SetDeviceList(struct physical *, int, const char *const *); 15396049Sfennerextern void physical_SetDevice(struct physical *, const char *); 154272434Sbdrewery 155272434Sbdreweryextern ssize_t physical_Read(struct physical *, void *, size_t); 156272434Sbdreweryextern ssize_t physical_Write(struct physical *, const void *, size_t); 157272434Sbdreweryextern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *, 15896049Sfenner fd_set *, int *, int); 159147506Sdwhiteextern int physical_IsSet(struct fdescriptor *, const fd_set *); 16096049Sfennerextern void physical_DescriptorRead(struct fdescriptor *, struct bundle *, 16196049Sfenner const fd_set *); 16296049Sfennerextern void physical_Login(struct physical *, const char *); 16396049Sfennerextern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *, 16496049Sfenner fd_set *); 16596049Sfennerextern int physical_SetMode(struct physical *, int); 166272434Sbdreweryextern void physical_DeleteQueue(struct physical *); 167147506Sdwhiteextern void physical_SetupStack(struct physical *, const char *, int); 168147506Sdwhiteextern void physical_StopDeviceTimer(struct physical *); 16996049Sfennerextern unsigned physical_MaxDeviceSize(void); 170147506Sdwhiteextern int physical_AwaitCarrier(struct physical *); 171147506Sdwhiteextern void physical_SetDescriptor(struct physical *); 172147506Sdwhiteextern void physical_SetAsyncParams(struct physical *, u_int32_t, u_int32_t); 17396049Sfennerextern int physical_Slot(struct physical *); 17496049Sfennerextern int physical_SetPPPoEnonstandard(struct physical *, int); 17596049Sfenner