Modem pluggability began.
This commit is contained in:
parent
f4989d6001
commit
42059bea9b
@ -3,7 +3,7 @@
|
||||
* (C)2005, Dan Ponte
|
||||
* BSDL w/ advert.
|
||||
*/
|
||||
/* $Amigan: phoned/include/phoned.h,v 1.13 2005/06/16 21:04:58 dcp1990 Exp $ */
|
||||
/* $Amigan: phoned/include/phoned.h,v 1.14 2005/06/18 03:10:45 dcp1990 Exp $ */
|
||||
#include <pcre.h> /* fugly, I know... */
|
||||
#define VERSION "0.1"
|
||||
#define LOGFILE "/var/log/phoned.log"
|
||||
@ -97,6 +97,22 @@ typedef struct cnd_t {
|
||||
struct cnd_t* last;
|
||||
struct cnd_t* next;
|
||||
} cond_t;
|
||||
typedef enum modes_t {
|
||||
ok,
|
||||
ring,
|
||||
incoming,
|
||||
err
|
||||
} mod_res_t;
|
||||
typedef struct mod_t {
|
||||
char* modem_name;
|
||||
int features;
|
||||
int deffuncs;
|
||||
int (*init)(void);
|
||||
int (*destroy)(void);
|
||||
mod_res_t (*evalrc)(char *result);
|
||||
void (*pickup)(void);
|
||||
void (*hangup)(void);
|
||||
} modem_t;
|
||||
typedef enum stat {
|
||||
init = 0,
|
||||
loginstage,
|
||||
@ -146,5 +162,14 @@ void *modem_io(void *k);
|
||||
void give_me_modem(char* str);
|
||||
char *parse_command(const char *cmd, short *cont, state_info_t *s);
|
||||
void begin_dialogue(FILE* fp, int fd);
|
||||
/* old stuff...
|
||||
void modem_pickup(void);
|
||||
void modem_hangup(void);
|
||||
*/
|
||||
/* function defs for modem... */
|
||||
#define modem_pickup mo->pickup
|
||||
#define modem_hangup mo->hangup
|
||||
#define modem_evalrc mo->evalrc
|
||||
#ifndef MODEM_C
|
||||
extern modem_t *mo;
|
||||
#endif
|
||||
|
@ -1,6 +1,6 @@
|
||||
# cnd Makefile
|
||||
# (C)2005, Dan Ponte
|
||||
# $Amigan: phoned/phonectl/Makefile,v 1.2 2005/06/01 00:43:07 dcp1990 Exp $
|
||||
# $Amigan: phoned/phonectl/Makefile,v 1.3 2005/06/18 03:10:53 dcp1990 Exp $
|
||||
include ../global.mk
|
||||
# basic stuff. we append for a reason.
|
||||
CPPFLAGS=-I../include
|
||||
@ -11,3 +11,4 @@ MAINBIN=phonectl
|
||||
SRCS=phonectl.c
|
||||
OBJS=phonectl.o
|
||||
include ../main.mk
|
||||
ourclean:
|
||||
|
@ -1,6 +1,6 @@
|
||||
# cnd Makefile
|
||||
# (C)2005, Dan Ponte
|
||||
# $Amigan: phoned/phoned/Makefile,v 1.10 2005/06/13 21:00:07 dcp1990 Exp $
|
||||
# $Amigan: phoned/phoned/Makefile,v 1.11 2005/06/18 03:10:55 dcp1990 Exp $
|
||||
include ../global.mk
|
||||
# basic stuff. we append for a reason.
|
||||
CPPFLAGS+=-I../include -DDEBUG -DYY_NO_UNPUT
|
||||
@ -9,7 +9,7 @@ LDFLAGS+=-lutil -lpcre
|
||||
# keep these up to date.
|
||||
MAINBIN=phoned
|
||||
SRCS=main.c init.c log.c cfg.c socket.c y.tab.c lex.yy.c signals.c cid.c modem.c notify.c filters.c remote.c
|
||||
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o modem.o notify.o filters.o remote.o
|
||||
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o modem.o notify.o filters.o remote.o modems/libmodems.a
|
||||
OHDRS=y.tab.h
|
||||
CLEANFILES=y.tab.c y.tab.h lex.yy.c
|
||||
LEX=lex
|
||||
@ -17,8 +17,12 @@ YACC=yacc
|
||||
|
||||
include ../main.mk
|
||||
|
||||
modems/libmodems.a:
|
||||
cd modems && $(MAKE)
|
||||
y.tab.h: y.tab.c
|
||||
y.tab.c: config.y
|
||||
$(YACC) -d config.y
|
||||
lex.yy.c: config.l y.tab.c y.tab.h
|
||||
$(LEX) config.l
|
||||
ourclean:
|
||||
cd modems && $(MAKE) clean
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#define MODEM_C
|
||||
#include <phoned.h>
|
||||
#define ROCKWELL_INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
|
||||
#define ROCKWELL_PICKUP "ATH1\r\n"
|
||||
@ -64,6 +65,8 @@ pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t mpcond = PTHREAD_COND_INITIALIZER;
|
||||
int modempipes[2];
|
||||
extern pthread_mutex_t cfmx;
|
||||
modem_t* mo;
|
||||
extern modem_t rockwell;
|
||||
void stmod(str)
|
||||
const char* str;
|
||||
{
|
||||
@ -135,36 +138,14 @@ int init_modem(char* dev)
|
||||
return -3;
|
||||
}
|
||||
pthread_mutex_unlock(&modemmx);
|
||||
stmod(ROCKWELL_INITSTRING);
|
||||
mo = &rockwell;
|
||||
mo->init();
|
||||
pthread_mutex_lock(&mpipemx);
|
||||
pipe(modempipes);
|
||||
pthread_mutex_unlock(&mpipemx);
|
||||
return 1;
|
||||
}
|
||||
int modem_evalrc(char* result)
|
||||
{
|
||||
int rescode;
|
||||
unsigned int i;
|
||||
for(i = 0; i <= strlen(result); i++) {
|
||||
if(result[i] == '\r' || result[i] == '\n') result[i] = '\0';
|
||||
}
|
||||
rescode = atoi(result);
|
||||
switch(rescode) {
|
||||
case 0:
|
||||
/* OK */
|
||||
return 0;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 4:
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void modem_hread(char* cbuf)
|
||||
{
|
||||
pthread_mutex_lock(&buffermx);
|
||||
@ -251,6 +232,7 @@ void *modem_io(k)
|
||||
pthread_exit(NULL);
|
||||
return 0;
|
||||
}
|
||||
#if 0 /* all old... */
|
||||
/* Modem control stuff: be forewarned, this might become pluggable!
|
||||
* Rockwell for now.
|
||||
*/
|
||||
@ -263,3 +245,28 @@ void modem_hangup(void)
|
||||
{
|
||||
stmod(ROCKWELL_HANGUP);
|
||||
}
|
||||
int modem_evalrc(char* result)
|
||||
{
|
||||
int rescode;
|
||||
unsigned int i;
|
||||
for(i = 0; i <= strlen(result); i++) {
|
||||
if(result[i] == '\r' || result[i] == '\n') result[i] = '\0';
|
||||
}
|
||||
rescode = atoi(result);
|
||||
switch(rescode) {
|
||||
case 0:
|
||||
/* OK */
|
||||
return 0;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 4:
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
25
phoned/modems/Makefile
Normal file
25
phoned/modems/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
# cnd Makefile
|
||||
# (C)2005, Dan Ponte
|
||||
# $Amigan: phoned/phoned/modems/Makefile,v 1.1 2005/06/18 03:10:56 dcp1990 Exp $
|
||||
include ../../global.mk
|
||||
# basic stuff. we append for a reason.
|
||||
CPPFLAGS+=-I../../include
|
||||
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
|
||||
LDFLAGS=
|
||||
# keep these up to date.
|
||||
MAINBIN=libmodems.a
|
||||
SRCS=rockwell.c
|
||||
OBJS=rockwell.o
|
||||
all: .depend ${MAINBIN}
|
||||
# I know, I know, but it's good.
|
||||
.depend: ${SRCS} ${OHDRS}
|
||||
mkdep ${CPPFLAGS} -MM -p ${SRCS}
|
||||
${MAINBIN}: ${OBJS}
|
||||
ar rc ${MAINBIN} ${OBJS}
|
||||
ranlib ${MAINBIN}
|
||||
# for this app
|
||||
%.o: %.c
|
||||
${CC} ${CFLAGS} -c ${.SOURCE}
|
||||
# end ours
|
||||
clean:
|
||||
rm -f *.o ${MAINBIN} .depend *~ *.core ${CLEANFILES}
|
99
phoned/modems/rockwell.c
Normal file
99
phoned/modems/rockwell.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Dan Ponte
|
||||
*
|
||||
* rockwell.c - Rockwell modem stuff
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* $Amigan: phoned/phoned/modems/rockwell.c,v 1.1 2005/06/18 03:10:56 dcp1990 Exp $ */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <phoned.h>
|
||||
#define ROCKWELL_INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
|
||||
#define ROCKWELL_PICKUP "ATH1\r\n"
|
||||
#define ROCKWELL_HANGUP "ATH\r\n"
|
||||
#define ROCKWELL_RESET "ATZ\r\n"
|
||||
|
||||
short plug_init(void)
|
||||
{
|
||||
return 1; /* ok */
|
||||
}
|
||||
/* modem stuff */
|
||||
int rw_init(void)
|
||||
{
|
||||
stmod(ROCKWELL_INITSTRING);
|
||||
return 1;
|
||||
}
|
||||
int rw_destroy(void)
|
||||
{
|
||||
stmod(ROCKWELL_RESET);
|
||||
return 1;
|
||||
}
|
||||
mod_res_t rw_evalrc(result)
|
||||
char* result;
|
||||
{
|
||||
int rescode;
|
||||
unsigned int i;
|
||||
for(i = 0; i <= strlen(result); i++) {
|
||||
if(result[i] == '\r' || result[i] == '\n') result[i] = '\0';
|
||||
}
|
||||
rescode = atoi(result);
|
||||
switch(rescode) {
|
||||
case 0:
|
||||
/* OK */
|
||||
return ok;
|
||||
break;
|
||||
case 2:
|
||||
return ring;
|
||||
break;
|
||||
case 4:
|
||||
return err;
|
||||
break;
|
||||
default:
|
||||
return ok;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void rw_pickup(void)
|
||||
{
|
||||
/* no locking because stmod() does it for us */
|
||||
stmod(ROCKWELL_PICKUP);
|
||||
}
|
||||
void rw_hangup(void)
|
||||
{
|
||||
stmod(ROCKWELL_HANGUP);
|
||||
}
|
||||
|
||||
modem_t rockwell = {
|
||||
"ROCKWELL",
|
||||
0x0,
|
||||
0x0,
|
||||
&rw_init,
|
||||
&rw_destroy,
|
||||
&rw_evalrc,
|
||||
&rw_pickup,
|
||||
&rw_hangup
|
||||
};
|
Loading…
Reference in New Issue
Block a user