1998-01-29 00:49:32 +00:00
|
|
|
/*
|
|
|
|
* Written by Eivind Eklund <eivind@yes.no>
|
|
|
|
* for Yes Interactive
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998, Yes Interactive. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in any form is permitted. Redistribution in
|
|
|
|
* source form should include the above copyright and this set of
|
|
|
|
* conditions, because large sections american law seems to have been
|
|
|
|
* created by a bunch of jerks on drugs that are now illegal, forcing
|
|
|
|
* me to include this copyright-stuff instead of placing this in the
|
|
|
|
* public domain. The name of of 'Yes Interactive' or 'Eivind Eklund'
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1998-03-13 21:07:46 +00:00
|
|
|
* $Id: physical.c,v 1.1.2.15 1998/03/13 00:44:20 brian Exp $
|
1998-01-29 00:49:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1998-03-10 03:06:07 +00:00
|
|
|
#include <time.h>
|
1998-01-29 00:49:32 +00:00
|
|
|
#include <unistd.h>
|
1998-03-10 03:06:07 +00:00
|
|
|
#include <utmp.h>
|
1998-01-29 00:49:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* XXX Name space pollution from vars.h */
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <alias.h>
|
1998-03-10 03:06:07 +00:00
|
|
|
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
|
|
|
|
/* XXX Name space pollution from hdlc.h */
|
|
|
|
#include "mbuf.h"
|
|
|
|
|
|
|
|
/* Name space pollution for physical.h */
|
|
|
|
#include "timer.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-02-18 19:35:59 +00:00
|
|
|
#include "hdlc.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "throughput.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "async.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "link.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
|
1998-02-09 19:21:11 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
|
|
|
|
|
|
|
#include "vars.h"
|
1998-03-13 21:07:46 +00:00
|
|
|
#include "iplist.h"
|
|
|
|
#include "ipcp.h"
|
1998-02-06 02:23:48 +00:00
|
|
|
#include "bundle.h"
|
1998-02-09 19:21:11 +00:00
|
|
|
#include "log.h"
|
1998-03-10 03:06:07 +00:00
|
|
|
#include "id.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
|
|
|
|
/* External calls - should possibly be moved inline */
|
|
|
|
extern int IntToSpeed(int);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_GetFD(struct physical *phys) {
|
|
|
|
return phys->fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_IsATTY(struct physical *phys) {
|
|
|
|
return isatty(phys->fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_IsSync(struct physical *phys) {
|
1998-02-17 19:29:03 +00:00
|
|
|
return phys->cfg.speed == 0;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_FD_ISSET(struct physical *phys, fd_set *set) {
|
|
|
|
return phys->fd >= 0 && FD_ISSET(phys->fd, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_FD_SET(struct physical *phys, fd_set *set) {
|
|
|
|
assert(phys->fd >= 0);
|
|
|
|
FD_SET(phys->fd, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-06 00:34:47 +00:00
|
|
|
const char *Physical_GetDevice(struct physical *phys)
|
|
|
|
{
|
|
|
|
return phys->name.full;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX-ML - must be moved into the physical struct */
|
|
|
|
void
|
1998-03-06 00:34:47 +00:00
|
|
|
Physical_SetDeviceList(struct physical *phys, const char *new_device_list) {
|
|
|
|
strncpy(phys->cfg.devlist, new_device_list, sizeof phys->cfg.devlist - 1);
|
|
|
|
phys->cfg.devlist[sizeof phys->cfg.devlist - 1] = '\0';
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_SetSpeed(struct physical *phys, int speed) {
|
|
|
|
if (IntToSpeed(speed) != B0) {
|
1998-02-17 19:29:03 +00:00
|
|
|
phys->cfg.speed = speed;
|
1998-01-29 00:49:32 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
1998-02-17 19:29:03 +00:00
|
|
|
return 0;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_SetSync(struct physical *phys) {
|
1998-02-17 19:29:03 +00:00
|
|
|
phys->cfg.speed = 0;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_SetRtsCts(struct physical *phys, int enable) {
|
|
|
|
assert(enable == 0 || enable == 1);
|
|
|
|
|
1998-02-17 19:29:03 +00:00
|
|
|
phys->cfg.rts_cts = enable;
|
1998-01-29 00:49:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_SetDedicated(struct physical *phys, int enable) {
|
|
|
|
assert(enable == 0 || enable == 1);
|
|
|
|
|
1998-02-17 19:29:03 +00:00
|
|
|
phys->cfg.is_dedicated = enable;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_SetDirect(struct physical *phys, int enable) {
|
|
|
|
assert(enable == 0 || enable == 1);
|
|
|
|
|
1998-02-17 19:29:03 +00:00
|
|
|
phys->cfg.is_direct = enable;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_IsDirect(struct physical *phys) {
|
1998-02-17 19:29:03 +00:00
|
|
|
return phys->cfg.is_direct;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_IsDedicated(struct physical *phys) {
|
1998-02-17 19:29:03 +00:00
|
|
|
return phys->cfg.is_dedicated;
|
1998-01-29 00:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_DupAndClose(struct physical *phys) {
|
|
|
|
int nmodem;
|
|
|
|
|
|
|
|
nmodem = dup(phys->fd);
|
|
|
|
close(phys->fd);
|
|
|
|
phys->fd = nmodem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encapsulation for a read on the FD. Avoids some exposure, and
|
|
|
|
concentrates control. */
|
|
|
|
ssize_t
|
|
|
|
Physical_Read(struct physical *phys, void *buf, size_t nbytes) {
|
|
|
|
return read(phys->fd, buf, nbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
Physical_Write(struct physical *phys, const void *buf, size_t nbytes) {
|
|
|
|
return write(phys->fd, buf, nbytes);
|
|
|
|
}
|
1998-02-06 02:22:28 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
Physical_ReportProtocolStatus(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-16 00:01:12 +00:00
|
|
|
link_ReportProtocolStatus(bundle2link(arg->bundle, NULL));
|
1998-02-06 02:22:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-02-09 19:21:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
Physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
|
1998-02-13 05:10:26 +00:00
|
|
|
int *n, int force)
|
1998-02-09 19:21:11 +00:00
|
|
|
{
|
|
|
|
struct physical *p = descriptor2physical(d);
|
|
|
|
int sets;
|
|
|
|
|
|
|
|
LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p);
|
|
|
|
|
1998-02-13 05:10:26 +00:00
|
|
|
sets = 0;
|
1998-02-09 19:21:11 +00:00
|
|
|
if (p->fd >= 0) {
|
1998-02-13 05:10:26 +00:00
|
|
|
if (r) {
|
|
|
|
FD_SET(p->fd, r);
|
|
|
|
sets++;
|
|
|
|
}
|
|
|
|
if (e) {
|
|
|
|
FD_SET(p->fd, e);
|
|
|
|
sets++;
|
|
|
|
}
|
|
|
|
if (w && (force || link_QueueLen(&p->link))) {
|
1998-02-09 19:21:11 +00:00
|
|
|
FD_SET(p->fd, w);
|
1998-02-13 05:10:26 +00:00
|
|
|
sets++;
|
|
|
|
}
|
|
|
|
if (sets && *n < p->fd + 1)
|
|
|
|
*n = p->fd + 1;
|
|
|
|
}
|
1998-02-09 19:21:11 +00:00
|
|
|
|
|
|
|
return sets;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Physical_IsSet(struct descriptor *d, fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct physical *p = descriptor2physical(d);
|
|
|
|
|
|
|
|
LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p);
|
|
|
|
return p->fd >= 0 && FD_ISSET(p->fd, fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-23 00:38:44 +00:00
|
|
|
Physical_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
|
|
|
const fd_set *fdset)
|
1998-02-09 19:21:11 +00:00
|
|
|
{
|
|
|
|
struct physical *p = descriptor2physical(d);
|
|
|
|
|
|
|
|
LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p);
|
1998-02-23 00:38:44 +00:00
|
|
|
link_StartOutput(&p->link, bundle);
|
1998-02-09 19:21:11 +00:00
|
|
|
}
|
1998-03-10 03:06:07 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Physical_Login(struct physical *phys, const char *name)
|
|
|
|
{
|
|
|
|
if ((mode & MODE_DIRECT) && Physical_IsATTY(phys) && Enabled(ConfUtmp))
|
|
|
|
if (phys->Utmp)
|
|
|
|
LogPrintf(LogERROR, "Oops, already logged in on %s\n", phys->name.base);
|
|
|
|
else {
|
|
|
|
struct utmp ut;
|
|
|
|
|
|
|
|
memset(&ut, 0, sizeof ut);
|
|
|
|
time(&ut.ut_time);
|
|
|
|
strncpy(ut.ut_name, name, sizeof ut.ut_name);
|
|
|
|
strncpy(ut.ut_line, phys->name.base, sizeof ut.ut_line - 1);
|
|
|
|
ID0login(&ut);
|
|
|
|
phys->Utmp = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Physical_Logout(struct physical *phys)
|
|
|
|
{
|
|
|
|
if (phys->Utmp) {
|
|
|
|
ID0logout(phys->name.base);
|
|
|
|
phys->Utmp = 0;
|
|
|
|
}
|
|
|
|
}
|