summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-05-16 12:20:32 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-05-16 12:20:32 +0000
commit3558968f7d95516e9e9eb8c11fcc878d7350dc6e (patch)
tree3bd224879b0f2f59eb591de08acb072c6d4a5f78 /usr.bin
parent4f99a01e86753ce8ebf0bb231ca707a99418953e (diff)
use the ``hello'' message a to set the device mode, and thus make
it mandatory. Old legacy clients setting the mode with sio_setpar() are still working thanks to small hack.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/aucat/amsg.h4
-rw-r--r--usr.bin/aucat/sock.c60
-rw-r--r--usr.bin/aucat/sock.h9
3 files changed, 47 insertions, 26 deletions
diff --git a/usr.bin/aucat/amsg.h b/usr.bin/aucat/amsg.h
index f0481f82909..c2eb4dfebee 100644
--- a/usr.bin/aucat/amsg.h
+++ b/usr.bin/aucat/amsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amsg.h,v 1.6 2009/05/16 11:15:26 ratchov Exp $ */
+/* $OpenBSD: amsg.h,v 1.7 2009/05/16 12:20:31 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -43,7 +43,7 @@ struct amsg {
uint32_t __pad;
union {
struct amsg_par {
- uint8_t mode; /* AMSG_PLAY or AMSG_REC */
+ uint8_t legacy_mode; /* compat for old libs */
#define AMSG_IGNORE 0 /* loose sync */
#define AMSG_SYNC 1 /* resync after xrun */
#define AMSG_ERROR 2 /* kill the stream */
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index 479e87663f9..07ef03af278 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.17 2009/05/16 11:15:26 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.18 2009/05/16 12:20:31 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -269,7 +269,7 @@ struct aproc_ops wsock_ops = {
};
/*
- * initialise socket in the SOCK_INIT state with default
+ * initialise socket in the SOCK_HELLO state with default
* parameters
*/
struct sock *
@@ -282,17 +282,15 @@ sock_new(struct fileops *ops, int fd, char *name,
f = (struct sock *)pipe_new(ops, fd, name);
if (f == NULL)
return NULL;
- f->pstate = SOCK_INIT;
+ f->pstate = SOCK_HELLO;
f->mode = 0;
if (dev_rec) {
f->templ_wpar = *wpar;
f->wpar = f->templ_wpar;
- f->mode |= AMSG_REC;
}
if (dev_play) {
f->templ_rpar = *rpar;
f->rpar = f->templ_rpar;
- f->mode |= AMSG_PLAY;
}
f->xrun = AMSG_IGNORE;
f->bufsz = dev_bufsz;
@@ -581,15 +579,20 @@ sock_setpar(struct sock *f)
struct amsg_par *p = &f->rmsg.u.par;
unsigned min, max, rate;
- if (AMSG_ISSET(p->mode)) {
- if ((p->mode & ~(AMSG_PLAY | AMSG_REC)) || p->mode == 0) {
- DPRINTF("sock_setpar: bad mode %x\n", p->mode);
+ if (AMSG_ISSET(p->legacy_mode)) {
+ /*
+ * XXX: allow old clients that don't support HELLO
+ * to work
+ */
+ if ((p->legacy_mode & ~(AMSG_PLAY | AMSG_REC)) ||
+ (p->legacy_mode == 0)) {
+ DPRINTF("sock_setpar: bad mode %x\n", p->legacy_mode);
return 0;
}
f->mode = 0;
- if ((p->mode & AMSG_PLAY) && dev_mix)
+ if ((p->legacy_mode & AMSG_PLAY) && dev_mix)
f->mode |= AMSG_PLAY;
- if ((p->mode & AMSG_REC) && dev_sub)
+ if ((p->legacy_mode & AMSG_REC) && dev_sub)
f->mode |= AMSG_REC;
DPRINTF("sock_setpar: mode -> %x\n", f->mode);
}
@@ -707,18 +710,27 @@ sock_hello(struct sock *f)
struct amsg_hello *p = &f->rmsg.u.hello;
DPRINTF("sock_hello: from <%s>\n", p->who);
- if ((p->proto & AMSG_PLAY) && dev_mix == NULL) {
- DPRINTF("sock_hello: playback not supported\n");
+ if ((p->proto & ~(AMSG_PLAY | AMSG_REC)) != 0 ||
+ (p->proto & (AMSG_PLAY | AMSG_REC)) == 0) {
+ DPRINTF("sock_hello: %x: unsupported proto\n", p->proto);
return 0;
}
- if ((p->proto & AMSG_REC) && dev_sub == NULL) {
- DPRINTF("sock_hello: recording not supported\n");
- return 0;
+ f->mode = 0;
+ if (p->proto & AMSG_PLAY) {
+ if (!dev_mix) {
+ DPRINTF("sock_hello: playback not supported\n");
+ return 0;
+ }
+ f->mode |= AMSG_PLAY;
}
- if ((p->proto & ~(AMSG_PLAY | AMSG_REC)) != 0) {
- DPRINTF("sock_hello: %x: unsupported proto\n", p->proto);
- return 0;
+ if (p->proto & AMSG_REC) {
+ if (!dev_sub) {
+ DPRINTF("sock_hello: recording not supported\n");
+ return 0;
+ }
+ f->mode |= AMSG_REC;
}
+ f->pstate = SOCK_INIT;
return 1;
}
@@ -731,6 +743,14 @@ sock_execmsg(struct sock *f)
{
struct amsg *m = &f->rmsg;
+ /*
+ * XXX: allow old clients to work without hello
+ */
+ if (f->pstate == SOCK_HELLO && m->cmd != AMSG_HELLO) {
+ DPRINTF("sock_execmsg: legacy client\n");
+ f->pstate = SOCK_INIT;
+ }
+
switch (m->cmd) {
case AMSG_DATA:
DPRINTFN(4, "sock_execmsg: %p: DATA\n", f);
@@ -801,7 +821,7 @@ sock_execmsg(struct sock *f)
}
AMSG_INIT(m);
m->cmd = AMSG_GETPAR;
- m->u.par.mode = f->mode;
+ m->u.par.legacy_mode = f->mode;
m->u.par.bits = f->rpar.bits;
m->u.par.bps = f->rpar.bps;
m->u.par.sig = f->rpar.sig;
@@ -856,7 +876,7 @@ sock_execmsg(struct sock *f)
break;
case AMSG_HELLO:
DPRINTFN(2, "sock_execmsg: %p: HELLO\n", f);
- if (f->pstate != SOCK_INIT) {
+ if (f->pstate != SOCK_HELLO) {
DPRINTF("sock_execmsg: %p: HELLO, bad state\n", f);
aproc_del(f->pipe.file.rproc);
return 0;
diff --git a/usr.bin/aucat/sock.h b/usr.bin/aucat/sock.h
index 9d0dd2f2597..3bcbadbe6a6 100644
--- a/usr.bin/aucat/sock.h
+++ b/usr.bin/aucat/sock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.h,v 1.5 2009/02/06 08:29:35 ratchov Exp $ */
+/* $OpenBSD: sock.h,v 1.6 2009/05/16 12:20:31 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -38,9 +38,10 @@ struct sock {
#define SOCK_WMSG 1 /* amsg being written */
#define SOCK_WDATA 2 /* data chunk being written */
unsigned wstate; /* state of the write-end FSM */
-#define SOCK_INIT 0 /* parameter negotiation */
-#define SOCK_START 1 /* filling play buffers */
-#define SOCK_RUN 2 /* attached to the mix / sub */
+#define SOCK_HELLO 0 /* waiting for HELLO message */
+#define SOCK_INIT 1 /* parameter negotiation */
+#define SOCK_START 2 /* filling play buffers */
+#define SOCK_RUN 3 /* attached to the mix / sub */
unsigned pstate; /* one of the above */
unsigned mode; /* a set of AMSG_PLAY, AMSG_REC */
struct aparams rpar; /* read (ie play) parameters */