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