sangoma_interface.h

Go to the documentation of this file.
00001 /*******************************************************************************/
00036 #ifndef SANGOMA_INTERFACE_H
00037 #define SANGOMA_INTERFACE_H
00038 
00039 #include <stdio.h>
00040 #include <stddef.h>     //for offsetof()
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" //for wp_usleep()
00049 
00050 #elif defined(__LINUX__)
00051 
00052 /* Include headers */
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  * FSK CallerID and DTMF detection note:
00076  *  Stelephony.dll expects input BitStream (aLaw or uLaw audio) from a SINGLE timeslot.
00077  *  It is always the case for Analog cards, but not for the Digital cards, where
00078  *  API may provide input from a SINGLE or from MULTIPLE timeslots.
00079  */
00080 #define USE_STELEPHONY_API 1 /* set to zero if don't need to compile 
00081                                 function calls to libstelephony.dll */
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 {
00099 protected:
00101     sng_fd_t    sangoma_dev;
00102 
00104     sangoma_wait_obj_t *sng_wait_obj;
00105 
00107     //receive stuff
00109     ULONG       rx_frames_count;
00111     ULONG       rx_bytes_count;
00112     //for counting frames with CRC/Abort errors
00114     ULONG       bad_rx_frames_count;
00116     DWORD       dwRxThreadId; 
00117 
00119     //transmit stuff
00121     ULONG       tx_bytes_count;
00123     ULONG       tx_frames_count;
00125     UCHAR       tx_test_byte;
00126 
00128     //IOCTL management structures and variables
00130     wan_udp_hdr_t   wan_udp;
00131 
00133     unsigned char get_wan_udphdr_data_byte(unsigned char off);
00134 
00136     unsigned char *get_wan_udphdr_data_ptr(unsigned char off);
00137 
00139     unsigned char set_wan_udphdr_data_byte(unsigned char off, unsigned char data);
00140 
00142     int             protocol_cb_size;
00144     int             wan_protocol;
00146     unsigned char   adapter_type;
00147 
00149     wanpipe_api_cmd_t tdm_api_cmd;
00150 
00152     wanpipe_api_t wp_api;
00153     
00155     void RxThreadFunc();
00157     void TxThreadFunc();
00158 
00160     int read_data();
00162     virtual int read_event();
00163 
00164     int write_data(wp_api_hdr_t *hdr, void *tx_buffer);
00165 
00167     void cleanup();
00168 
00170     int get_wan_config();
00171 
00173     int get_interface_configuration(if_cfg_t *wanif_conf_ptr);
00174 
00176     int get_fe_type(unsigned char* adapter_type);
00177 
00179     int wanpipe_api_ioctl(wan_cmd_api_t *api_cmd);
00180 
00182     unsigned char wp_brt[256];
00183 
00185     void generate_bit_rev_table();
00186 
00188     char is_rbs_monitoring_enabled;
00189 
00190 #if USE_STELEPHONY_API
00191 
00192     stelephony_callback_functions_t scf;
00193     void *stelObj;
00194     void *DtmfBuffer;
00195     void *FskCidBuffer;
00196     void TxStelEncoderBuffer(void *pStelEncoderBuffer);
00197     CRITICAL_SECTION    StelTxCriticalSection;
00198 #endif
00199 
00201     //data
00202     char                terminate_tx_rx_threads;
00203 
00205     wp_api_hdr_t        rxhdr;
00207     unsigned char       rx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00208 
00210     wp_api_hdr_t        txhdr;
00212     unsigned char       tx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00213 
00215     if_cfg_t                wanif_conf_struct;
00216 
00218     int WanpipeNumber;
00219 
00221     int InterfaceNumber;
00222 
00223 #if DBG_TIMING
00224     wan_debug_t     wan_debug_rx_timing;
00225 #endif
00226 
00228     callback_functions_t    callback_functions;
00229 
00230     virtual unsigned long threadFunction(struct ThreadParam& thParam);
00231 
00232 public:
00233     char    device_name[DEV_NAME_LEN];
00234 
00235     char    is_logger_dev;
00237     //methods
00238     sangoma_interface(int wanpipe_number, int interface_number);
00239     ~sangoma_interface();
00240 
00241     int DoManagementCommand(sng_fd_t drv, wan_udp_hdr_t* packet);
00242 
00243     virtual int init(callback_functions_t *callback_functions_ptr);
00244     int run();
00245     int stop();
00246 
00248     int transmit(wp_api_hdr_t *hdr, void *data);
00249 
00251     int receive (wp_api_hdr_t *hdr, void *data);
00252 
00253     void bit_swap_a_buffer(unsigned char *data, int len);
00254 
00255     void get_te1_56k_stat(void);
00256     void set_lb_modes(unsigned char type, unsigned char mode);
00257     int loopback_command(u_int8_t type, u_int8_t mode, u_int32_t chan_map);
00258 
00259     int get_operational_stats(wanpipe_chan_stats_t *stats);
00260     virtual int flush_operational_stats (void);
00261 
00262     int CreateSwDtmfTxThread(void *buffer);
00263     int CreateFskCidTxThread(void *buffer);
00264 
00265     int enable_rbs_monitoring();
00266     char get_rbs(rbs_management_t *rbs_management_ptr);
00267     char set_rbs(rbs_management_t *rbs_management_ptr);
00268 
00269     int tdm_enable_rbs_events(int polls_per_second);
00270     int tdm_disable_rbs_events();
00271 
00272     int set_tx_idle_flag(unsigned char new_idle_flag);
00273     int get_open_handles_counter();
00274 
00275     //remove all data from API driver's transmit queue
00276     int flush_tx_buffers (void);
00277 
00278     sng_fd_t open_api_device();
00279 
00280     unsigned char get_adapter_type();
00281     unsigned int get_sub_media();
00282     void set_fe_debug_mode(sdla_fe_debug_t *fe_debug);
00283 
00284     void get_api_driver_version(PDRIVER_VERSION version);
00285 
00286     void get_card_customer_id(u_int8_t *customer_id);
00287 
00288 #if USE_STELEPHONY_API
00289     int resetFSKCID(void);
00290     int sendCallerID(char *name, char *number);
00291     int sendSwDTMF(char dtmf_char);
00292 #endif
00293 
00295     //TDM API calls
00296     int tdm_enable_rxhook_events();
00297     int tdm_disable_rxhook_events();
00298 
00299     /* DTMF Detection on A200 Analog card (SLIC) chip */
00300     int tdm_enable_rm_dtmf_events();
00301     int tdm_disable_rm_dtmf_events();
00302 
00303     /* DTMF Detection on Octasic chip */
00304     int tdm_enable_dtmf_events(uint8_t channel);
00305     int tdm_disable_dtmf_events(uint8_t channel);
00306 
00307     int tdm_enable_ring_detect_events();
00308     int tdm_disable_ring_detect_events();
00309 
00310     int tdm_enable_ring_trip_detect_events();
00311     int tdm_disable_ring_trip_detect_events();
00312 
00313     int tdm_enable_ring_events();
00314     int tdm_disable_ring_events();
00315 
00316     int tdm_txsig_onhook();
00317     int tdm_txsig_offhook();
00318     int tdm_txsig_kewl();
00319     /*To transmit data while FXS is on-hook */
00320     /* Example: To transmit FSK Message Wait Indication (MWI)
00321     to phone connected with FXS */
00322     int tdm_txsig_onhooktransfer();
00323 
00324     int tdm_enable_tone_events(uint16_t tone_id);
00325     int tdm_disable_tone_events();
00326 
00327     int tdm_front_end_activate();
00328     int tdm_front_end_deactivate();
00329 
00330     int tdm_control_flash_events(int rxflashtime);
00331     
00332     /* To set tx/rx gain for analog FXS/FXO modules
00333         Gain in dB = gainvalue / 10 
00334         For FXS: txgain/rxgain value could be -35 or 35 
00335             FXO: txgain/rxgain value ranges from -150 to 120 
00336             FXO/FXS: Set txgain/rxgain value 0 for default setting*/    
00337     
00338     int tdm_control_rm_txgain(int txgain);
00339     int tdm_control_rm_rxgain(int rxgain);
00340 
00341     /* Only valid for FXS module to Set Polarity on the line 
00342         polarity 0: Forward Polarity
00343               1: Reverse Polarity */
00344     int tdm_set_rm_polarity(int polarity);
00345 
00346     /* get current state of the line - is it Connected or Disconnected */
00347     int tdm_get_front_end_status(unsigned char *status);
00348 
00349     int tdm_set_user_period(unsigned int usr_period);
00351 
00352     int tdmv_api_ioctl(wanpipe_api_cmd_t *api_cmd);
00353 
00354     int reset_interface_state();
00355 
00356     int start_ring_tone();
00357     int stop_ring_tone();
00358 
00359     int start_congestion_tone();
00360     int stop_congestion_tone();
00361 
00362     int start_busy_tone();
00363     int stop_busy_tone();
00364 
00365     int stop_all_tones();
00366 
00367     int start_dial_tone();
00368     int stop_dial_tone();
00369 
00370     int start_ringing_phone();
00371     int stop_ringing_phone();
00372 
00373     int fxo_go_off_hook();
00374     int fxo_go_on_hook();
00375 
00376     int fxs_txsig_offhook();
00377 
00378     //BRI only:
00379     int tdm_enable_bri_bchan_loopback(u_int8_t channel);
00380     int tdm_disable_bri_bchan_loopback(u_int8_t channel);
00381 
00382 };
00383 
00384 class sangoma_api_ctrl_dev : public sangoma_interface
00385 {
00386 public:
00387     sangoma_api_ctrl_dev(void);
00388     ~sangoma_api_ctrl_dev(void);
00389     virtual int init(callback_functions_t *callback_functions_ptr);
00390 };
00391 
00392 class sangoma_api_logger_dev : public sangoma_interface
00393 {
00394     wp_logger_cmd_t logger_cmd;
00395 
00396 public:
00397     sangoma_api_logger_dev(void);
00398     ~sangoma_api_logger_dev(void);
00399     virtual int init(callback_functions_t *callback_functions_ptr);
00401     virtual int read_event();
00402     virtual int flush_operational_stats (void);
00403     int get_logger_dev_operational_stats(wp_logger_stats_t *stats);
00404 };
00405 
00406 #endif//SANGOMA_INTERFACE_H
00407 

Generated on Tue Apr 13 22:29:20 2010 for libsangoma by  doxygen 1.4.7