00001
00036 #ifndef SANGOMA_INTERFACE_H
00037 #define SANGOMA_INTERFACE_H
00038
00039 #include <stdio.h>
00040 #include <stddef.h>
00041 #include <stdlib.h>
00042
00043 #if defined(__WINDOWS__)
00044 # include <windows.h>
00045 # include <winioctl.h>
00046 # include <conio.h>
00047 # include "bit_win.h"
00048 # include "wanpipe_time.h"
00049
00050 #elif defined(__LINUX__)
00051
00052
00053 # include <stddef.h>
00054 # include <errno.h>
00055 # include <fcntl.h>
00056 # include <string.h>
00057 # include <ctype.h>
00058 # include <sys/stat.h>
00059 # include <sys/ioctl.h>
00060 # include <sys/types.h>
00061 # include <dirent.h>
00062 # include <unistd.h>
00063 # include <sys/socket.h>
00064 # include <netdb.h>
00065 # include <sys/un.h>
00066 # include <sys/wait.h>
00067 # include <unistd.h>
00068 # include <signal.h>
00069 # include <time.h>
00070 #else
00071 # error "sangoma_interface.h: undefined OS type"
00072 #endif
00073
00074
00075
00076
00077
00078
00079
00080 #define USE_STELEPHONY_API 1
00081
00082
00083 #include "wanpipe_api.h"
00084 #include "sangoma_cthread.h"
00085 #include "sample.h"
00086
00087 #include <libsangoma.h>
00088
00089 #if USE_STELEPHONY_API
00090 # include <libstelephony.h>
00091 #endif
00092
00097 class sangoma_interface : public sangoma_cthread
00098 {
00100 sng_fd_t sangoma_dev;
00101
00103 void *sng_wait_obj;
00104
00106
00108 ULONG rx_frames_count;
00110 ULONG rx_bytes_count;
00111
00113 ULONG bad_rx_frames_count;
00115 DWORD dwRxThreadId;
00116
00118
00120 ULONG tx_bytes_count;
00122 ULONG tx_frames_count;
00124 UCHAR tx_test_byte;
00125
00127
00129 wan_udp_hdr_t wan_udp;
00130
00132 unsigned char get_wan_udphdr_data_byte(unsigned char off);
00133
00135 unsigned char *get_wan_udphdr_data_ptr(unsigned char off);
00136
00138 unsigned char set_wan_udphdr_data_byte(unsigned char off, unsigned char data);
00139
00141 int protocol_cb_size;
00143 int wan_protocol;
00145 unsigned char adapter_type;
00146
00148 wanpipe_api_cmd_t tdm_api_cmd;
00149
00151 wanpipe_api_t wp_api;
00152
00154 void RxThreadFunc();
00156 void TxThreadFunc();
00157
00159 int read_data();
00161 int read_event();
00162
00163 int write_data(wp_api_hdr_t *hdr, void *tx_buffer);
00164
00166 void cleanup();
00167
00169 wan_cmd_api_t wanpipe_api_cmd;
00170
00172 int get_wan_config();
00173
00175 int get_interface_configuration(if_cfg_t *wanif_conf_ptr);
00176
00178 int get_fe_type(unsigned char* adapter_type);
00179
00181 int wanpipe_api_ioctl(wan_cmd_api_t *api_cmd);
00182
00184 unsigned char wp_brt[256];
00185
00187 void generate_bit_rev_table();
00188
00190 char is_rbs_monitoring_enabled;
00191
00192 #if USE_STELEPHONY_API
00193
00194 stelephony_callback_functions_t scf;
00195 void *stelObj;
00196 void *DtmfBuffer;
00197 void *FskCidBuffer;
00198 void TxStelEncoderBuffer(void *pStelEncoderBuffer);
00199 CRITICAL_SECTION StelTxCriticalSection;
00200 #endif
00201
00203
00204 char terminate_tx_rx_threads;
00205
00207 wp_api_hdr_t rxhdr;
00209 unsigned char rx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00210
00212 wp_api_hdr_t txhdr;
00214 unsigned char tx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00215
00217 callback_functions_t callback_functions;
00218
00220 if_cfg_t wanif_conf_struct;
00221
00223 int WanpipeNumber;
00224
00226 int InterfaceNumber;
00227
00228 #if DBG_TIMING
00229 wan_debug_t wan_debug_rx_timing;
00230 #endif
00231
00232 protected:
00233 virtual unsigned long threadFunction(struct ThreadParam& thParam);
00234
00235 public:
00236 char device_name[DEV_NAME_LEN];
00237
00239
00240 sangoma_interface(int wanpipe_number, int interface_number);
00241 ~sangoma_interface();
00242
00243 int DoManagementCommand(sng_fd_t drv, wan_udp_hdr_t* packet);
00244
00245 int init(callback_functions_t *callback_functions_ptr);
00246 int run();
00247 int stop();
00248
00250 int transmit(wp_api_hdr_t *hdr, void *data);
00251
00253 int receive (wp_api_hdr_t *hdr, void *data);
00254
00255 void bit_swap_a_buffer(unsigned char *data, int len);
00256
00257 void get_te1_56k_stat(void);
00258 void set_lb_modes(unsigned char type, unsigned char mode);
00259 int loopback_command(u_int8_t type, u_int8_t mode, u_int32_t chan_map);
00260
00261 int get_operational_stats(wanpipe_chan_stats_t *stats);
00262 int flush_operational_stats (void);
00263
00264 int CreateSwDtmfTxThread(void *buffer);
00265 int CreateFskCidTxThread(void *buffer);
00266
00267 int enable_rbs_monitoring();
00268 char get_rbs(rbs_management_t *rbs_management_ptr);
00269 char set_rbs(rbs_management_t *rbs_management_ptr);
00270
00271 int tdm_enable_rbs_events(int polls_per_second);
00272 int tdm_disable_rbs_events();
00273
00274 int set_tx_idle_flag(unsigned char new_idle_flag);
00275 int get_open_handles_counter();
00276
00277
00278 int flush_tx_buffers (void);
00279
00280 sng_fd_t open_api_device();
00281
00282 unsigned char get_adapter_type();
00283 unsigned int get_sub_media();
00284 void set_fe_debug_mode(sdla_fe_debug_t *fe_debug);
00285
00286 void get_api_driver_version(PDRIVER_VERSION version);
00287
00288 void get_card_customer_id(u_int8_t *customer_id);
00289
00290 #if USE_STELEPHONY_API
00291 int resetFSKCID(void);
00292 int sendCallerID(char *name, char *number);
00293 int sendSwDTMF(char dtmf_char);
00294 #endif
00295
00297
00298 int tdm_enable_rxhook_events();
00299 int tdm_disable_rxhook_events();
00300
00301
00302 int tdm_enable_rm_dtmf_events();
00303 int tdm_disable_rm_dtmf_events();
00304
00305
00306 int tdm_enable_dtmf_events(uint8_t channel);
00307 int tdm_disable_dtmf_events(uint8_t channel);
00308
00309 int tdm_enable_ring_detect_events();
00310 int tdm_disable_ring_detect_events();
00311
00312 int tdm_enable_ring_trip_detect_events();
00313 int tdm_disable_ring_trip_detect_events();
00314
00315 int tdm_enable_ring_events();
00316 int tdm_disable_ring_events();
00317
00318 int tdm_txsig_onhook();
00319 int tdm_txsig_offhook();
00320
00321 int tdm_enable_tone_events(uint16_t tone_id);
00322 int tdm_disable_tone_events();
00323
00324 int tdm_front_end_activate();
00325 int tdm_front_end_deactivate();
00326
00327 int tdm_control_flash_events(int rxflashtime);
00328
00329
00330 int tdm_get_front_end_status(unsigned char *status);
00331
00332 int tdm_set_user_period(unsigned int usr_period);
00334
00335 int tdmv_api_ioctl(wanpipe_api_cmd_t *api_cmd);
00336
00337 int reset_interface_state();
00338
00339 int start_ring_tone();
00340 int stop_ring_tone();
00341
00342 int start_congestion_tone();
00343 int stop_congestion_tone();
00344
00345 int start_busy_tone();
00346 int stop_busy_tone();
00347
00348 int stop_all_tones();
00349
00350 int start_dial_tone();
00351 int stop_dial_tone();
00352
00353 int start_ringing_phone();
00354 int stop_ringing_phone();
00355
00356 int fxo_go_off_hook();
00357 int fxo_go_on_hook();
00358
00359
00360 int tdm_enable_bri_bchan_loopback(u_int8_t channel);
00361 int tdm_disable_bri_bchan_loopback(u_int8_t channel);
00362
00363 };
00364
00365
00366 #if defined(__WINDOWS__)
00367
00368 #define HANDLE_DEVICE_IOCTL_RESULT(bResult)\
00369 { \
00370 if(bResult == 0){ \
00371 \
00372 printf("%s(): Line: %d: Error!!\n", __FUNCTION__, __LINE__); \
00373 DecodeLastError(__FUNCTION__); \
00374 return 1; \
00375 } \
00376 }
00377
00378 #endif
00379
00380 #endif//SANGOMA_INTERFACE_H
00381