00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _LIB_HP_SNAGOMA_H
00016 #define _LIB_HP_SNAGOMA_H
00017
00018
00019 #ifdef WIN32
00020
00021 #error "WINDOWS NOT DEFINED"
00022
00023 #else
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <ctype.h>
00028 #include <unistd.h>
00029 #include <sys/time.h>
00030 #include <sys/socket.h>
00031 #include <sys/ioctl.h>
00032 #include <sys/types.h>
00033 #include <sys/signal.h>
00034 #include <sys/select.h>
00035 #include <sys/wait.h>
00036 #include <sys/resource.h>
00037 #include <netinet/in.h>
00038 #include <string.h>
00039 #include <errno.h>
00040 #include <fcntl.h>
00041 #include <linux/if.h>
00042 #include <poll.h>
00043 #include <signal.h>
00044
00045
00046 #include <linux/wanpipe_defines.h>
00047 #include <linux/wanpipe_common.h>
00048 #include <linux/wanpipe_cfg.h>
00049 #include <linux/wanpipe.h>
00050 #include <linux/if_wanpipe.h>
00051 #include <linux/sdla_aft_te1.h>
00052 #endif
00053
00054 #define SMG_HP_MAX_CHAN_DATA 1024
00055 #define SMG_HP_TDM_CHUNK_IDX_SZ 16
00056 #define SMG_HP_TDM_MAX_CHANS 31
00057 #define SMG_HP_MAX_SPAN_DATA (31*160)+32
00058
00059 #define hp_tdmapi_rx_event_t api_rx_hdr_t
00060 #define hp_tdmapi_tx_event_t api_tx_hdr_t
00061
00062 #define SANGOMA_HPTDM_VERSION 1
00063
00064
00065
00066
00067
00068
00072 typedef struct sangoma_hptdm_span_reg
00073 {
00075 void *p;
00077 void (*log)(int level, FILE *fp, char *file, const char *func, int line, char *fmt, ...);
00079 int (*rx_event)(void *p, hp_tdmapi_rx_event_t *data);
00080 }sangoma_hptdm_span_reg_t;
00081
00082
00086 typedef struct hp_tdm_chunk
00087 {
00089 int init;
00091 int len;
00093 int offset;
00095 char data[SMG_HP_MAX_CHAN_DATA];
00096 }hp_tmd_chunk_t;
00097
00101 typedef struct sangoma_hptdm_chan_reg
00102 {
00104 void *p;
00106 int (*rx_data)(void *p, char *data, int len);
00108 int (*rx_event)(void *p, hp_tdmapi_rx_event_t *data);
00109
00110 }sangoma_hptdm_chan_reg_t;
00111
00115 typedef struct sangoma_hptdm_chan
00116 {
00118 int init;
00119
00121 int chan_no;
00122
00124 int span_no;
00125
00127 void *span;
00128
00130 hp_tmd_chunk_t rx_chunk;
00131
00133 hp_tmd_chunk_t tx_idx[SMG_HP_TDM_CHUNK_IDX_SZ];
00134
00136 int tx_idx_in;
00137
00139 int tx_idx_out;
00140
00142 int (*push)(struct sangoma_hptdm_chan *, char *data, int len);
00143
00145 sangoma_hptdm_chan_reg_t chan_reg;
00146
00147 }sangoma_hptdm_chan_t;
00148
00157 typedef struct sangoma_hptdm_chan_map
00158 {
00162 int chan_no_hw;
00163
00165 sangoma_hptdm_chan_t chan;
00166
00167 }sangoma_hptdm_chan_map_t;
00168
00169
00173 typedef struct sangoma_hptdm_span
00174 {
00176 int init;
00177
00179 int span_no;
00180
00182 char if_name[100];
00183
00185 int sock;
00186
00188 int chunk_sz;
00189
00191 int max_chans;
00192
00194 int tx_size;
00195
00197 unsigned char idle;
00198
00200 unsigned int timeslot_cfg;
00201
00203 unsigned int hwcoding;
00204
00206 sangoma_hptdm_chan_map_t chan_idx[SMG_HP_TDM_MAX_CHANS];
00207
00209 char rx_data[SMG_HP_MAX_SPAN_DATA];
00210
00212 int rx_len;
00213
00215 char tx_data[SMG_HP_MAX_SPAN_DATA];
00216
00218 int tx_len;
00219
00221 sangoma_hptdm_span_reg_t span_reg;
00222
00224 wan_if_cfg_t span_cfg;
00225
00227 wan_udp_hdr_t wan_udp;
00228
00235 int (*open_chan)(struct sangoma_hptdm_span *span,
00236 sangoma_hptdm_chan_reg_t *chan_reg,
00237 unsigned int chan_no,
00238 sangoma_hptdm_chan_t **chan_ptr);
00239
00243 int (*close_chan)(sangoma_hptdm_chan_t *chan);
00244
00247 int (*is_chan_closed)(sangoma_hptdm_chan_t *chan);
00248
00259 int (*run_span)(struct sangoma_hptdm_span *span);
00260
00263 int (*close_span)(struct sangoma_hptdm_span *span);
00264
00269 int (*event_ctrl)(struct sangoma_hptdm_span *span, hp_tdmapi_tx_event_t *event);
00270
00275 int (*get_cfg)(struct sangoma_hptdm_span *span, wan_if_cfg_t *cfg);
00276
00277
00278 }sangoma_hptdm_span_t;
00279
00280
00281
00282
00283
00291
00292 #define sangoma_hptdm_api_span_init(span,cfg) __sangoma_hptdm_api_span_init(span, cfg, SANGOMA_HPTDM_VERSION);
00293
00305
00306
00307
00308
00309 extern sangoma_hptdm_span_t * __sangoma_hptdm_api_span_init(int span_no, sangoma_hptdm_span_reg_t *cfg, int version);
00310
00311
00317 extern int sangoma_hptdm_api_span_free(sangoma_hptdm_span_t *span);
00318
00319
00320
00321
00322
00323 #endif
00324