libsangoma  1
sangoma_interface.h
Go to the documentation of this file.
1 /*******************************************************************************/
36 #ifndef SANGOMA_INTERFACE_H
37 #define SANGOMA_INTERFACE_H
38 
39 #include <stdio.h>
40 #include <stddef.h> //for offsetof()
41 #include <stdlib.h>
42 
43 #if defined(__WINDOWS__)
44 # include <windows.h>
45 # include <winioctl.h>
46 # include <conio.h>
47 # include "bit_win.h"
48 # include "wanpipe_time.h" //for wp_usleep()
49 
50 #elif defined(__LINUX__)
51 
52 /* Include headers */
53 # include <stddef.h>
54 # include <errno.h>
55 # include <fcntl.h>
56 # include <string.h>
57 # include <ctype.h>
58 # include <sys/stat.h>
59 # include <sys/ioctl.h>
60 # include <sys/types.h>
61 # include <dirent.h>
62 # include <unistd.h>
63 # include <sys/socket.h>
64 # include <netdb.h>
65 # include <sys/un.h>
66 # include <sys/wait.h>
67 # include <unistd.h>
68 # include <signal.h>
69 # include <time.h>
70 #else
71 # error "sangoma_interface.h: undefined OS type"
72 #endif
73 
74 /*
75  * FSK CallerID and DTMF detection note:
76  * Stelephony.dll expects input BitStream (aLaw or uLaw audio) from a SINGLE timeslot.
77  * It is always the case for Analog cards, but not for the Digital cards, where
78  * API may provide input from a SINGLE or from MULTIPLE timeslots.
79  */
80 #define USE_STELEPHONY_API 1 /* set to zero if don't need to compile
81  function calls to libstelephony.dll */
82 
83 #include "wanpipe_api.h"
84 #include "sangoma_cthread.h"
85 #include "sample.h"
86 
87 #include "libsangoma.h"
88 
89 #if USE_STELEPHONY_API
90 # include "libstelephony.h"
91 #endif
92 
93 /* sangoma_waitfor_many() can wait on an array of sangoma wait objects.
94  * In this example there is a single object in the array. */
95 #define SANGOMA_INTERFACE_NUMBER_OF_WAIT_OBJECTS 1
96 #define SANGOMA_TX_WAIT_OBJECT 0
97 #define SANGOMA_RX_AND_EVENT_WAIT_OBJECT 0
98 
99 
104 class sangoma_interface : public sangoma_cthread
105 {
106 protected:
109 
111  sangoma_wait_obj_t *sng_wait_obj[SANGOMA_INTERFACE_NUMBER_OF_WAIT_OBJECTS];
112 
114  //receive stuff
119  //for counting frames with CRC/Abort errors
124 
126  //transmit stuff
133 
135  //IOCTL management structures and variables
138 
140  unsigned char get_wan_udphdr_data_byte(unsigned char off);
141 
143  unsigned char *get_wan_udphdr_data_ptr(unsigned char off);
144 
146  unsigned char set_wan_udphdr_data_byte(unsigned char off, unsigned char data);
147 
153  unsigned char adapter_type;
154 
157 
160 
162  void RxThreadFunc();
164  void TxThreadFunc();
165 
167  int read_data();
169  virtual int read_event();
170 
171  int write_data(wp_api_hdr_t *hdr, void *tx_buffer);
172 
174  void cleanup();
175 
177  int get_wan_config();
178 
180  int get_interface_configuration(if_cfg_t *wanif_conf_ptr);
181 
183  int get_fe_type(unsigned char* adapter_type);
184 
186  int wanpipe_api_ioctl(wan_cmd_api_t *api_cmd);
187 
189  unsigned char wp_brt[256];
190 
192  void generate_bit_rev_table();
193 
196 
197 #if USE_STELEPHONY_API
198 
199  stelephony_callback_functions_t scf;
200  void *stelObj;
201  void *DtmfBuffer;
202  void *FskCidBuffer;
203  void TxStelEncoderBuffer(void *pStelEncoderBuffer);
204  CRITICAL_SECTION StelTxCriticalSection;
205 #endif
206 
208  //data
209  char terminate_tx_rx_threads;
210 
214  unsigned char rx_data[SAMPLE_CPP_MAX_DATA_LEN];
215 
219  unsigned char tx_data[SAMPLE_CPP_MAX_DATA_LEN];
220 
223 
226 
229 
230 #if DBG_TIMING
231  wan_debug_t wan_debug_rx_timing;
232 #endif
233 
235  callback_functions_t callback_functions;
236 
237  virtual unsigned long threadFunction(struct ThreadParam& thParam);
238 
239 public:
240  char device_name[DEV_NAME_LEN];
241 
242  char is_logger_dev;
244  //methods
245  sangoma_interface(int wanpipe_number, int interface_number);
246  virtual ~sangoma_interface();
247 
248  int DoManagementCommand(sng_fd_t drv, wan_udp_hdr_t* packet);
249 
250  virtual int init(callback_functions_t *callback_functions_ptr);
251  int run();
252  int stop();
253 
255  int transmit(wp_api_hdr_t *hdr, void *data);
256 
258  int receive (wp_api_hdr_t *hdr, void *data);
259 
260  void bit_swap_a_buffer(unsigned char *data, int len);
261 
262  void get_te1_56k_stat(void);
263  void set_lb_modes(unsigned char type, unsigned char mode);
264  int loopback_command(u_int8_t type, u_int8_t mode, u_int32_t chan_map);
265 
266  int get_operational_stats(wanpipe_chan_stats_t *stats);
267  virtual int flush_operational_stats (void);
268 
269  int CreateSwDtmfTxThread(void *buffer);
270  int CreateFskCidTxThread(void *buffer);
271 
272  int enable_rbs_monitoring();
273  char get_rbs(rbs_management_t *rbs_management_ptr);
274  char set_rbs(rbs_management_t *rbs_management_ptr);
275 
276  int tdm_enable_rbs_events(int polls_per_second);
277  int tdm_disable_rbs_events();
278 
279  int set_tx_idle_flag(unsigned char new_idle_flag);
280  int get_open_handles_counter();
281 
282  //remove all data from API driver's transmit queue
283  int flush_tx_buffers (void);
284 
285  unsigned char get_adapter_type();
286  unsigned int get_sub_media();
287  void set_fe_debug_mode(sdla_fe_debug_t *fe_debug);
288 
289  void get_api_driver_version(PDRIVER_VERSION version);
290 
291  void get_card_customer_id(u_int8_t *customer_id);
292 
293 #if USE_STELEPHONY_API
294  int resetFSKCID(void);
295  int sendCallerID(char *name, char *number);
296  int sendSwDTMF(char dtmf_char);
297 #endif
298 
300  //TDM API calls
301  int tdm_enable_rxhook_events();
302  int tdm_disable_rxhook_events();
303 
304  /* DTMF Detection on A200 Analog card (SLIC) chip */
305  int tdm_enable_rm_dtmf_events();
306  int tdm_disable_rm_dtmf_events();
307 
308  /* DTMF Detection on Octasic chip */
309  int tdm_enable_dtmf_events(uint8_t channel);
310  int tdm_disable_dtmf_events(uint8_t channel);
311 
312  int tdm_enable_ring_detect_events();
313  int tdm_disable_ring_detect_events();
314 
315  int tdm_enable_ring_trip_detect_events();
316  int tdm_disable_ring_trip_detect_events();
317 
318  int tdm_enable_ring_events();
319  int tdm_disable_ring_events();
320 
321  int tdm_txsig_onhook();
322  int tdm_txsig_offhook();
323  int tdm_txsig_kewl();
324  /*To transmit data while FXS is on-hook */
325  /* Example: To transmit FSK Message Wait Indication (MWI)
326  to phone connected with FXS */
327  int tdm_txsig_onhooktransfer();
328 
329  int tdm_enable_tone_events(uint16_t tone_id);
330  int tdm_disable_tone_events();
331 
332  int tdm_front_end_activate();
333  int tdm_front_end_deactivate();
334 
335  int tdm_control_flash_events(int rxflashtime);
336 
337  /* To set tx/rx gain for analog FXS/FXO modules
338  Gain in dB = gainvalue / 10
339  For FXS: txgain/rxgain value could be -35 or 35
340  FXO: txgain/rxgain value ranges from -150 to 120
341  FXO/FXS: Set txgain/rxgain value 0 for default setting*/
342 
343  int tdm_control_rm_txgain(int txgain);
344  int tdm_control_rm_rxgain(int rxgain);
345 
346  /* Only valid for FXS module to Set Polarity on the line
347  polarity 0: Forward Polarity
348  1: Reverse Polarity */
349  int tdm_set_rm_polarity(int polarity);
350 
351  /* get current state of the line - is it Connected or Disconnected */
352  int tdm_get_front_end_status(unsigned char *status);
353 
354  int tdm_set_user_period(unsigned int usr_period);
356 
357  int tdmv_api_ioctl(wanpipe_api_cmd_t *api_cmd);
358 
359  int reset_interface_state();
360 
361  int start_ring_tone();
362  int stop_ring_tone();
363 
364  int start_congestion_tone();
365  int stop_congestion_tone();
366 
367  int start_busy_tone();
368  int stop_busy_tone();
369 
370  int stop_all_tones();
371 
372  int start_dial_tone();
373  int stop_dial_tone();
374 
375  int start_ringing_phone();
376  int stop_ringing_phone();
377 
378  int fxo_go_off_hook();
379  int fxo_go_on_hook();
380 
381  int fxs_txsig_offhook();
382 
383  //BRI only:
384  int tdm_enable_bri_bchan_loopback(u_int8_t channel);
385  int tdm_disable_bri_bchan_loopback(u_int8_t channel);
386 
387 };
388 
390 {
391 public:
392  sangoma_api_ctrl_dev(void);
393  ~sangoma_api_ctrl_dev(void);
394  virtual int init(callback_functions_t *callback_functions_ptr);
395 };
396 
398 {
399  wp_logger_cmd_t logger_cmd;
400 
401 public:
403  ~sangoma_api_logger_dev(void);
404  virtual int init(callback_functions_t *callback_functions_ptr);
406  virtual int read_event();
407  virtual int flush_operational_stats (void);
408  int get_logger_dev_operational_stats(wp_logger_stats_t *stats);
409 };
410 
411 #endif//SANGOMA_INTERFACE_H
412 
wanpipe_api_cmd_t tdm_api_cmd
unsigned char rx_data[SAMPLE_CPP_MAX_DATA_LEN]
Wanpipe API Library header for Sangoma AFT T1/E1/Analog/BRI/Serial Hardware -.
callback_functions_t callback_functions
stelephony_callback_functions_t scf
int get_fe_type(unsigned char *adapter_type)
int receive(wp_api_hdr_t *hdr, void *data)
Sangoma Interface Class that deals with span/chan IO (read/write/events)
wan_udp_hdr_t wan_udp
int get_interface_configuration(if_cfg_t *wanif_conf_ptr)
Wanpipe API Device Command Structure used with WANPIPE_IOCTL_API_CMD.
unsigned char tx_data[SAMPLE_CPP_MAX_DATA_LEN]
int sng_fd_t
Windows/Unix file handle abstraction.
virtual int read_event()
Wanpipe UDP Structure used for Maintenance and Debugging.
Definition: wanpipe_api.h:92
unsigned char adapter_type
TDM API channel statistics.
unsigned char wp_brt[256]
unsigned char set_wan_udphdr_data_byte(unsigned char off, unsigned char data)
int wanpipe_api_ioctl(wan_cmd_api_t *api_cmd)
Wanpipe UDP CMD Structure.
int DWORD
DWORD type is int, Ported from Windows.
Definition: libsangoma.h:259
WANPIPE(tm) Driver API - Provides FULL Wanpipe Driver API Support.
Wanpipe API Command Structure.
wanpipe_api_t wp_api
unsigned char * get_wan_udphdr_data_ptr(unsigned char off)
virtual int read_event()
sangoma_wait_obj_t * sng_wait_obj[SANGOMA_INTERFACE_NUMBER_OF_WAIT_OBJECTS]
void generate_bit_rev_table()
unsigned char get_wan_udphdr_data_byte(unsigned char off)
Wanpipe API Header Structure.
int transmit(wp_api_hdr_t *hdr, void *data)