physical.h revision 65862
136285Sbrian/*
236285Sbrian * Written by Eivind Eklund <eivind@yes.no>
336285Sbrian *    for Yes Interactive
436285Sbrian *
536285Sbrian * Copyright (C) 1998, Yes Interactive.  All rights reserved.
636285Sbrian *
736285Sbrian * Redistribution and use in any form is permitted.  Redistribution in
836285Sbrian * source form should include the above copyright and this set of
936285Sbrian * conditions, because large sections american law seems to have been
1036285Sbrian * created by a bunch of jerks on drugs that are now illegal, forcing
1136285Sbrian * me to include this copyright-stuff instead of placing this in the
1236285Sbrian * public domain.  The name of of 'Yes Interactive' or 'Eivind Eklund'
1336285Sbrian * may not be used to endorse or promote products derived from this
1436285Sbrian * software without specific prior written permission.
1536285Sbrian * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1636285Sbrian * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1736285Sbrian * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1836285Sbrian *
1950479Speter * $FreeBSD: head/usr.sbin/ppp/physical.h 65862 2000-09-14 22:02:54Z brian $
2036285Sbrian *
2136285Sbrian */
2236285Sbrian
2346686Sbrianstruct datalink;
2436285Sbrianstruct bundle;
2546686Sbrianstruct iovec;
2646686Sbrianstruct physical;
2746686Sbrianstruct bundle;
2846686Sbrianstruct ccp;
2946686Sbrianstruct cmdargs;
3036285Sbrian
3153684Sbrian/* Device types (don't use zero, it'll be confused with NULL in physical2iov */
3249472Sbrian#define I4B_DEVICE	1
3349472Sbrian#define TTY_DEVICE	2
3449472Sbrian#define TCP_DEVICE	3
3549472Sbrian#define UDP_DEVICE	4
3652942Sbrian#define ETHER_DEVICE	5
3752942Sbrian#define EXEC_DEVICE	6
3865862Sbrian#define ATM_DEVICE	7
3946686Sbrian
4049472Sbrian/* Returns from awaitcarrier() */
4149472Sbrian#define CARRIER_PENDING	1
4249472Sbrian#define CARRIER_OK	2
4349472Sbrian#define CARRIER_LOST	3
4449472Sbrian
4551699Sbrian/* A cd ``necessity'' value */
4653733Sbrian#define CD_VARIABLE	0
4753733Sbrian#define CD_REQUIRED	1
4853733Sbrian#define CD_NOTREQUIRED	2
4953733Sbrian#define CD_DEFAULT	3
5051699Sbrian
5153733Sbrianstruct cd {
5253733Sbrian  unsigned necessity : 2;  /* A CD_ value */
5353733Sbrian  int delay;               /* Wait this many seconds after login script */
5453733Sbrian};
5553733Sbrian
5646686Sbrianstruct device {
5746686Sbrian  int type;
5846686Sbrian  const char *name;
5953733Sbrian  struct cd cd;
6047061Sbrian
6149472Sbrian  int (*awaitcarrier)(struct physical *);
6252942Sbrian  int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *);
6346686Sbrian  int (*raw)(struct physical *);
6446686Sbrian  void (*offline)(struct physical *);
6546686Sbrian  void (*cooked)(struct physical *);
6647061Sbrian  void (*stoptimer)(struct physical *);
6747061Sbrian  void (*destroy)(struct physical *);
6847061Sbrian  ssize_t (*read)(struct physical *, void *, size_t);
6947061Sbrian  ssize_t (*write)(struct physical *, const void *, size_t);
7053684Sbrian  void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *);
7146686Sbrian  int (*speed)(struct physical *);
7246686Sbrian  const char *(*openinfo)(struct physical *);
7346686Sbrian};
7446686Sbrian
7536285Sbrianstruct physical {
7636285Sbrian  struct link link;
7758028Sbrian  struct fdescriptor desc;
7836285Sbrian  int type;                    /* What sort of PHYS_* link are we ? */
7936285Sbrian  struct async async;          /* Our async state */
8036285Sbrian  struct hdlc hdlc;            /* Our hdlc state */
8158038Sbrian  int fd;                      /* File descriptor for this device */
8236285Sbrian  struct mbuf *out;            /* mbuf that suffered a short write */
8336285Sbrian  int connect_count;
8436285Sbrian  struct datalink *dl;         /* my owner */
8536285Sbrian
8636285Sbrian  struct {
8745264Sbrian    u_char buf[MAX_MRU];       /* Our input data buffer */
8845264Sbrian    size_t sz;
8945264Sbrian  } input;
9045264Sbrian
9145264Sbrian  struct {
9247682Sbrian    char full[DEVICE_LEN];     /* Our current device name */
9336285Sbrian    char *base;
9436285Sbrian  } name;
9536285Sbrian
9652429Sbrian  time_t Utmp;                 /* Are we in utmp ? */
9736467Sbrian  pid_t session_owner;         /* HUP this when closing the link */
9836285Sbrian
9947061Sbrian  struct device *handler;      /* device specific handler */
10047061Sbrian
10146686Sbrian  struct {
10246686Sbrian    unsigned rts_cts : 1;      /* Is rts/cts enabled ? */
10346686Sbrian    unsigned parity;           /* What parity is enabled? (tty flags) */
10446686Sbrian    unsigned speed;            /* tty speed */
10536285Sbrian
10646102Sbrian    char devlist[LINE_LEN];    /* NUL separated list of devices */
10746102Sbrian    int ndev;                  /* number of devices in list */
10853733Sbrian    struct cd cd;
10936285Sbrian  } cfg;
11036285Sbrian};
11136285Sbrian
11236285Sbrian#define field2phys(fp, name) \
11336285Sbrian  ((struct physical *)((char *)fp - (int)(&((struct physical *)0)->name)))
11436285Sbrian
11536285Sbrian#define link2physical(l) \
11636285Sbrian  ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL)
11736285Sbrian
11836285Sbrian#define descriptor2physical(d) \
11936285Sbrian  ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL)
12036285Sbrian
12152942Sbrian#define PHYSICAL_NOFORCE		1
12252942Sbrian#define PHYSICAL_FORCE_ASYNC		2
12352942Sbrian#define PHYSICAL_FORCE_SYNC		3
12452942Sbrian#define PHYSICAL_FORCE_SYNCNOACF	4
12547061Sbrian
12646686Sbrianextern struct physical *physical_Create(struct datalink *, int);
12746686Sbrianextern int physical_Open(struct physical *, struct bundle *);
12846686Sbrianextern int physical_Raw(struct physical *);
12946686Sbrianextern int physical_GetSpeed(struct physical *);
13046686Sbrianextern int physical_SetSpeed(struct physical *, int);
13146686Sbrianextern int physical_SetParity(struct physical *, const char *);
13246686Sbrianextern int physical_SetRtsCts(struct physical *, int);
13346686Sbrianextern void physical_SetSync(struct physical *);
13446686Sbrianextern int physical_ShowStatus(struct cmdargs const *);
13546686Sbrianextern void physical_Offline(struct physical *);
13646686Sbrianextern void physical_Close(struct physical *);
13746686Sbrianextern void physical_Destroy(struct physical *);
13846686Sbrianextern struct physical *iov2physical(struct datalink *, struct iovec *, int *,
13952942Sbrian                                     int, int, int *, int *);
14052942Sbrianextern int physical2iov(struct physical *, struct iovec *, int *, int, int *,
14153684Sbrian                        int *);
14253684Sbrianextern const char *physical_LockedDevice(struct physical *);
14346686Sbrianextern void physical_ChangedPid(struct physical *, pid_t);
14446686Sbrian
14536285Sbrianextern int physical_IsSync(struct physical *);
14636285Sbrianextern const char *physical_GetDevice(struct physical *);
14736285Sbrianextern void physical_SetDeviceList(struct physical *, int, const char *const *);
14846686Sbrianextern void physical_SetDevice(struct physical *, const char *);
14936285Sbrian
15036285Sbrianextern ssize_t physical_Read(struct physical *, void *, size_t);
15136285Sbrianextern ssize_t physical_Write(struct physical *, const void *, size_t);
15258028Sbrianextern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *,
15346686Sbrian                                fd_set *, int *, int);
15458028Sbrianextern int physical_IsSet(struct fdescriptor *, const fd_set *);
15558028Sbrianextern void physical_DescriptorRead(struct fdescriptor *, struct bundle *,
15652942Sbrian                                    const fd_set *);
15736285Sbrianextern void physical_Login(struct physical *, const char *);
15836285Sbrianextern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *,
15936285Sbrian                                  fd_set *);
16036285Sbrianextern int physical_SetMode(struct physical *, int);
16138544Sbrianextern void physical_DeleteQueue(struct physical *);
16247461Sbrianextern void physical_SetupStack(struct physical *, const char *, int);
16347061Sbrianextern void physical_StopDeviceTimer(struct physical *);
16447769Sbrianextern int physical_MaxDeviceSize(void);
16549472Sbrianextern int physical_AwaitCarrier(struct physical *);
16652942Sbrianextern void physical_SetDescriptor(struct physical *);
167