libsangoma.h

Go to the documentation of this file.
00001 /*******************************************************************************/
00040 #ifndef _LIBSNAGOMA_H
00041 #define _LIBSNAGOMA_H
00042 
00043 #ifdef __cplusplus
00044 extern "C" {    /* for C++ users */
00045 #endif
00046 
00047 #include <stdio.h>
00048 
00049 
00054 #define WANPIPE_TDM_API 1
00055 
00056 /*TODO: LIBSANGOMA_VERSION_CODE should be generated out of LIBSANGOMA_LT_CURRENT and friends in configure.in */
00057 
00062 #define LIBSANGOMA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
00063 
00068 #define LIBSANGOMA_VERSION_CODE LIBSANGOMA_VERSION(3,0,0)
00069 
00074 #define LIBSANGOMA_VERSION_STR "3.0.0"
00075 
00076 #ifdef __COMPILING_LIBSANGOMA__
00077  struct sangoma_wait_obj;
00078  #define sangoma_wait_obj_t struct sangoma_wait_obj
00079 #else
00080  typedef void sangoma_wait_obj_t;
00081 #endif
00082 
00083 #if defined(WIN32) || defined(WIN64)
00084 #ifndef __WINDOWS__
00085 #define __WINDOWS__
00086 #endif
00087 #include <windows.h>
00088 #include <winioctl.h>
00089 #include <conio.h>
00090 #include <stddef.h> 
00091 #include <stdlib.h> 
00092 
00097 #define _SAPI_CALL  __cdecl
00098 
00103 #define SANGOMA_INFINITE_API_POLL_WAIT INFINITE
00104 #define SANGOMA_WAIT_INFINITE INFINITE
00105 
00110 #define sangoma_msleep(x)   Sleep(x)
00111 
00112 #else
00113 /* L I N U X */
00114 #include <stdlib.h>
00115 #include <stdarg.h>
00116 #include <ctype.h>
00117 #include <unistd.h>
00118 #include <sys/time.h>
00119 #include <sys/socket.h>
00120 #include <sys/ioctl.h>
00121 #include <sys/types.h>
00122 #include <sys/stat.h>
00123 #include <sys/signal.h>
00124 #include <sys/select.h>
00125 #include <sys/wait.h>
00126 #include <sys/resource.h>
00127 #include <netinet/in.h>
00128 #include <string.h>
00129 #include <errno.h>
00130 #include <fcntl.h>
00131 #include <net/if.h>
00132 #include <poll.h>
00133 #include <signal.h>
00134 #include <pthread.h>
00135 #include <stdint.h>
00136 
00141 #define _SAPI_CALL
00142 
00147 #define INVALID_HANDLE_VALUE -1
00148 
00153 #define SANGOMA_INFINITE_API_POLL_WAIT -1
00154 #define SANGOMA_WAIT_INFINITE -1
00155 
00195 #define __cdecl
00196 
00197 #ifndef FALSE
00198 #define FALSE       0
00199 #endif
00200 
00201 #ifndef TRUE
00202 #define TRUE        1
00203 #endif
00204 
00205 #define sangoma_msleep(x) usleep(x*1000)
00206 #define _getch      getchar
00207 #define Sleep       sangoma_msleep
00208 #define _stricmp    strcmp
00209 #define _snprintf   snprintf
00210 #define _vsnprintf      vsnprintf
00211 
00212 typedef int HANDLE;
00213 typedef int BOOL;
00214 typedef int DWORD;
00215 typedef char TCHAR;
00216 typedef unsigned char UCHAR;
00217 typedef unsigned long ULONG;
00218 typedef unsigned short USHORT;
00219 typedef unsigned char * LPSTR;
00220 typedef unsigned char * PUCHAR;
00221 typedef void * LPTHREAD_START_ROUTINE;
00222 typedef pthread_mutex_t CRITICAL_SECTION;
00223 
00224 #define EnterCriticalSection(arg)   pthread_mutex_lock(arg)
00225 #define LeaveCriticalSection(arg)   pthread_mutex_unlock(arg)
00226 #define InitializeCriticalSection(arg) pthread_mutex_init(arg, NULL);
00227 
00228 typedef struct tm SYSTEMTIME;
00229 typedef char * LPCTSTR;
00230                
00231 #endif/* WIN32 */
00232 
00233 
00245 #ifdef LIBSANGOMA_LIGHT
00246 #include "wanpipe_api_iface.h"
00247 #include "wanpipe_api_hdr.h"
00248 #include "sdla_te1.h"
00249 #include "wanpipe_events.h"
00250 #include "wanpipe_api_deprecated.h"
00251 #else
00252 #include "wanpipe_api.h"
00253 #endif
00254 
00265 typedef int32_t sangoma_status_t;
00266 
00275 #define FNAME_LEN       100
00276 #define FUNC_DBG(x)     if(0)printf("%s():%d\n", x, __LINE__)
00277 #define DBG_PRINT       if(1)printf
00278 
00283 typedef wp_api_hdr_t sangoma_api_hdr_t;
00284 
00291 typedef enum _sangoma_wait_obj_type
00292 {
00294     UNKNOWN_WAIT_OBJ = 0, 
00296     SANGOMA_GENERIC_WAIT_OBJ = 0, 
00298     SANGOMA_DEVICE_WAIT_OBJ, 
00300     SANGOMA_DEVICE_WAIT_OBJ_SIG, 
00301 } sangoma_wait_obj_type_t;
00302 
00303 #define DECODE_SANGOMA_WAIT_OBJECT_TYPE(type)\
00304     type == SANGOMA_GENERIC_WAIT_OBJ    ? "SANGOMA_GENERIC_WAIT_OBJ"    :\
00305     type == SANGOMA_DEVICE_WAIT_OBJ     ? "SANGOMA_DEVICE_WAIT_OBJ"     :\
00306     type == SANGOMA_DEVICE_WAIT_OBJ_SIG ? "SANGOMA_DEVICE_WAIT_OBJ_SIG" :\
00307     "Invalid Wait Object type!"
00308 
00309 /************************************************************/
00322 sng_fd_t _SAPI_CALL sangoma_open_api_span_chan(int span, int chan);
00323 
00324 
00334 sng_fd_t _SAPI_CALL __sangoma_open_api_span_chan(int span, int chan);
00335 #define __sangoma_open_tdmapi_span_chan __sangoma_open_api_span_chan
00336 
00345 sng_fd_t _SAPI_CALL sangoma_open_api_span(int span);
00346 
00347 
00359 #ifndef LIBSANGOMA_TDMAPI_CTRL
00360 #define LIBSANGOMA_TDMAPI_CTRL 1
00361 #endif
00362 
00371 sng_fd_t _SAPI_CALL sangoma_open_api_ctrl(void);
00372 
00373 
00382 sng_fd_t _SAPI_CALL sangoma_open_driver_ctrl(int port_no);
00383 
00384 
00385 
00393 void _SAPI_CALL sangoma_close(sng_fd_t *fd);
00394 
00395 
00396 
00405 int _SAPI_CALL sangoma_get_open_cnt(sng_fd_t fd, wanpipe_api_t *tdm_api);
00406 
00407 
00408 /************************************************************/
00427 int _SAPI_CALL sangoma_writemsg(sng_fd_t fd, void *hdrbuf, int hdrlen,
00428                          void *databuf, unsigned short datalen, int flag);
00429 
00430 
00445 int _SAPI_CALL sangoma_readmsg(sng_fd_t fd, void *hdrbuf, int hdrlen,
00446                         void *databuf, int datalen, int flag);
00447 
00448 
00449 
00450 
00451 /************************************************************/
00462 sangoma_status_t _SAPI_CALL sangoma_waitfor(sangoma_wait_obj_t *sangoma_wait_obj, uint32_t inflags, uint32_t *outflags, int32_t timeout);
00463 
00474 sangoma_status_t _SAPI_CALL sangoma_waitfor_many(sangoma_wait_obj_t *sangoma_wait_objects[], uint32_t in_flags[], uint32_t out_flags[],
00475         uint32_t number_of_sangoma_wait_objects, int32_t system_wait_timeout);
00476 
00491 sangoma_status_t _SAPI_CALL sangoma_wait_obj_create(sangoma_wait_obj_t **sangoma_wait_object, sng_fd_t fd, sangoma_wait_obj_type_t object_type);
00492 
00499 sangoma_status_t _SAPI_CALL sangoma_wait_obj_delete(sangoma_wait_obj_t **sangoma_wait_object);
00500 
00507 sangoma_status_t _SAPI_CALL sangoma_wait_obj_signal(sangoma_wait_obj_t *sangoma_wait_object);
00508 
00515 sng_fd_t _SAPI_CALL sangoma_wait_obj_get_fd(sangoma_wait_obj_t *sangoma_wait_object);
00516 
00525 void _SAPI_CALL sangoma_wait_obj_set_context(sangoma_wait_obj_t *sangoma_wait_object, void *context);
00526 
00533 void* _SAPI_CALL sangoma_wait_obj_get_context(sangoma_wait_obj_t *sangoma_wait_object);
00534 
00535 
00536 /************************************************************/
00547 int _SAPI_CALL sangoma_cmd_exec(sng_fd_t fd, wanpipe_api_t *tdm_api);
00548 
00549 
00557 int _SAPI_CALL sangoma_get_full_cfg(sng_fd_t fd, wanpipe_api_t *tdm_api);
00558 
00569 int _SAPI_CALL sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_api_t *tdm_api, int period);
00570 
00578 int _SAPI_CALL sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_api_t *tdm_api);
00579 
00587 int _SAPI_CALL sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_api_t *tdm_api);
00588 
00589 
00598 int _SAPI_CALL sangoma_flush_bufs(sng_fd_t fd, wanpipe_api_t *tdm_api);
00599 
00600 
00609 int _SAPI_CALL sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_api_t *tdm_api, int poll_in_sec);
00610 
00618 int _SAPI_CALL sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00619 
00629 int _SAPI_CALL sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_api_t *tdm_api, int channel, unsigned char rbs);
00630 
00641 int _SAPI_CALL sangoma_tdm_read_rbs(sng_fd_t fd, wanpipe_api_t *tdm_api, int channel, unsigned char *rbs);
00642 
00652 int _SAPI_CALL sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00653 
00663 int _SAPI_CALL sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00664 
00665 
00675 int _SAPI_CALL sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00676 
00686 int _SAPI_CALL sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00687 
00697 int _SAPI_CALL sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00698 
00708 int _SAPI_CALL sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00709 
00719 int _SAPI_CALL sangoma_tdm_enable_ring_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00720 
00730 int _SAPI_CALL sangoma_tdm_disable_ring_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00731 
00732 
00742 int _SAPI_CALL sangoma_tdm_enable_ring_detect_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00743 
00753 int _SAPI_CALL sangoma_tdm_disable_ring_detect_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00754 
00764 int _SAPI_CALL sangoma_tdm_enable_ring_trip_detect_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00765 
00775 int _SAPI_CALL sangoma_tdm_disable_ring_trip_detect_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00776 
00787 int _SAPI_CALL sangoma_tdm_enable_tone_events(sng_fd_t fd, wanpipe_api_t *tdm_api, uint16_t tone_id);
00788 
00798 int _SAPI_CALL sangoma_tdm_disable_tone_events(sng_fd_t fd, wanpipe_api_t *tdm_api);
00799 
00809 int _SAPI_CALL sangoma_tdm_txsig_onhook(sng_fd_t fd, wanpipe_api_t *tdm_api);
00810 
00820 int _SAPI_CALL sangoma_tdm_txsig_offhook(sng_fd_t fd, wanpipe_api_t *tdm_api);
00821 
00831 int _SAPI_CALL sangoma_tdm_txsig_start(sng_fd_t fd, wanpipe_api_t *tdm_api);
00832 
00842 int _SAPI_CALL sangoma_tdm_txsig_kewl(sng_fd_t fd, wanpipe_api_t *tdm_api);
00843 
00853 int _SAPI_CALL sangoma_tdm_enable_hwec(sng_fd_t fd, wanpipe_api_t *tdm_api);
00854 
00864 int _SAPI_CALL sangoma_tdm_disable_hwec(sng_fd_t fd, wanpipe_api_t *tdm_api);
00865 
00876 int _SAPI_CALL sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned int *alarms);
00877 
00878 
00879 
00880 #ifdef WP_API_FEATURE_LINK_STATUS
00881 # ifndef LIBSANGOMA_GET_LINKSTATUS
00882 
00886 # define LIBSANGOMA_GET_LINKSTATUS 1
00887 # endif
00888 
00898 int _SAPI_CALL sangoma_get_link_status(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned char *current_status);
00899 
00900 #endif
00901 
00902 /* set current Line Connection state - Connected/Disconnected */
00903 #ifndef LIBSANGOMA_GET_FESTATUS
00904 
00908 #define LIBSANGOMA_GET_FESTATUS 1
00909 #endif
00910 
00919 int _SAPI_CALL sangoma_set_fe_status(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned char new_status);
00920 
00921 
00931 int _SAPI_CALL sangoma_enable_bri_bchan_loopback(sng_fd_t fd, wanpipe_api_t *tdm_api, int channel);
00932 
00942 int _SAPI_CALL sangoma_disable_bri_bchan_loopback(sng_fd_t fd, wanpipe_api_t *tdm_api, int channel);
00943 
00944 
00952 int _SAPI_CALL sangoma_get_tx_queue_sz(sng_fd_t fd, wanpipe_api_t *tdm_api);
00953 
00954 
00963 int _SAPI_CALL sangoma_set_tx_queue_sz(sng_fd_t fd, wanpipe_api_t *tdm_api, int size);
00964 
00972 int _SAPI_CALL sangoma_get_rx_queue_sz(sng_fd_t fd, wanpipe_api_t *tdm_api);
00973 
00982 int _SAPI_CALL sangoma_set_rx_queue_sz(sng_fd_t fd, wanpipe_api_t *tdm_api, int size);
00983 
00984 
00985 #ifndef LIBSANGOMA_GET_HWCODING
00986 
00990 #define LIBSANGOMA_GET_HWCODING 1
00991 #endif
00992 
01003 int _SAPI_CALL sangoma_get_hw_coding(sng_fd_t fd, wanpipe_api_t *tdm_api);
01004 
01005 
01006 
01007 #ifndef LIBSANGOMA_GET_HWDTMF
01008 
01012 #define LIBSANGOMA_GET_HWDTMF 1
01013 #endif
01014 
01023 int _SAPI_CALL sangoma_tdm_get_hw_dtmf(sng_fd_t fd, wanpipe_api_t *tdm_api);
01024 
01033 int _SAPI_CALL sangoma_span_chan_toif(int span, int chan, char *interface_name);
01034 
01043 int _SAPI_CALL sangoma_span_chan_fromif(char *interface_name, int *span, int *chan);
01044 
01045 
01054 int _SAPI_CALL sangoma_interface_wait_up(int span, int chan, int sectimeout);
01055 
01064 int _SAPI_CALL sangoma_get_driver_version(sng_fd_t fd, wanpipe_api_t *tdm_api, wan_driver_version_t *drv_ver);
01065 
01074 int _SAPI_CALL sangoma_get_firmware_version(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned char *ver);
01075 
01084 int _SAPI_CALL sangoma_get_cpld_version(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned char *ver);
01085 
01086 
01095 int _SAPI_CALL sangoma_get_stats(sng_fd_t fd, wanpipe_api_t *tdm_api, wanpipe_chan_stats_t *stats);
01096 
01104 int _SAPI_CALL sangoma_flush_stats(sng_fd_t fd, wanpipe_api_t *tdm_api);
01105 
01114 int _SAPI_CALL sangoma_set_rm_rxflashtime(sng_fd_t fd, wanpipe_api_t *tdm_api, int rxflashtime);
01115 
01116 
01117 
01118 /************************************************************/
01134 int _SAPI_CALL sangoma_read_event(sng_fd_t fd, wanpipe_api_t *tdm_api);
01135 
01136 
01137 
01138 #ifndef LIBSANGOMA_LIGHT
01139 
01140 /************************************************************/
01144 int _SAPI_CALL sangoma_driver_port_start(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no);
01145 int _SAPI_CALL sangoma_driver_port_stop(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no);
01146 int _SAPI_CALL sangoma_driver_port_set_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no);
01147 int _SAPI_CALL sangoma_driver_port_get_config(sng_fd_t fd, port_cfg_t *port_cfg, unsigned short port_no);
01148 int _SAPI_CALL sangoma_driver_get_hw_info(sng_fd_t fd, port_management_struct_t *port_mgmnt, unsigned short port_no);
01149 
01150 
01151 /************************************************************/
01162 int _SAPI_CALL sangoma_mgmt_cmd(sng_fd_t fd, wan_udp_hdr_t* wan_udp);
01163 
01164 
01165 #endif  /* LIBSANGOMA_LIGHT */
01166 
01167 
01168 /*================================================================
01169  * DEPRECATED Function Calls - Not to be used any more
01170  * Here for backward compatibility 
01171  *================================================================*/
01172 
01173 
01174 #ifndef LIBSANGOMA_SET_FESTATUS
01175 
01179 #define LIBSANGOMA_SET_FESTATUS 1
01180 #endif
01181 
01192 int _SAPI_CALL sangoma_get_fe_status(sng_fd_t fd, wanpipe_api_t *tdm_api, unsigned char *current_status);
01193 
01194 
01195 
01207 int _SAPI_CALL sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_api_t *tdm_api, int codec);
01208 
01219 int _SAPI_CALL sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_api_t *tdm_api);
01220 
01221 
01231 sng_fd_t _SAPI_CALL sangoma_create_socket_by_name(char *device, char *card);
01232 
01242 int _SAPI_CALL sangoma_interface_toi(char *interface_name, int *span, int *chan);
01243 
01244 
01255 int _SAPI_CALL sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_api_t *tdm_api, int power);
01256 
01266 int _SAPI_CALL sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_api_t *tdm_api);
01267 
01268 
01269 #ifdef __cplusplus
01270 }
01271 #endif
01272 
01274 #if !defined(__WINDOWS__)
01275 #define sangoma_open_tdmapi_span_chan sangoma_open_api_span_chan
01276 #define sangoma_open_tdmapi_span sangoma_open_api_span
01277 #define sangoma_open_tdmapi_ctrl sangoma_open_api_ctrl
01278 #define sangoma_tdm_get_fe_status sangoma_get_fe_status
01279 #define sangoma_socket_close sangoma_close
01280 #define sangoma_tdm_get_hw_coding sangoma_get_hw_coding
01281 #define sangoma_tdm_set_fe_status sangoma_set_fe_status
01282 #define sangoma_tdm_get_link_status sangoma_get_link_status
01283 #define sangoma_tdm_flush_bufs sangoma_flush_bufs
01284 #define sangoma_tdm_cmd_exec sangoma_cmd_exec
01285 #define sangoma_tdm_read_event sangoma_read_event
01286 #define sangoma_readmsg_tdm sangoma_readmsg
01287 #define sangoma_readmsg_socket sangoma_readmsg
01288 #define sangoma_sendmsg_socket sangoma_writemsg
01289 #define sangoma_writemsg_tdm sangoma_writemsg
01290 #define sangoma_create_socket_intr sangoma_open_api_span_chan
01291 #endif
01292 
01293 #endif  /* _LIBSNAGOMA_H */
01294 

Generated on Fri Jun 26 12:46:14 2009 for libsangoma by  doxygen 1.4.7