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