Xref: utzoo comp.sys.att:6154 unix-pc.sources:299 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!shamash!sialis!icus!lenny From: lenny@icus.islp.ny.us (Lenny Tropiano) Newsgroups: comp.sys.att,unix-pc.sources Subject: Re: UNIXPC communication questions Summary: switching to DATA and/or VOICE (requires phtoggle) Message-ID: <678@icus.islp.ny.us> Date: 21 Apr 89 04:22:14 GMT References: <23118@shemp.CS.UCLA.EDU> Reply-To: lenny@icus.islp.ny.us (Lenny Tropiano) Distribution: usa Organization: ICUS Software Systems, Islip, New York Lines: 265 In article <23118@shemp.CS.UCLA.EDU> kirkaas@cs.ucla.edu (paul kirkaas) writes: ... |> |>2) phtoggle toggles between data/voice. Is there any way to *absolutely* |>switch to data or voice? I mean, I want to write a script that is scheduled |>by cron to make sure that the pc is is in a given mode at a given time. I |>don't want to automatically toggle if it is already in the right mode. |> Yes, I did exactly that with a little utility. Since it's small I'm reposting it again. Basically it is invoked like: $ phset DATA -or- phset VOICE -Lenny -- cut here -- -- cut here -- -- cut here -- -- cut here -- -- cut here -- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh phset.mk <<'END_OF_phset.mk' X# X# Makefile to compile phset.c (Phone Set) X# By Lenny Tropiano X# (c)1988 ICUS Software Systems UUCP: ...icus!lenny X# X# add -DSINGLE_LINE to CFLAGS if using only /dev/ph0 as the line to toggle, X# else leave undefined. XCFLAGS=-v -O XLDFLAGS=-s XLIBS=/lib/crt0s.o /lib/shlib.ifile XDEST=/usr/lbin/ X# Xphset.o: X $(CC) $(CFLAGS) -c phset.c X# Xphset: phset.o X @echo "Loading ..." X $(LD) $(LDFLAGS) -o phset phset.o $(LIBS) X# X# Need to be root for this X# X/usr/lbin: X mkdir /usr/lbin X# Xinstall: phset /usr/lbin X cp phset ${DEST} X chown root ${DEST}/phset X chgrp bin ${DEST}/phset X chmod 4755 ${DEST}/phset X# Xclean: X rm -f phset *.o *.shar END_OF_phset.mk if test 653 -ne `wc -c phset.c <<'END_OF_phset.c' X/************************************************************************\ X** ** X** Program name: phset.c (Phone line set) ** X** Programmer: Lenny Tropiano UUCP: ...icus!lenny ** X** Organization: ICUS Software Systems (c)1988 ** X** Date: April 3, 1988 ** X** ** X************************************************************************** X** ** X** Program use: Program is run to set the phone line to a specific ** X** setting. This checks the phone line status to ** X** see what the line is set at currently, and calls ** X** /usr/bin/phtoggle if necessary. This will solve the ** X** problems inherent in using phtoggle in your crontab ** X** to adjust the line status. If the status gets to the ** X** wrong setting you'll be toggling to the wrong setting. ** X** ** X************************************************************************** X** Permission is granted to distribute this program by any means as ** X** long as credit is given for my work. I would also like to see ** X** any modifications or enhancements to this program. ** X\************************************************************************/ X X#include X#include X#include X#include X#include X X#define PHNDEF 0 X#define UNIX "/unix" X#define KMEM "/dev/kmem" X X#ifdef SINGLE_LINE /* if defined, then check ph0 */ X# define OFFSET 0 X#else /* else, then check ph1 */ X# define OFFSET sizeof(struct phdef) X#endif X Xstruct nlist unixsym[] = { /* /unix name list of symbols */ X { "phndef", }, X { NULL, }, X}; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X void read_kmem(); X struct phdef phblock; X int kmem; X ushort phone_mode; X X if (argc != 2) { X printf("usage: %s [VOICE|DATA]\n", argv[0]); X exit(1); X } X X if (strcmp(argv[1],"VOICE") != 0 && X strcmp(argv[1],"DATA") != 0) { X printf("usage: %s [VOICE|DATA]\n", argv[0]); X exit(1); X } X X /* X * Open unix namelist. X */ X X if (nlist(UNIX, unixsym) < 0) { X fprintf(stderr, "%s: no namelist.\n", UNIX); X exit(1); X } X X /* X * Open kernel memory. X */ X X if ((kmem = open(KMEM, 0)) < 0) { X perror(KMEM); X exit(1); X } X X /* X * Read memory location out of /dev/kmem. X */ X X read_kmem(kmem, &phblock, X (unixsym[PHNDEF].n_value + OFFSET), X (long)sizeof (struct phdef)); X X if (phblock.p_lineparam & DATA) { /* check to see if DATA */ X if (strcmp(argv[1],"DATA") == 0) /* do you want it this way? */ X exit(0); X } else { /* it must be VOICE then */ X if (strcmp(argv[1],"VOICE") == 0) /* do you want it this way? */ X exit(0); X } X X /* if not set, call phtoggle, to change mode */ X X putenv("IFS=\" \n\t\""); /* prevent any security breaches */ X X execl("/usr/bin/phtoggle","phtoggle", 0); X X perror("execl() failed"); X X} X Xvoid read_kmem(fd, caddr, kaddr, nbytes) Xint fd; Xchar *caddr; Xlong kaddr; Xlong nbytes; X{ X if (lseek(fd, kaddr, 0)<0L || X read(fd, caddr, (unsigned)nbytes) != nbytes ) X perror("can't read /dev/kmem"); X} X END_OF_phset.c if test 3497 -ne `wc -c phtoggle.mk <<'END_OF_phtoggle.mk' X# Makefile for phtoggle implementation. X# By Lenny Tropiano (lenny@icus.UUCP) X# (c)1988 ICUS Software Systems X XCFLAGS = -v -O XLDFLAGS = -s XBINDIR = /usr/lbin XSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile X Xphtoggle: phtoggle.o X ld $(LDFLAGS) -o phtoggle phtoggle.o $(SHAREDLIB) X Xinstall: phtoggle X chown root phtoggle X chgrp root phtoggle X chmod 4755 phtoggle X mv phtoggle $(BINDIR) X END_OF_phtoggle.mk if test 395 -ne `wc -c phtoggle.mk <<'END_OF_phtoggle.mk' X# Makefile for phtoggle implementation. X# By Lenny Tropiano (lenny@icus.UUCP) X# (c)1988 ICUS Software Systems X XCFLAGS = -v -O XLDFLAGS = -s XBINDIR = /usr/lbin XSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile X Xphtoggle: phtoggle.o X ld $(LDFLAGS) -o phtoggle phtoggle.o $(SHAREDLIB) X Xinstall: phtoggle X chown root phtoggle X chgrp root phtoggle X chmod 4755 phtoggle X mv phtoggle $(BINDIR) X END_OF_phtoggle.mk if test 395 -ne `wc -c