1 /* 2 * Written by Eivind Eklund <eivind@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 * $Id: physical.h,v 1.12 1999/06/01 19:08:59 brian 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 #define TTY_DEVICE 1 32 #define TCP_DEVICE 2 33 #define UDP_DEVICE 3 34 #define EXEC_DEVICE 4 35 36 struct device { 37 int type; 38 const char *name; 39 40 int (*raw)(struct physical *); 41 void (*offline)(struct physical *); 42 void (*cooked)(struct physical *); 43 void (*stoptimer)(struct physical *); 44 void (*destroy)(struct physical *); 45 ssize_t (*read)(struct physical *, void *, size_t); 46 ssize_t (*write)(struct physical *, const void *, size_t); 47 void (*device2iov)(struct device *, struct iovec *, int *, int, pid_t); 48 int (*speed)(struct physical *); 49 const char *(*openinfo)(struct physical *); 50 }; 51 52 struct physical { 53 struct link link; 54 struct descriptor desc; 55 int type; /* What sort of PHYS_* link are we ? */ 56 struct async async; /* Our async state */ 57 struct hdlc hdlc; /* Our hdlc state */ 58 int fd; /* File descriptor for this device */ 59 struct mbuf *out; /* mbuf that suffered a short write */ 60 int connect_count; 61 struct datalink *dl; /* my owner */ 62 63 struct { 64 u_char buf[MAX_MRU]; /* Our input data buffer */ 65 size_t sz; 66 } input; 67 68 struct { 69 char full[DEVICE_LEN]; /* Our current device name */ 70 char *base; 71 } name; 72 73 unsigned Utmp : 1; /* Are we in utmp ? (move to ttydevice ?) */ 74 pid_t session_owner; /* HUP this when closing the link */ 75 76 struct device *handler; /* device specific handler */ 77 78 struct { 79 unsigned rts_cts : 1; /* Is rts/cts enabled ? */ 80 unsigned parity; /* What parity is enabled? (tty flags) */ 81 unsigned speed; /* tty speed */ 82 83 char devlist[LINE_LEN]; /* NUL separated list of devices */ 84 int ndev; /* number of devices in list */ 85 struct { 86 unsigned required : 1; /* Is cd *REQUIRED* on this device */ 87 int delay; /* Wait this many seconds after login script */ 88 } cd; 89 } cfg; 90 }; 91 92 #define field2phys(fp, name) \ 93 ((struct physical *)((char *)fp - (int)(&((struct physical *)0)->name))) 94 95 #define link2physical(l) \ 96 ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) 97 98 #define descriptor2physical(d) \ 99 ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) 100 101 #define PHYSICAL_NOFORCE 1 102 #define PHYSICAL_FORCE_ASYNC 2 103 #define PHYSICAL_FORCE_SYNC 3 104 105 extern struct physical *physical_Create(struct datalink *, int); 106 extern int physical_Open(struct physical *, struct bundle *); 107 extern int physical_Raw(struct physical *); 108 extern int physical_GetSpeed(struct physical *); 109 extern int physical_SetSpeed(struct physical *, int); 110 extern int physical_SetParity(struct physical *, const char *); 111 extern int physical_SetRtsCts(struct physical *, int); 112 extern void physical_SetSync(struct physical *); 113 extern int physical_ShowStatus(struct cmdargs const *); 114 extern void physical_Offline(struct physical *); 115 extern void physical_Close(struct physical *); 116 extern void physical_Destroy(struct physical *); 117 extern struct physical *iov2physical(struct datalink *, struct iovec *, int *, 118 int, int); 119 extern int physical2iov(struct physical *, struct iovec *, int *, int, pid_t); 120 extern void physical_ChangedPid(struct physical *, pid_t); 121 122 extern int physical_IsSync(struct physical *); 123 extern const char *physical_GetDevice(struct physical *); 124 extern void physical_SetDeviceList(struct physical *, int, const char *const *); 125 extern void physical_SetDevice(struct physical *, const char *); 126 127 extern ssize_t physical_Read(struct physical *, void *, size_t); 128 extern ssize_t physical_Write(struct physical *, const void *, size_t); 129 extern int physical_doUpdateSet(struct descriptor *, fd_set *, fd_set *, 130 fd_set *, int *, int); 131 extern int physical_IsSet(struct descriptor *, const fd_set *); 132 extern void physical_Login(struct physical *, const char *); 133 extern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *, 134 fd_set *); 135 extern int physical_SetMode(struct physical *, int); 136 extern void physical_DeleteQueue(struct physical *); 137 extern void physical_SetupStack(struct physical *, const char *, int); 138 extern void physical_StopDeviceTimer(struct physical *); 139 extern int physical_MaxDeviceSize(void); 140