1 /* 2 * Written by Eivind Eklund <eivind (at) yes.no> 3 * for Yes Interactive 4 * 5 * Copyright (C) 1998, Yes Interactive. All rights reserved. 6 * 7 * Redistribution and use in any form is permitted. Redistribution in 8 * source form should include the above copyright and this set of 9 * conditions, because large sections american law seems to have been 10 * created by a bunch of jerks on drugs that are now illegal, forcing 11 * me to include this copyright-stuff instead of placing this in the 12 * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund' 13 * may not be used to endorse or promote products derived from this 14 * software without specific prior written permission. 15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 18 * 19 * $FreeBSD: src/usr.sbin/ppp/physical.h,v 1.28.24.1 2010/12/21 17:10:29 kensmith Exp $ 20 * 21 */ 22 23 struct datalink; 24 struct bundle; 25 struct iovec; 26 struct physical; 27 struct bundle; 28 struct ccp; 29 struct cmdargs; 30 31 /* Device types (don't use zero, it'll be confused with NULL in physical2iov */ 32 #define I4B_DEVICE 1 33 #define TTY_DEVICE 2 34 #define TCP_DEVICE 3 35 #define UDP_DEVICE 4 36 #define ETHER_DEVICE 5 37 #define EXEC_DEVICE 6 38 #define ATM_DEVICE 7 39 #define NG_DEVICE 8 40 41 /* Returns from awaitcarrier() */ 42 #define CARRIER_PENDING 1 43 #define CARRIER_OK 2 44 #define CARRIER_LOST 3 45 46 /* A cd ``necessity'' value */ 47 #define CD_VARIABLE 0 48 #define CD_REQUIRED 1 49 #define CD_NOTREQUIRED 2 50 #define CD_DEFAULT 3 51 52 struct cd { 53 unsigned necessity : 2; /* A CD_ value */ 54 int delay; /* Wait this many seconds after login script */ 55 }; 56 57 struct device { 58 int type; 59 const char *name; 60 u_short mtu; 61 struct cd cd; 62 63 int (*awaitcarrier)(struct physical *); 64 int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *); 65 int (*raw)(struct physical *); 66 void (*offline)(struct physical *); 67 void (*cooked)(struct physical *); 68 void (*setasyncparams)(struct physical *, u_int32_t, u_int32_t); 69 void (*stoptimer)(struct physical *); 70 void (*destroy)(struct physical *); 71 ssize_t (*read)(struct physical *, void *, size_t); 72 ssize_t (*write)(struct physical *, const void *, size_t); 73 void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *); 74 unsigned (*speed)(struct physical *); 75 const char *(*openinfo)(struct physical *); 76 int (*slot)(struct physical *); 77 }; 78 79 struct physical { 80 struct link link; 81 struct fdescriptor desc; 82 int type; /* What sort of PHYS_* link are we ? */ 83 struct async async; /* Our async state */ 84 struct hdlc hdlc; /* Our hdlc state */ 85 int fd; /* File descriptor for this device */ 86 struct mbuf *out; /* mbuf that suffered a short write */ 87 int connect_count; 88 struct datalink *dl; /* my owner */ 89 90 struct { 91 u_char buf[MAX_MRU]; /* Our input data buffer */ 92 size_t sz; 93 } input; 94 95 struct { 96 char full[DEVICE_LEN]; /* Our current device name */ 97 char *base; 98 } name; 99 100 time_t Utmp; /* Are we in utmp ? */ 101 pid_t session_owner; /* HUP this when closing the link */ 102 103 struct device *handler; /* device specific handler */ 104 105 struct { 106 unsigned rts_cts : 1; /* Is rts/cts enabled ? */ 107 unsigned nonstandard_pppoe : 1; /* Is PPPoE mode nonstandard */ 108 unsigned pppoe_configured : 1; /* temporary hack */ 109 unsigned parity; /* What parity is enabled? (tty flags) */ 110 unsigned speed; /* tty speed */ 111 112 char devlist[LINE_LEN]; /* NUL separated list of devices */ 113 int ndev; /* number of devices in list */ 114 struct cd cd; 115 } cfg; 116 }; 117 118 #define field2phys(fp, name) \ 119 ((struct physical *)((char *)fp - (int)(&((struct physical *)0)->name))) 120 121 #define link2physical(l) \ 122 ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) 123 124 #define descriptor2physical(d) \ 125 ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) 126 127 #define PHYSICAL_NOFORCE 1 128 #define PHYSICAL_FORCE_ASYNC 2 129 #define PHYSICAL_FORCE_SYNC 3 130 #define PHYSICAL_FORCE_SYNCNOACF 4 131 132 extern struct physical *physical_Create(struct datalink *, int); 133 extern int physical_Open(struct physical *); 134 extern int physical_Raw(struct physical *); 135 extern unsigned physical_GetSpeed(struct physical *); 136 extern int physical_SetSpeed(struct physical *, unsigned); 137 extern int physical_SetParity(struct physical *, const char *); 138 extern int physical_SetRtsCts(struct physical *, int); 139 extern void physical_SetSync(struct physical *); 140 extern int physical_ShowStatus(struct cmdargs const *); 141 extern void physical_Offline(struct physical *); 142 extern void physical_Close(struct physical *); 143 extern void physical_Destroy(struct physical *); 144 extern struct physical *iov2physical(struct datalink *, struct iovec *, int *, 145 int, int, int *, int *); 146 extern int physical2iov(struct physical *, struct iovec *, int *, int, int *, 147 int *); 148 extern const char *physical_LockedDevice(struct physical *); 149 extern void physical_ChangedPid(struct physical *, pid_t); 150 151 extern int physical_IsSync(struct physical *); 152 extern u_short physical_DeviceMTU(struct physical *); 153 extern const char *physical_GetDevice(struct physical *); 154 extern void physical_SetDeviceList(struct physical *, int, const char *const *); 155 extern void physical_SetDevice(struct physical *, const char *); 156 157 extern ssize_t physical_Read(struct physical *, void *, size_t); 158 extern ssize_t physical_Write(struct physical *, const void *, size_t); 159 extern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *, 160 fd_set *, int *, int); 161 extern int physical_IsSet(struct fdescriptor *, const fd_set *); 162 extern void physical_DescriptorRead(struct fdescriptor *, struct bundle *, 163 const fd_set *); 164 extern void physical_Login(struct physical *, const char *); 165 extern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *, 166 fd_set *); 167 extern int physical_SetMode(struct physical *, int); 168 extern void physical_DeleteQueue(struct physical *); 169 extern void physical_SetupStack(struct physical *, const char *, int); 170 extern void physical_StopDeviceTimer(struct physical *); 171 extern unsigned physical_MaxDeviceSize(void); 172 extern int physical_AwaitCarrier(struct physical *); 173 extern void physical_SetDescriptor(struct physical *); 174 extern void physical_SetAsyncParams(struct physical *, u_int32_t, u_int32_t); 175 extern int physical_Slot(struct physical *); 176 extern int physical_SetPPPoEnonstandard(struct physical *, int); 177