adsp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /******************************************************************************
  2. adsp.h
  3. This file is part of the lpstyl package.
  4. Copyright (C) 1996-2000 Monroe Williams (monroe@pobox.com)
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. 1. Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. ******************************************************************************/
  25. #include <machine/endian.h>
  26. struct adsphdr {
  27. u_int16_t src_conn_id;
  28. u_int32_t first_byte_seq;
  29. u_int32_t next_rcv_seq;
  30. u_int16_t rcv_window;
  31. u_int8_t flags;
  32. } __attribute__((packed));
  33. struct adsp_data
  34. {
  35. char data[572];
  36. } __attribute__((packed));
  37. struct adsp_attn_data
  38. {
  39. u_int16_t code;
  40. char data[570];
  41. } __attribute__((packed));
  42. struct adsp_cntl_data
  43. {
  44. u_int16_t version;
  45. u_int16_t dst_conn_id;
  46. u_int32_t attn_rcv_seq;
  47. } __attribute__((packed));
  48. struct adsp_cntl_packet
  49. {
  50. struct adsphdr hdr;
  51. struct adsp_cntl_data data;
  52. } __attribute__((packed));
  53. struct adsp_attn_packet
  54. {
  55. struct adsphdr hdr;
  56. struct adsp_attn_data data;
  57. } __attribute__((packed));
  58. struct adsp_packet
  59. {
  60. struct adsphdr hdr;
  61. char data[572];
  62. } __attribute__((packed));
  63. #ifndef DDPTYPE_ADSP
  64. #define DDPTYPE_ADSP 7
  65. #endif
  66. enum
  67. {
  68. ADSP_VERSION = 0x0100,
  69. SZ_ADSPHDR = 13,
  70. ADSPOP_MASK = 0x0F,
  71. ADSPOP_PROBE_ACK = 0x00,
  72. ADSPOP_OPEN_REQ = 0x01,
  73. ADSPOP_OPEN_ACK = 0x02,
  74. ADSPOP_OPEN_REQ_ACK = 0x03,
  75. ADSPOP_OPEN_NAK = 0x04,
  76. ADSPOP_CLOSE = 0x05,
  77. ADSPOP_RESET_REQ = 0x06,
  78. ADSPOP_RESET_ACK = 0x07,
  79. ADSPOP_RETRANS = 0x08,
  80. ADSPFLAG_CONTROL = 0x80,
  81. ADSPFLAG_ACK = 0x40,
  82. ADSPFLAG_EOM = 0x20,
  83. ADSPFLAG_ATTN = 0x10,
  84. ADSP_RECV_BUFFER_SIZE = 2048,
  85. ADSP_ATTN_BUFFER_SIZE = 570,
  86. ADSP_MAX_DATA_SIZE = 572,
  87. ADSP_STATE_CLOSED = 0,
  88. ADSP_STATE_OPEN_SENT,
  89. ADSP_STATE_OPEN_RCVD,
  90. ADSP_STATE_OPEN,
  91. ADSP_STATE_HALF_CLOSED
  92. };
  93. /* State for an ADSP socket. */
  94. struct adsp_socket
  95. {
  96. int socket;
  97. struct sockaddr_at local_addr;
  98. u_int16_t lastConnID;
  99. };
  100. /* Endpoint state for an ADSP connection. */
  101. struct adsp_endp
  102. {
  103. /* connection state */
  104. struct adsp_socket *local_socket;
  105. struct sockaddr_at remote_addr;
  106. u_int16_t connID;
  107. u_int16_t remote_connID;
  108. u_int16_t state;
  109. /* sequencing variables */
  110. u_int32_t send_seq; /* next byte to transmit */
  111. u_int32_t oldest_seq; /* oldest byte in local send queue */
  112. u_int32_t rmt_window_seq; /* last byte of remote window */
  113. u_int32_t recv_seq; /* next byte to receive */
  114. u_int32_t recv_window; /* local window size */
  115. /* receive ring buffer */
  116. char recv_buffer[ADSP_RECV_BUFFER_SIZE];
  117. int recv_next_input;
  118. int recv_next_output;
  119. /* attention message handling */
  120. u_int32_t attn_send_seq; /* next outgoing sequence number */
  121. u_int32_t attn_recv_seq; /* next incoming sequence number */
  122. int attn_valid; /* true if an attention message is pending. */
  123. char attn_buffer[ADSP_ATTN_BUFFER_SIZE];
  124. int attn_size; /* length of the message in the buffer */
  125. u_int16_t attn_code; /* code on this message */
  126. };
  127. int adsp_open_socket(struct adsp_socket *s);
  128. int adsp_close_socket(struct adsp_socket *s);
  129. int adsp_connect( struct adsp_socket *s,
  130. struct adsp_endp *endp,
  131. char *name);
  132. int adsp_disconnect(struct adsp_endp *endp);
  133. int adsp_listen(struct adsp_socket *s,
  134. struct adsp_endp *endp);
  135. int adsp_accept(struct adsp_endp *endp);
  136. int adsp_idle(struct adsp_endp *endp);
  137. int adsp_read(struct adsp_endp *endp, char *data, int len);
  138. int adsp_read_nonblock(struct adsp_endp *endp, char *data, int len);
  139. int adsp_write(struct adsp_endp *endp, char *data, int len);
  140. /* There must be at least ADSP_RECV_BUFFER_SIZE bytes at *data to receive
  141. the message.
  142. */
  143. int adsp_read_attn(struct adsp_endp *endp, u_int16_t *code, char *data);
  144. int adsp_write_attn(struct adsp_endp *endp,
  145. u_int16_t code,
  146. char *data,
  147. int len);
  148. int adsp_fwd_reset(struct adsp_endp *endp);