1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH mod_spandsp.
18  *
19  * The Initial Developer of the Original Code is
20  * Massimo Cetra <devel@navynet.it>
21  *
22  * Portions created by the Initial Developer are Copyright (C)
23  * the Initial Developer. All Rights Reserved.
24  *
25  * Contributor(s):
26  *
27  * Brian West <brian@freeswitch.org>
28  * Anthony Minessale II <anthm@freeswitch.org>
29  * Steve Underwood <steveu@coppice.org>
30  * Antonio Gallo <agx@linux.it>
31  * mod_spandsp.h -- applications provided by SpanDSP
32  *
33  */
34 
35 #include <switch.h>
36 
37 #ifdef WIN32
38 #define FAX_INVALID_SOCKET INVALID_HANDLE_VALUE
39 typedef HANDLE zap_socket_t;
40 #else
41 #define FAX_INVALID_SOCKET -1
42 typedef int zap_socket_t;
43 #endif
44 
45 #define MY_EVENT_TDD_SEND_MESSAGE "TDD::SEND_MESSAGE"
46 #define MY_EVENT_TDD_RECV_MESSAGE "TDD::RECV_MESSAGE"
47 
48 #define MAX_MODEMS 1024
49 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
50 #include <spandsp.h>
51 
52 #define SPANDSP_EVENT_TXFAXRESULT "spandsp::txfaxresult"
53 #define SPANDSP_EVENT_RXFAXRESULT "spandsp::rxfaxresult"
54 
55 #define SPANDSP_EVENT_TXFAXPAGERESULT "spandsp::txfaxpageresult"
56 #define SPANDSP_EVENT_RXFAXPAGERESULT "spandsp::rxfaxpageresult"
57 
58 #define SPANDSP_EVENT_TXFAXNEGOCIATERESULT "spandsp::txfaxnegociateresult"
59 #define SPANDSP_EVENT_RXFAXNEGOCIATERESULT "spandsp::rxfaxnegociateresult"
60 
61 
62 
63 /* The global stuff */
64 struct spandsp_globals {
65 	switch_memory_pool_t *pool;
66 	switch_memory_pool_t *config_pool;
67 	switch_mutex_t *mutex;
68 
69 	uint32_t total_sessions;
70 
71 	short int use_ecm;
72 	short int verbose;
73 	short int disable_v17;
74 	short int enable_tep;
75 	short int enable_colour_fax;
76 	short int enable_image_resizing;
77 	short int enable_colour_to_bilevel;
78 	short int enable_grayscale_to_bilevel;
79 	short int enable_t38;
80 	short int enable_t38_request;
81 	short int enable_t38_insist;
82 	char *ident;
83 	char *header;
84 	char *timezone;
85 	char *prepend_string;
86 	char *spool;
87 	switch_thread_cond_t *cond;
88 	switch_mutex_t *cond_mutex;
89 	int modem_count;
90 	int modem_verbose;
91 	char *modem_context;
92 	char *modem_dialplan;
93 	char *modem_directory;
94 	switch_hash_t *tones;
95 	int tonedebug;
96     int t38_tx_reinvite_packet_count;
97     int t38_rx_reinvite_packet_count;
98 };
99 
100 extern struct spandsp_globals spandsp_globals;
101 
102 
103 typedef enum {
104 	FUNCTION_TX,
105 	FUNCTION_RX,
106 	FUNCTION_GW
107 } mod_spandsp_fax_application_mode_t;
108 
109 /******************************************************************************
110  * TONE DETECTION WITH CADENCE
111  */
112 
113 #define MAX_TONES 128
114 #define STRLEN 128
115 /**
116  * Tone descriptor
117  *
118  * Defines a set of tones to look for
119  */
120 struct tone_descriptor {
121 	/** The name of this descriptor set */
122 	const char *name;
123 
124 	/** Describes the tones to watch */
125 	super_tone_rx_descriptor_t *spandsp_tone_descriptor;
126 
127 	/** The mapping of tone id to key */
128 	char tone_keys[MAX_TONES][STRLEN];
129 	int idx;
130 
131 };
132 typedef struct tone_descriptor tone_descriptor_t;
133 
134 
135 switch_status_t tone_descriptor_create(tone_descriptor_t **descriptor, const char *name, switch_memory_pool_t *memory_pool);
136 void tone_descriptor_destroy(tone_descriptor_t *descriptor);
137 int tone_descriptor_add_tone(tone_descriptor_t *descriptor, const char *name);
138 switch_status_t tone_descriptor_add_tone_element(tone_descriptor_t *descriptor, int tone_id, int freq1, int freq2, int min, int max);
139 
140 
141 void mod_spandsp_fax_load(switch_memory_pool_t *pool);
142 switch_status_t mod_spandsp_codecs_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool);
143 switch_status_t mod_spandsp_dsp_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool);
144 
145 void mod_spandsp_fax_shutdown(void);
146 void mod_spandsp_dsp_shutdown(void);
147 
148 void mod_spandsp_fax_event_handler(switch_event_t *event);
149 void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *data, mod_spandsp_fax_application_mode_t app_mode);
150 void mod_spandsp_fax_stop_fax(switch_core_session_t *session);
151 switch_bool_t t38_gateway_start(switch_core_session_t *session, const char *app, const char *data);
152 
153 switch_status_t spandsp_stop_inband_dtmf_session(switch_core_session_t *session);
154 switch_status_t spandsp_inband_dtmf_session(switch_core_session_t *session);
155 
156 switch_status_t callprogress_detector_start(switch_core_session_t *session, const char *name);
157 switch_status_t callprogress_detector_stop(switch_core_session_t *session);
158 
159 switch_status_t spandsp_fax_detect_session(switch_core_session_t *session,
160 														   const char *flags, int timeout, int tone_type,
161 														   int hits, const char *app, const char *data, switch_tone_detect_callback_t callback);
162 
163 switch_status_t spandsp_fax_stop_detect_session(switch_core_session_t *session);
164 void mod_spandsp_log_message(void *session, int level, const char *msg);
165 switch_status_t load_configuration(switch_bool_t reload);
166 void mod_spandsp_indicate_data(switch_core_session_t *session, switch_bool_t self, switch_bool_t on);
167 
168 switch_status_t spandsp_stop_tdd_encode_session(switch_core_session_t *session);
169 switch_status_t spandsp_tdd_encode_session(switch_core_session_t *session, const char *text);
170 
171 
172 switch_status_t spandsp_stop_tdd_decode_session(switch_core_session_t *session);
173 switch_status_t spandsp_tdd_decode_session(switch_core_session_t *session);
174 switch_status_t spandsp_tdd_send_session(switch_core_session_t *session, const char *text);
175 
176 /* For Emacs:
177  * Local Variables:
178  * mode:c
179  * indent-tabs-mode:t
180  * tab-width:4
181  * c-basic-offset:4
182  * End:
183  * For VIM:
184  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
185  */
186