# Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. # $Id: scmd.c,v 1.1 2004/03/11 03:59:31 bcrl Exp $ # Released under the GNU Public License. See LICENSE file for details. #include #include #include #include #include #include #include #include #include #include "../scb/scioc.h" #include "../scb/message.h" enum Reqs { ReqGetChan, ReqConnect, ReqConnecting, ReqDisconnect, ReqDisconnected }; struct Req { enum Reqs req; void *ch; unsigned long data; char num[52]; }; int scmfd; void sendReq ( int req, void *ch, unsigned long data ) { struct Req r; r.req = req; r.ch = ch; r.data = data; memset(r.num, 0, sizeof(r.num)); if (sizeof(r) != write(scmfd, &r, sizeof(r))) { perror("write(req)"); exit(1); } } void getReq ( struct Req *req ) { if (sizeof(*req) != read(scmfd, req, sizeof(*req))) { perror("read(req)"); exit(1); } } void dumpBuf ( unsigned char *buf, int len ) { int i; for (i=0; i 0) { printf("read()=%d", len); dumpBuf(buf, len); if (1==buf[8] && 1==buf[9] && 1==buf[10]) { int i = buf[11] - 1; printf("got PhyConnect on %d: setting Mvip stream,slot to 0,%d\n", i, i); if (i<0 || i >= NUM_CH) printf("ooops... channel %d out of range", i); ioc.device = 0; ioc.channel = i; ioc.command = SCIOCSETMVIP; ioc.dataptr = (void *)(i); if (ioctl(fd, SCIOCSETMVIP, &ioc)) perror("ioctl(SCIOCSETMVIP"); else printf("ok!\n"); if (chan_connected[i]) fprintf(stderr, "Argh! channel %d already connected!\n", i); chan_connected[i] = 1; sendReq(ReqGetChan, 0, 0); } else if (1==buf[8] && 1==buf[9] && 2==buf[10]) { int i = buf[11] - 1; printf("got PhyDisconnect on %d\n", i); if (i<0 || i >= NUM_CH) printf("ooops... channel %d out of range", i); ioc.device = 0; ioc.channel = i; ioc.command = SCIOCRELMVIP; ioc.dataptr = NULL; if (ioctl(fd, SCIOCRELMVIP, &ioc)) perror("ioctl(SCIOCRELMVIP)"); else printf("ok!\n"); if (!chan_connected[i]) fprintf(stderr, "Argh! channel %d not connected!\n", i); if (channels[i]) { sendReq(ReqDisconnect, channels[i], 0); channels[i] = NULL; } chan_connected[i] = 0; } fflush(stdout); } } printf("read=%d\n", len); if (len < 0) perror("read"); close(fd); return 0; }