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 * 1963b73463SBrian Somers */ 2063b73463SBrian Somers 215d9e6103SBrian Somers struct datalink; 222764b86aSBrian Somers struct bundle; 235d9e6103SBrian Somers struct iovec; 245d9e6103SBrian Somers struct physical; 255d9e6103SBrian Somers struct bundle; 265d9e6103SBrian Somers struct ccp; 275d9e6103SBrian Somers struct cmdargs; 285d9e6103SBrian Somers 292cb305afSBrian Somers /* Device types (don't use zero, it'll be confused with NULL in physical2iov */ 30eb6e5e05SBrian Somers #define I4B_DEVICE 1 31eb6e5e05SBrian Somers #define TTY_DEVICE 2 32eb6e5e05SBrian Somers #define TCP_DEVICE 3 33eb6e5e05SBrian Somers #define UDP_DEVICE 4 3487c3786eSBrian Somers #define ETHER_DEVICE 5 3587c3786eSBrian Somers #define EXEC_DEVICE 6 36481a4f61SBrian Somers #define ATM_DEVICE 7 37fb11a9c2SBrian Somers #define NG_DEVICE 8 38eb6e5e05SBrian Somers 39eb6e5e05SBrian Somers /* Returns from awaitcarrier() */ 40eb6e5e05SBrian Somers #define CARRIER_PENDING 1 41eb6e5e05SBrian Somers #define CARRIER_OK 2 42eb6e5e05SBrian Somers #define CARRIER_LOST 3 435d9e6103SBrian Somers 44ccd587f0SBrian Somers /* A cd ``necessity'' value */ 45fdc29d54SBrian Somers #define CD_VARIABLE 0 46fdc29d54SBrian Somers #define CD_REQUIRED 1 47fdc29d54SBrian Somers #define CD_NOTREQUIRED 2 48fdc29d54SBrian Somers #define CD_DEFAULT 3 49fdc29d54SBrian Somers 50fdc29d54SBrian Somers struct cd { 51fdc29d54SBrian Somers unsigned necessity : 2; /* A CD_ value */ 52fdc29d54SBrian Somers int delay; /* Wait this many seconds after login script */ 53fdc29d54SBrian Somers }; 54ccd587f0SBrian Somers 555d9e6103SBrian Somers struct device { 565d9e6103SBrian Somers int type; 575d9e6103SBrian Somers const char *name; 58c8b9fb53SBrian Somers u_short mtu; 59fdc29d54SBrian Somers struct cd cd; 606815097bSBrian Somers 61eb6e5e05SBrian Somers int (*awaitcarrier)(struct physical *); 6287c3786eSBrian Somers int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *); 635d9e6103SBrian Somers int (*raw)(struct physical *); 645d9e6103SBrian Somers void (*offline)(struct physical *); 655d9e6103SBrian Somers void (*cooked)(struct physical *); 66fb11a9c2SBrian Somers void (*setasyncparams)(struct physical *, u_int32_t, u_int32_t); 676815097bSBrian Somers void (*stoptimer)(struct physical *); 686815097bSBrian Somers void (*destroy)(struct physical *); 696815097bSBrian Somers ssize_t (*read)(struct physical *, void *, size_t); 706815097bSBrian Somers ssize_t (*write)(struct physical *, const void *, size_t); 712cb305afSBrian Somers void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *); 72057f1760SBrian Somers unsigned (*speed)(struct physical *); 735d9e6103SBrian Somers const char *(*openinfo)(struct physical *); 74de59e178SBrian Somers int (*slot)(struct physical *); 755d9e6103SBrian Somers }; 762764b86aSBrian Somers 7763b73463SBrian Somers struct physical { 788c07a7b2SBrian Somers struct link link; 79f013f33eSBrian Somers struct fdescriptor desc; 80dd7e2610SBrian Somers int type; /* What sort of PHYS_* link are we ? */ 816140ba11SBrian Somers struct async async; /* Our async state */ 8263258dccSBrian Somers struct hdlc hdlc; /* Our hdlc state */ 838e7bd08eSBrian Somers int fd; /* File descriptor for this device */ 84fc1141b2SBrian Somers struct mbuf *out; /* mbuf that suffered a short write */ 8563b73463SBrian Somers int connect_count; 86dc0fdb6bSBrian Somers struct datalink *dl; /* my owner */ 8763b73463SBrian Somers 883bf710a4SBrian Somers struct { 89e3044845SBrian Somers u_char buf[MAX_MRU]; /* Our input data buffer */ 90e3044845SBrian Somers size_t sz; 91e3044845SBrian Somers } input; 92e3044845SBrian Somers 93e3044845SBrian Somers struct { 94e6923505SBrian Somers char full[DEVICE_LEN]; /* Our current device name */ 953bf710a4SBrian Somers char *base; 963bf710a4SBrian Somers } name; 973bf710a4SBrian Somers 98adc17f0aSEd Schouten int Utmp; /* Are we in utmp ? */ 998e7b8599SBrian Somers pid_t session_owner; /* HUP this when closing the link */ 100fc1141b2SBrian Somers 1016815097bSBrian Somers struct device *handler; /* device specific handler */ 1026815097bSBrian Somers 103d585f8f5SBrian Somers struct { 10463b73463SBrian Somers unsigned rts_cts : 1; /* Is rts/cts enabled ? */ 105b5bc6d4dSGleb Smirnoff unsigned nonstandard_pppoe : 1; /* Is PPPoE mode nonstandard */ 106b5bc6d4dSGleb Smirnoff unsigned pppoe_configured : 1; /* temporary hack */ 1075d9e6103SBrian Somers unsigned parity; /* What parity is enabled? (tty flags) */ 1085d9e6103SBrian Somers unsigned speed; /* tty speed */ 1095d9e6103SBrian Somers 110a8d7acdcSBrian Somers char devlist[LINE_LEN]; /* NUL separated list of devices */ 111a8d7acdcSBrian Somers int ndev; /* number of devices in list */ 112fdc29d54SBrian Somers struct cd cd; 113d585f8f5SBrian Somers } cfg; 11463b73463SBrian Somers }; 11563b73463SBrian Somers 11642d4d396SBrian Somers #define field2phys(fp, name) \ 11716e790daSJohn Birrell ((struct physical *)((char *)fp - (uintptr_t)(&((struct physical *)0)->name))) 11842d4d396SBrian Somers 11942d4d396SBrian Somers #define link2physical(l) \ 12042d4d396SBrian Somers ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) 12142d4d396SBrian Somers 12242d4d396SBrian Somers #define descriptor2physical(d) \ 12342d4d396SBrian Somers ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) 1248c07a7b2SBrian Somers 1256815097bSBrian Somers #define PHYSICAL_NOFORCE 1 1266815097bSBrian Somers #define PHYSICAL_FORCE_ASYNC 2 1276815097bSBrian Somers #define PHYSICAL_FORCE_SYNC 3 12887c3786eSBrian Somers #define PHYSICAL_FORCE_SYNCNOACF 4 1296815097bSBrian Somers 1305d9e6103SBrian Somers extern struct physical *physical_Create(struct datalink *, int); 131057f1760SBrian Somers extern int physical_Open(struct physical *); 1325d9e6103SBrian Somers extern int physical_Raw(struct physical *); 133057f1760SBrian Somers extern unsigned physical_GetSpeed(struct physical *); 134057f1760SBrian Somers extern int physical_SetSpeed(struct physical *, unsigned); 1355d9e6103SBrian Somers extern int physical_SetParity(struct physical *, const char *); 1365d9e6103SBrian Somers extern int physical_SetRtsCts(struct physical *, int); 1375d9e6103SBrian Somers extern void physical_SetSync(struct physical *); 1385d9e6103SBrian Somers extern int physical_ShowStatus(struct cmdargs const *); 1395d9e6103SBrian Somers extern void physical_Offline(struct physical *); 1405d9e6103SBrian Somers extern void physical_Close(struct physical *); 1415d9e6103SBrian Somers extern void physical_Destroy(struct physical *); 1425d9e6103SBrian Somers extern struct physical *iov2physical(struct datalink *, struct iovec *, int *, 14387c3786eSBrian Somers int, int, int *, int *); 14487c3786eSBrian Somers extern int physical2iov(struct physical *, struct iovec *, int *, int, int *, 1452cb305afSBrian Somers int *); 1462cb305afSBrian Somers extern const char *physical_LockedDevice(struct physical *); 1475d9e6103SBrian Somers extern void physical_ChangedPid(struct physical *, pid_t); 1485d9e6103SBrian Somers 149dd7e2610SBrian Somers extern int physical_IsSync(struct physical *); 150c8b9fb53SBrian Somers extern u_short physical_DeviceMTU(struct physical *); 151dd7e2610SBrian Somers extern const char *physical_GetDevice(struct physical *); 152dd7e2610SBrian Somers extern void physical_SetDeviceList(struct physical *, int, const char *const *); 1535d9e6103SBrian Somers extern void physical_SetDevice(struct physical *, const char *); 15463b73463SBrian Somers 155dd7e2610SBrian Somers extern ssize_t physical_Read(struct physical *, void *, size_t); 156dd7e2610SBrian Somers extern ssize_t physical_Write(struct physical *, const void *, size_t); 157f013f33eSBrian Somers extern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *, 158dd7e2610SBrian Somers fd_set *, int *, int); 159f013f33eSBrian Somers extern int physical_IsSet(struct fdescriptor *, const fd_set *); 160f013f33eSBrian Somers extern void physical_DescriptorRead(struct fdescriptor *, struct bundle *, 16187c3786eSBrian Somers const fd_set *); 162dd7e2610SBrian Somers extern void physical_Login(struct physical *, const char *); 163ea722969SBrian Somers extern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *, 164ea722969SBrian Somers fd_set *); 165dd0645c5SBrian Somers extern int physical_SetMode(struct physical *, int); 1666f8e9f0aSBrian Somers extern void physical_DeleteQueue(struct physical *); 167acbd1f00SBrian Somers extern void physical_SetupStack(struct physical *, const char *, int); 1686815097bSBrian Somers extern void physical_StopDeviceTimer(struct physical *); 169057f1760SBrian Somers extern unsigned physical_MaxDeviceSize(void); 170eb6e5e05SBrian Somers extern int physical_AwaitCarrier(struct physical *); 17187c3786eSBrian Somers extern void physical_SetDescriptor(struct physical *); 172fb11a9c2SBrian Somers extern void physical_SetAsyncParams(struct physical *, u_int32_t, u_int32_t); 173de59e178SBrian Somers extern int physical_Slot(struct physical *); 174057f1760SBrian Somers extern int physical_SetPPPoEnonstandard(struct physical *, int); 175