1 /* $OpenBSD: amsg.h,v 1.10 2016/01/09 08:27:24 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 * unix-domain socket name is: 24 * 25 * DIR [ '-' UID ] '/' FILE UNIT 26 * 27 * example: "/tmp/aucat-1000/aucat0" 28 * 29 */ 30 #define SOCKPATH_DIR "/tmp/aucat" 31 #define SOCKPATH_FILE "aucat" 32 #define SOCKPATH_MAX (1 + \ 33 sizeof(SOCKPATH_DIR) - 1 + \ 34 sizeof(char) + \ 35 sizeof(int) * 3 + \ 36 sizeof(char) + \ 37 sizeof(SOCKPATH_FILE) - 1 + \ 38 sizeof(int) * 3) 39 40 /* 41 * server TCP base port number 42 */ 43 #define AUCAT_PORT 11025 44 45 /* 46 * WARNING: since the protocol may be simultaneously used by static 47 * binaries or by different versions of a shared library, we are not 48 * allowed to change the packet binary representation in a backward 49 * incompatible way. 50 * 51 * Especially, make sure the amsg_xxx structures are not larger 52 * than 32 bytes. 53 */ 54 struct amsg { 55 #define AMSG_ACK 0 /* ack for START/STOP */ 56 #define AMSG_GETPAR 1 /* get the current parameters */ 57 #define AMSG_SETPAR 2 /* set the current parameters */ 58 #define AMSG_START 3 /* request the server to start the stream */ 59 #define AMSG_STOP 4 /* request the server to stop the stream */ 60 #define AMSG_DATA 5 /* data block */ 61 #define AMSG_FLOWCTL 6 /* feedback about buffer usage */ 62 #define AMSG_MOVE 7 /* position changed */ 63 #define AMSG_SETVOL 9 /* set volume */ 64 #define AMSG_HELLO 10 /* say hello, check versions and so ... */ 65 #define AMSG_BYE 11 /* ask server to drop connection */ 66 #define AMSG_AUTH 12 /* send authentication cookie */ 67 uint32_t cmd; 68 uint32_t __pad; 69 union { 70 struct amsg_par { 71 uint8_t legacy_mode; /* compat for old libs */ 72 uint8_t xrun; /* one of above */ 73 uint8_t bps; /* bytes per sample */ 74 uint8_t bits; /* actually used bits */ 75 uint8_t msb; /* 1 if MSB justified */ 76 uint8_t le; /* 1 if little endian */ 77 uint8_t sig; /* 1 if signed */ 78 uint8_t __pad1; 79 uint16_t pchan; /* play channels */ 80 uint16_t rchan; /* record channels */ 81 uint32_t rate; /* frames per second */ 82 uint32_t bufsz; /* total buffered frames */ 83 uint32_t round; 84 uint32_t appbufsz; /* client side bufsz */ 85 uint32_t _reserved[1]; /* for future use */ 86 } par; 87 struct amsg_data { 88 #define AMSG_DATAMAX 0x1000 89 uint32_t size; 90 } data; 91 struct amsg_ts { 92 int32_t delta; 93 } ts; 94 struct amsg_vol { 95 uint32_t ctl; 96 } vol; 97 struct amsg_hello { 98 uint16_t mode; /* bitmap of MODE_XXX */ 99 #define AMSG_VERSION 7 100 uint8_t version; /* protocol version */ 101 uint8_t devnum; /* device number */ 102 uint32_t _reserved[1]; /* for future use */ 103 #define AMSG_OPTMAX 12 104 char opt[AMSG_OPTMAX]; /* profile name */ 105 char who[12]; /* hint for leases */ 106 } hello; 107 struct amsg_auth { 108 #define AMSG_COOKIELEN 16 109 uint8_t cookie[AMSG_COOKIELEN]; 110 } auth; 111 } u; 112 }; 113 114 /* 115 * Initialize an amsg structure: fill all fields with 0xff, so the read 116 * can test which fields were set. 117 */ 118 #define AMSG_INIT(m) do { memset((m), 0xff, sizeof(struct amsg)); } while (0) 119 120 /* 121 * Since the structure is memset to 0xff, the MSB can be used to check 122 * if any field was set. 123 */ 124 #define AMSG_ISSET(x) (((x) & (1 << (8 * sizeof(x) - 1))) == 0) 125 126 #endif /* !defined(AMSG_H) */ 127