1 /* $OpenBSD: amsg.h,v 1.2 2011/04/28 06:19:57 ratchov Exp $ */ 2 /* 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 #ifndef AMSG_H 18 #define AMSG_H 19 20 #include <stdint.h> 21 22 /* 23 * socket and option names 24 */ 25 #define AUCAT_PATH "aucat" 26 #define AUCAT_PORT 11025 27 #define MIDICAT_PATH "midicat" 28 #define MIDICAT_PORT 11041 29 #define DEFAULT_OPT "default" 30 31 /* 32 * WARNING: since the protocol may be simultaneously used by static 33 * binaries or by different versions of a shared library, we are not 34 * allowed to change the packet binary representation in a backward 35 * incompatible way. 36 * 37 * Especially, make sure the amsg_xxx structures are not larger 38 * than 32 bytes. 39 */ 40 struct amsg { 41 #define AMSG_ACK 0 /* ack for START/STOP */ 42 #define AMSG_GETPAR 1 /* get the current parameters */ 43 #define AMSG_SETPAR 2 /* set the current parameters */ 44 #define AMSG_START 3 /* request the server to start the stream */ 45 #define AMSG_STOP 4 /* request the server to stop the stream */ 46 #define AMSG_DATA 5 /* data block */ 47 #define AMSG_POS 6 /* initial position */ 48 #define AMSG_MOVE 7 /* position changed */ 49 #define AMSG_SETVOL 9 /* set volume */ 50 #define AMSG_HELLO 10 /* say hello, check versions and so ... */ 51 #define AMSG_BYE 11 /* ask server to drop connection */ 52 #define AMSG_AUTH 12 /* send authentication cookie */ 53 uint32_t cmd; 54 uint32_t __pad; 55 union { 56 struct amsg_par { 57 uint8_t legacy_mode; /* compat for old libs */ 58 uint8_t xrun; /* one of above */ 59 uint8_t bps; /* bytes per sample */ 60 uint8_t bits; /* actually used bits */ 61 uint8_t msb; /* 1 if MSB justified */ 62 uint8_t le; /* 1 if little endian */ 63 uint8_t sig; /* 1 if signed */ 64 uint8_t __pad1; 65 uint16_t pchan; /* play channels */ 66 uint16_t rchan; /* record channels */ 67 uint32_t rate; /* frames per second */ 68 uint32_t bufsz; /* total buffered frames */ 69 uint32_t round; 70 uint32_t appbufsz; /* client side bufsz */ 71 uint32_t _reserved[1]; /* for future use */ 72 } par; 73 struct amsg_data { 74 #define AMSG_DATAMAX 0x1000 75 uint32_t size; 76 } data; 77 struct amsg_ts { 78 int32_t delta; 79 } ts; 80 struct amsg_vol { 81 uint32_t ctl; 82 } vol; 83 struct amsg_hello { 84 uint16_t mode; /* bitmap of MODE_XXX */ 85 #define AMSG_VERSION 5 86 uint8_t version; /* protocol version */ 87 uint8_t reserved1[5]; /* for future use */ 88 char opt[12]; /* profile name */ 89 char who[12]; /* hint for leases */ 90 } hello; 91 struct amsg_auth { 92 #define AMSG_COOKIELEN 16 93 uint8_t cookie[AMSG_COOKIELEN]; 94 } auth; 95 } u; 96 }; 97 98 /* 99 * Initialize an amsg structure: fill all fields with 0xff, so the read 100 * can test which fields were set. 101 */ 102 #define AMSG_INIT(m) do { memset((m), 0xff, sizeof(struct amsg)); } while (0) 103 104 /* 105 * Since the structure is memset to 0xff, the MSB can be used to check 106 * if any field was set. 107 */ 108 #define AMSG_ISSET(x) (((x) & (1 << (8 * sizeof(x) - 1))) == 0) 109 110 #endif /* !defined(AMSG_H) */ 111