spandsp  3.1.1
private/v150_1.h
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * private/v150_1.h - An implementation of V.150.1.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2022 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2, as
14  * published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 #if !defined(_SPANDSP_PRIVATE_V150_1_H_)
27 #define _SPANDSP_PRIVATE_V150_1_H_
28 
29 #if defined(_WIN32)
30 /* <windows.h> (minwindef.h) defines the legacy 16 bit memory model keywords
31  "near" and "far" as empty macros. Left in place, they strip the names from
32  the near and far members of v150_1_state_s, making them anonymous structs.
33  MSVC then flattens their contents into the enclosing struct, where the two
34  "parms" members collide (error C2020: 'parms': 'struct' member
35  redefinition). Both macros are restored at the end of this header, so an
36  including application keeps whatever it had. */
37 #pragma push_macro("near")
38 #pragma push_macro("far")
39 #undef near
40 #undef far
41 #endif
42 
43 /*
44  telephone network
45  ^
46  |
47  |
48  v
49  +-----------------------------------+
50  | |
51  | Signal processing entity (SPE) |
52  | |
53  +-----------------------------------+
54  | ^
55  | |
56  Signal list 1 | | Signal list 2
57  | |
58  v |
59  +-----------------------------------+ Signal list 5 +-----------------------------------+
60  | | ----------------------->| |
61  | SSE protocol state machine (P) | | Gateway state machine (s,s') |
62  | |<------------------------| |
63  +-----------------------------------+ Signal list 6 +-----------------------------------+
64  | ^
65  | |
66  Signal list 3 | | Signal list 4
67  | |
68  v |
69  +-----------------------------------+
70  | |
71  | IP network processor |
72  | |
73  +-----------------------------------+
74  ^
75  |
76  |
77  v
78  IP network
79 */
80 
81 enum V150_1_SIGNAL_e
82 {
83  /* Signal list 1 - SPE to SSE protocol state engine */
84 
85  /* SPE has detected 2100Hz tone for a duration less than 50ms */
86  V150_1_SIGNAL_TONE_2100HZ = 1,
87  /* SPE has detected 2225Hz tone for a duration less than 50ms */
88  V150_1_SIGNAL_TONE_2225HZ,
89  /* SPE has verified presence of V.25 ANS type answer tone */
90  V150_1_SIGNAL_ANS,
91  /* SPE has detected a 180-degree phase reversal in a verified ANS type answer tone */
92  V150_1_SIGNAL_ANS_PR,
93  /* SPE has verified presence of V.8 ANSam type answer tone */
94  V150_1_SIGNAL_ANSAM,
95  /* SPE has detected a 180-degree phase reversal in a verified ANSam type answer tone */
96  V150_1_SIGNAL_ANSAM_PR,
97  /* SPE has detected a V.8 CI signal */
98  V150_1_SIGNAL_CI,
99  /* SPE has detected a V.8 CM signal */
100  V150_1_SIGNAL_CM,
101  /* SPE has detected a V.8 JM signal */
102  V150_1_SIGNAL_JM,
103  /* SPE has detected a V.21 low channel signal */
104  V150_1_SIGNAL_V21_LOW,
105  /* SPE has detected a V.21 high channel signal */
106  V150_1_SIGNAL_V21_HIGH,
107  /* SPE has detected a V.23 low channel signal */
108  V150_1_SIGNAL_V23_LOW,
109  /* SPE has detected a V.23 high channel signal */
110  V150_1_SIGNAL_V23_HIGH,
111  /* SPE has detected a V.22bis scrambled binary one's signal */
112  V150_1_SIGNAL_SB1,
113  /* SPE has detected a V.22bis unscrambled binary one's signal */
114  V150_1_SIGNAL_USB1,
115  /* SPE has detected a V.22bis S1 signal */
116  V150_1_SIGNAL_S1,
117  /* SPE has detected a V.32/V.32bis AA signal */
118  V150_1_SIGNAL_AA,
119  /* SPE has detected a V.32/V.32bis AC signal */
120  V150_1_SIGNAL_AC,
121  /* Call discrimination time-out */
122  V150_1_SIGNAL_CALL_DISCRIMINATION_TIMEOUT,
123  /* SPE has detected an unknown or unsupported signal */
124  V150_1_SIGNAL_UNKNOWN,
125  /* SPE has detected silence */
126  V150_1_SIGNAL_SILENCE,
127  /* SPE has initiated an abort request */
128  V150_1_SIGNAL_ABORT,
129 
130  /* Signal list 2 - SSE protocol state engine to SPE */
131 
132  /* SPE requested to generate a V.25 ANS type answer tone signal */
133  V150_1_SIGNAL_ANS_GEN,
134  /* SPE requested to generate a V.25 ANS type answer tone signal with 180-degree phase reversals every 450 ms */
135  V150_1_SIGNAL_ANS_PR_GEN,
136  /* SPE requested to generate a V.8 ANSam type answer tone signal */
137  V150_1_SIGNAL_ANSAM_GEN,
138  /* SPE requested to generate a V.8 ANSam type answer tone signal with 180-degree phase reversals every 450 ms */
139  V150_1_SIGNAL_ANSAM_PR_GEN,
140  /* SPE requested to generate a 2225Hz tone */
141  V150_1_SIGNAL_2225HZ_GEN,
142  /* SPE requested to prevent any modem signal to be output to the telephony side of the gateway */
143  V150_1_SIGNAL_CONCEAL_MODEM,
144  /* SPE requested to block 2100Hz tone */
145  V150_1_SIGNAL_BLOCK_2100HZ_TONE,
146  /* SPE requested to enable automode function */
147  V150_1_SIGNAL_AUTOMODE_ENABLE,
148 
149  /* Signal list 3 - SSE protocol state engine to IP network */
150 
151  /* Send audio state with reason code */
152  V150_1_SIGNAL_AUDIO_GEN,
153  /* Send facsimile relay state with reason code */
154  V150_1_SIGNAL_FAX_RELAY_GEN,
155  /* Send indeterminate state with reason code */
156  V150_1_SIGNAL_INDETERMINATE_GEN,
157  /* Send modem relay state with reason code */
158  V150_1_SIGNAL_MODEM_RELAY_GEN,
159  /* Send text relay state with reason code */
160  V150_1_SIGNAL_TEXT_RELAY_GEN,
161  /* Send VBD state with reason code */
162  V150_1_SIGNAL_VBD_GEN,
163  /* Send RFC4733 ANS event */
164  V150_1_SIGNAL_RFC4733_ANS_GEN,
165  /* Send RFC4733 ANS with phase reversals event */
166  V150_1_SIGNAL_RFC4733_ANS_PR_GEN,
167  /* Send RFC4733 ANSam event */
168  V150_1_SIGNAL_RFC4733_ANSAM_GEN,
169  /* Send RFC4733 ANSam with phase reversals event */
170  V150_1_SIGNAL_RFC4733_ANSAM_PR_GEN,
171  /* Send RFC4733 tone */
172  V150_1_SIGNAL_RFC4733_TONE_GEN,
173 
174  /* Signal list 4 - IP network to SSE protocol state engine */
175 
176  /* Audio state detected with reason code */
177  V150_1_SIGNAL_AUDIO,
178  /* Facsimile relay state detected with reason code */
179  V150_1_SIGNAL_FAX_RELAY,
180  /* Indeterminate state detected with reason code */
181  V150_1_SIGNAL_INDETERMINATE,
182  /* Modem relay state detected with reason code */
183  V150_1_SIGNAL_MODEM_RELAY,
184  /* Text relay state detected with reason code */
185  V150_1_SIGNAL_TEXT_RELAY,
186  /* VBD state detected with reason code */
187  V150_1_SIGNAL_VBD,
188  /* An RFC4733 ANS event detected with reason code */
189  V150_1_SIGNAL_RFC4733_ANS,
190  /* An RFC4733 ANS with phase reversals event detected */
191  V150_1_SIGNAL_RFC4733_ANS_PR,
192  /* An RFC4733 ANSam event detected */
193  V150_1_SIGNAL_RFC4733_ANSAM,
194  /* An RFC4733 ANSam with phase reversals event detected */
195  V150_1_SIGNAL_RFC4733_ANSAM_PR,
196  /* An RFC4733 tone detected */
197  V150_1_SIGNAL_RFC4733_TONE,
198 
199  /* Lists 5 and 6 have the same contents */
200  /* Signal list 5 - SSE protocol state engine to gateway */
201  /* Signal list 6 - Gateway to SSE protocol state engine */
202 
203  /* Audio state */
204  V150_1_SIGNAL_AUDIO_STATE,
205  /* Facsimile relay state */
206  V150_1_SIGNAL_FAX_RELAY_STATE,
207  /* Indeterminate state */
208  V150_1_SIGNAL_INDETERMINATE_STATE,
209  /* Modem relay state */
210  V150_1_SIGNAL_MODEM_RELAY_STATE,
211  /* Text relay state */
212  V150_1_SIGNAL_TEXT_RELAY_STATE,
213  /* VBD state */
214  V150_1_SIGNAL_VBD_STATE,
215 
216  /* Signal not listed in V.150.1 */
217  V150_1_SIGNAL_CALL_DISCRIMINATION_TIMER_EXPIRED
218 };
219 
220 typedef struct
221 {
222  v150_1_cdscselect_t cdscselect;
223  v150_1_modem_relay_gateway_type_t modem_relay_gateway_type;
224 
225  bool v42_lapm_supported;
226  /* Annex A was removed from the V.42 spec. in 2002, so it won't be supported. */
227  bool v42_annex_a_supported;
228  bool v42bis_supported;
229  bool v44_supported;
230  bool mnp5_supported;
231 
232  int ecp;
233  bool necrxch_option;
234  bool ecrxch_option;
235  bool xid_profile_exchange_supported;
236  bool asymmetric_data_types_supported;
237  bool dlci_supported;
238  bool i_raw_bit_supported;
239  bool i_char_stat_supported;
240  bool i_char_dyn_supported;
241  bool i_frame_supported;
242  bool i_octet_cs_supported;
243  bool i_char_stat_cs_supported;
244  bool i_char_dyn_cs_supported;
245 
246  bool i_raw_bit_available;
247  bool i_frame_available;
248  bool i_octet_with_dlci_available;
249  bool i_octet_without_dlci_available;
250  bool i_char_stat_available;
251  bool i_char_dyn_available;
252  bool i_octet_cs_available;
253  bool i_char_stat_cs_available;
254  bool i_char_dyn_cs_available;
255 
256  uint16_t compression_tx_dictionary_size;
257  uint16_t compression_rx_dictionary_size;
258  uint8_t compression_tx_string_length;
259  uint8_t compression_rx_string_length;
260  uint16_t compression_tx_history_size;
261  uint16_t compression_rx_history_size;
262 
263  bool jm_category_id_seen[16];
264  uint16_t jm_category_info[16];
265 
266  uint16_t v42bis_p0; /* directions */
267  uint16_t v42bis_p1; /* codewords */
268  uint16_t v42bis_p2; /* string size */
269  uint16_t v44_c0; /* capability */
270  uint16_t v44_p0; /* directions */
271  uint16_t v44_p1t; /* tx_dictionary_size */
272  uint16_t v44_p1r; /* rx_dictionary_size */
273  uint16_t v44_p2t; /* tx_string_size */
274  uint16_t v44_p2r; /* rx_string_size */
275  uint16_t v44_p3t; /* tx_history_size */
276  uint16_t v44_p3r; /* rx_history_size */
277 
278  uint16_t selected_compression_direction;
279  uint16_t selected_compression;
280  uint16_t selected_error_correction;
281 
282  /* Data link connection identifier */
283  uint16_t dlci;
284 
285  /* Sequence number for the information packets which contain a transmitted character sequence number */
286  uint16_t octet_cs_next_seq_no;
287  /* The data format for asynchronous data characters - data bits, parity and stop bits */
288  uint8_t data_format_code;
289 
290  /* Selected modulation scheme */
291  uint16_t selmod;
292  /* Transmit symbol rate enable */
293  bool txsen;
294  /* Receive symbol rate enable */
295  bool rxsen;
296  /* Transmit data signalling rate */
297  uint16_t tdsr;
298  /* Receive data signalling rate */
299  uint16_t rdsr;
300  /* Physical layer transmitter symbol rate */
301  uint16_t txsr;
302  /* Physical layer receiver symbol rate */
303  uint16_t rxsr;
304 
305  bool busy;
306 
307  int sprt_subsession_id;
308  uint8_t sprt_payload_type;
309 
310  int connection_state;
311  int cleardown_reason;
313 
315 {
316  v150_1_rx_data_handler_t rx_data_handler;
317  void *rx_data_handler_user_data;
318  v150_1_rx_status_report_handler_t rx_status_report_handler;
319  void *rx_status_report_user_data;
320  v150_1_spe_signal_handler_t spe_signal_handler;
321  void *spe_signal_handler_user_data;
322  v150_1_timer_handler_t timer_handler;
323  void *timer_user_data;
324 
325  v150_1_cdscselect_t cdscselect;
326  /* True if RFC4733 is preferred */
327  bool rfc4733_preferred;
328  int call_discrimination_timeout;
329 
330  /* The current media state of the local node (i.e., the value that will be sent to the remote
331  node in the event field of an SSE message) */
332  uint8_t local_media_state; /* See V.150.1 C.4.3.1 */
333  /* The last known media state of the remote node, as known by the local node (i.e. the value
334  that will be sent to the remote node in the remote media state field of an SSE extension
335  field with explicit acknowledgement) */
336  uint8_t remote_media_state; /* See V.150.1 C.4.3.1 */
337  /* The last known mode of the local node known by the remote node, as known by the local node
338  (i.e., the value that was received from the remote node in the remote media state field of
339  an SSE extension field with explicit acknowledgement) */
340  uint8_t remote_ack; /* See V.150.1 C.4.3.1 */
341 
342  struct
343  {
344  v150_1_near_far_t parms;
345 
346  int8_t info_msg_preferences[10];
347 
348  /* The maximum packet lengths we may generate. These vary with the channel number when using SPRT
349  as the transport. So, we hold a length for each SPRT protocol channel ID. */
350  int max_payload_bytes[SPRT_CHANNELS];
351 
352  /* The channel to be used for info packets */
353  uint16_t info_stream_channel;
354  /* The message ID to be used for info packets */
355  uint16_t info_stream_msg_id;
356  } near;
357  struct
358  {
359  v150_1_near_far_t parms;
360 
361  int break_source;
362  int break_type;
363  int break_duration;
364  } far;
365  int joint_connection_state;
366 
367  v150_1_sse_state_t sse;
368  sprt_state_t sprt;
369 
370  span_timestamp_t latest_timer;
371  span_timestamp_t call_discrimination_timer;
372  span_timestamp_t sse_timer;
373  span_timestamp_t sprt_timer;
374  /*! \brief Error and flow logging control */
376 };
377 
378 #if defined(_WIN32)
379 #pragma pop_macro("far")
380 #pragma pop_macro("near")
381 #endif
382 
383 #endif
384 /*- End of file ------------------------------------------------------------*/
Definition: private/logging.h:34
Definition: private/sprt.h:96
Definition: private/v150_1.h:221
Definition: private/v150_1_sse.h:32
Definition: private/v150_1.h:315
logging_state_t logging
Error and flow logging control.
Definition: private/v150_1.h:375