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