summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-05-16 11:15:27 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2009-05-16 11:15:27 +0000
commit72e3742d78c2cfbd9922f6bb2625ab415d731242 (patch)
treef9ad94464d43063421fe82da6d2da5368940b0da
parent96ecee597077d226df03d5f305c2d6666129283a (diff)
add a new ``hello'' message to aucat protocol useful to work on
future aucat extentions. No functional changes.
-rw-r--r--lib/libsndio/aucat.c30
-rw-r--r--usr.bin/aucat/amsg.h20
-rw-r--r--usr.bin/aucat/sock.c39
3 files changed, 79 insertions, 10 deletions
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index 5ed3b76857e..f5931778751 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.19 2009/05/16 09:04:45 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.20 2009/05/16 11:15:26 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -169,8 +169,8 @@ aucat_runmsg(struct aucat_hdl *hdl)
struct sio_hdl *
sio_open_aucat(char *path, unsigned mode, int nbio)
{
+ extern char *__progname;
int s;
- struct sio_cap cap;
struct aucat_hdl *hdl;
struct sockaddr_un ca;
socklen_t len = sizeof(struct sockaddr_un);
@@ -209,11 +209,31 @@ sio_open_aucat(char *path, unsigned mode, int nbio)
hdl->wtodo = 0xdeadbeef;
hdl->curvol = SIO_MAXVOL;
hdl->reqvol = SIO_MAXVOL;
- if (!sio_getcap(&hdl->sio, &cap))
+
+ /*
+ * say hello to server
+ */
+ AMSG_INIT(&hdl->wmsg);
+ hdl->wmsg.cmd = AMSG_HELLO;
+ hdl->wmsg.u.hello.proto = 0;
+ if (mode & SIO_PLAY)
+ hdl->wmsg.u.hello.proto |= AMSG_PLAY;
+ if (mode & SIO_REC)
+ hdl->wmsg.u.hello.proto |= AMSG_REC;
+ strlcpy(hdl->wmsg.u.hello.who, __progname,
+ sizeof(hdl->wmsg.u.hello.who));
+ hdl->wtodo = sizeof(struct amsg);
+ if (!aucat_wmsg(hdl))
goto bad_connect;
- if (((mode & SIO_PLAY) && cap.confs[0].pchan == 0) ||
- ((mode & SIO_REC) && cap.confs[0].rchan == 0))
+ hdl->rtodo = sizeof(struct amsg);
+ if (!aucat_rmsg(hdl)) {
+ DPRINTF("sio_open_aucat: mode refused\n");
goto bad_connect;
+ }
+ if (hdl->rmsg.cmd != AMSG_ACK) {
+ DPRINTF("sio_open_aucat: protocol err\n");
+ goto bad_connect;
+ }
return (struct sio_hdl *)hdl;
bad_connect:
while (close(s) < 0 && errno == EINTR)
diff --git a/usr.bin/aucat/amsg.h b/usr.bin/aucat/amsg.h
index 3e50aa24da8..f0481f82909 100644
--- a/usr.bin/aucat/amsg.h
+++ b/usr.bin/aucat/amsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amsg.h,v 1.5 2009/02/13 20:48:49 ratchov Exp $ */
+/* $OpenBSD: amsg.h,v 1.6 2009/05/16 11:15:26 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -24,6 +24,9 @@
* binaries or by different versions of a shared library, we are not
* allowed to change the packet binary representation in a backward
* incompatible way.
+ *
+ * Especially, make sure the amsg_xxx structures are not larger
+ * than 32 bytes.
*/
struct amsg {
#define AMSG_ACK 0 /* ack for START/STOP */
@@ -35,13 +38,12 @@ struct amsg {
#define AMSG_MOVE 6 /* position changed */
#define AMSG_GETCAP 7 /* get capabilities */
#define AMSG_SETVOL 8 /* set volume */
+#define AMSG_HELLO 9 /* say hello, check versions and so ... */
uint32_t cmd;
uint32_t __pad;
union {
struct amsg_par {
-#define AMSG_PLAY 1 /* will play */
-#define AMSG_REC 2 /* will record */
- uint8_t mode; /* a bitmap of above */
+ uint8_t mode; /* AMSG_PLAY or AMSG_REC */
#define AMSG_IGNORE 0 /* loose sync */
#define AMSG_SYNC 1 /* resync after xrun */
#define AMSG_ERROR 2 /* kill the stream */
@@ -79,6 +81,16 @@ struct amsg {
struct amsg_vol {
uint32_t ctl;
} vol;
+ struct amsg_hello {
+#define AMSG_PLAY 0x1 /* audio playback */
+#define AMSG_REC 0x2 /* audio recording */
+#define AMSG_MIDIIN 0x4 /* MIDI thru input */
+#define AMSG_MIDIOUT 0x8 /* MIDI thru output */
+#define AMSG_MIXER 0x10 /* MIDI mixer */
+ uint16_t proto; /* protocol type */
+ uint8_t reserved1[18]; /* for future use */
+ char who[12]; /* hint for leases */
+ } hello;
} u;
};
diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c
index 52c79293e6e..479e87663f9 100644
--- a/usr.bin/aucat/sock.c
+++ b/usr.bin/aucat/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.16 2009/03/15 10:31:37 jakemsr Exp $ */
+/* $OpenBSD: sock.c,v 1.17 2009/05/16 11:15:26 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -701,6 +701,27 @@ sock_setpar(struct sock *f)
return 1;
}
+int
+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");
+ return 0;
+ }
+ if ((p->proto & AMSG_REC) && dev_sub == NULL) {
+ DPRINTF("sock_hello: recording not supported\n");
+ return 0;
+ }
+ if ((p->proto & ~(AMSG_PLAY | AMSG_REC)) != 0) {
+ DPRINTF("sock_hello: %x: unsupported proto\n", p->proto);
+ return 0;
+ }
+ return 1;
+}
+
/*
* execute message in f->rmsg and change the state accordingly; return 1
* on success, and 0 on failure, in which case the socket is destroyed.
@@ -833,6 +854,22 @@ sock_execmsg(struct sock *f)
f->rtodo = sizeof(struct amsg);
f->rstate = SOCK_RMSG;
break;
+ case AMSG_HELLO:
+ DPRINTFN(2, "sock_execmsg: %p: HELLO\n", f);
+ if (f->pstate != SOCK_INIT) {
+ DPRINTF("sock_execmsg: %p: HELLO, bad state\n", f);
+ aproc_del(f->pipe.file.rproc);
+ return 0;
+ }
+ if (!sock_hello(f)) {
+ aproc_del(f->pipe.file.rproc);
+ return 0;
+ }
+ AMSG_INIT(m);
+ m->cmd = AMSG_ACK;
+ f->rstate = SOCK_RRET;
+ f->rtodo = sizeof(struct amsg);
+ break;
default:
DPRINTF("sock_execmsg: %p bogus command\n", f);
aproc_del(f->pipe.file.rproc);