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