libsangoma  1
wanpipe_api_iface.h
Go to the documentation of this file.
1 /******************************************************************************/
35 #ifndef __WANPIPE_API_IFACE_H_
36 #define __WANPIPE_API_IFACE_H_
37 
38 #include "wanpipe_api_hdr.h"
39 
44 #if defined(__WINDOWS__)
45 typedef HANDLE sng_fd_t;
46 #else
47 typedef int sng_fd_t;
48 #endif
49 
50 /* Indicate to library that new features exist */
77 #define WP_API_FEATURE_DTMF_EVENTS 1
78 #define WP_API_FEATURE_FE_ALARM 1
79 #define WP_API_FEATURE_EVENTS 1
80 #define WP_API_FEATURE_LINK_STATUS 1
81 #define WP_API_FEATURE_POL_REV 1
82 #define WP_API_FEATURE_LOGGER 1
83 #define WP_API_FEATURE_FAX_EVENTS 1
84 #define WP_API_FEATURE_RM_GAIN 1
85 #define WP_API_FEATURE_LOOP 1
86 #define WP_API_FEATURE_BUFFER_MULT 1
87 #define WP_API_FEATURE_RX_TX_ERRS 1
88 #define WP_API_FEATURE_EC_CHAN_STAT 1
89 #define WP_API_FEATURE_LIBSNG_HWEC 1
90 #define WP_API_FEATURE_DRIVER_GAIN 1
91 #define WP_API_FEATURE_FE_RW 1
92 #define WP_API_FEATURE_HWEC_PERSIST 1
93 #define WP_API_FEATURE_FAX_TYPE_EVENTS 1
94 #define WP_API_FEATURE_HARDWARE_RESCAN 1
95 #define WP_API_FEATURE_LED_CTRL 1
96 #define WP_API_FEATURE_SS7_FORCE_RX 1
97 #define WP_API_FEATURE_SS7_CFG_STATUS 1
98 #define WP_API_FEATURE_LIBSNG_HWEC_DTMF_REMOVAL 1
99 
100 
126 };
127 
128 
169  WANPIPEMON_READ_PERFORMANCE_STATS,
170  WANPIPEMON_FLUSH_PERFORMANCE_STATS,
179  /* Do not add any non-debugging commands below */
185  /* All Public commands must be between WANPIPEMON_ROUTER_UP_TIME and WANPIPEMON_PROTOCOL_PRIVATE. */
186 
188 };
189 
190 
191 typedef enum wp_bert_sequence_type{
192  WP_BERT_RANDOM_SEQUENCE = 1,
193  WP_BERT_ASCENDANT_SEQUENCE,
194  WP_BERT_DESCENDANT_SEQUENCE
195 }wp_bert_sequence_type_t;
196 
197 #define WP_BERT_DECODE_SEQUENCE_TYPE(sequence) \
198  ((sequence) == WP_BERT_RANDOM_SEQUENCE) ? "WP_BERT_RANDOM_SEQUENCE" : \
199  ((sequence) == WP_BERT_ASCENDANT_SEQUENCE) ? "WP_BERT_ASCENDANT_SEQUENCE" : \
200  ((sequence) == WP_BERT_DESCENDANT_SEQUENCE) ? "WP_BERT_DESCENDANT_SEQUENCE" : \
201  "(Unknown BERT sequence)"
202 
203 #define WP_BERT_STATUS_OUT_OF_SYNCH 0
204 #define WP_BERT_STATUS_IN_SYNCH 1
205 
212 typedef struct _wp_bert_status{
213 
214  unsigned char state;
215  unsigned int errors;
216  unsigned int synchonized_count;
219 
220 
221 
228 typedef struct wan_api_ss7_cfg_status {
229  unsigned char ss7_hw_enable;
230  unsigned char ss7_hw_mode;
231  unsigned char ss7_hw_lssu_size;
232  unsigned char ss7_driver_repeat;
234 
240 {
241 
267  WP_API_CMD_READ_EVENT,
268  WP_API_CMD_SET_EVENT,
269  WP_API_CMD_SET_RX_GAINS,
270  WP_API_CMD_SET_TX_GAINS,
271  WP_API_CMD_CLEAR_RX_GAINS,
272  WP_API_CMD_CLEAR_TX_GAINS,
273  WP_API_CMD_GET_FE_ALARMS,
274  WP_API_CMD_ENABLE_HWEC,
275  WP_API_CMD_DISABLE_HWEC,
276  WP_API_CMD_SET_FE_STATUS,
277  WP_API_CMD_GET_FE_STATUS,
279  WP_API_CMD_DRV_MGMNT,
289  WP_API_CMD_EVENT_CTRL,
290  WP_API_CMD_NOTSUPP,
304  /* Add only debugging commands here */
305  WP_API_CMD_GEN_FIFO_ERR_TX=500,
306  WP_API_CMD_GEN_FIFO_ERR_RX,
307  WP_API_CMD_START_CHAN_SEQ_DEBUG,
308  WP_API_CMD_STOP_CHAN_SEQ_DEBUG
309 };
310 
316 {
317  WP_CDEV_CMD_SET_DPC_TIMEDIFF_MONITORING_OPTION=1, /* DPC() monitoring */
318  WP_CDEV_CMD_SET_TX_INTERRUPT_TIMEDIFF_MONITORING_OPTION,/* TX ISR() monitoring */
319  WP_CDEV_CMD_SET_RX_INTERRUPT_TIMEDIFF_MONITORING_OPTION,/* RX ISR() monitoring */
320  WP_CDEV_CMD_PRINT_INTERRUPT_TIMEDIFF_MONITORING_INFO, /* print ISR() monitoring info to Wanpipelog */
321  WP_CDEV_CMD_GET_INTERFACE_NAME /* Retrun Interface Name to user-mode application */
322 };
323 
337 {
338  WP_API_EVENT_NONE,
340  WP_API_EVENT_ALARM,
342  WP_API_EVENT_RM_DTMF,
343  WP_API_EVENT_RXHOOK,
344  WP_API_EVENT_RING,
345  WP_API_EVENT_RING_DETECT,
346  WP_API_EVENT_RING_TRIP_DETECT,
347  WP_API_EVENT_TONE,
348  WP_API_EVENT_TXSIG_KEWL,
349  WP_API_EVENT_TXSIG_START,
350  WP_API_EVENT_TXSIG_OFFHOOK,
351  WP_API_EVENT_TXSIG_ONHOOK,
352  WP_API_EVENT_ONHOOKTRANSFER,
353  WP_API_EVENT_SETPOLARITY,
354  WP_API_EVENT_BRI_CHAN_LOOPBACK,
355  WP_API_EVENT_LINK_STATUS,
356  WP_API_EVENT_MODEM_STATUS,
357  WP_API_EVENT_POLARITY_REVERSE,
364 };
365 
366 
380 #define WP_API_EVENT_SET 0x01
381 #define WP_API_EVENT_GET 0x02
382 #define WP_API_EVENT_ENABLE 0x01
383 #define WP_API_EVENT_DISABLE 0x02
384 
385 #define WP_API_EVENT_MODE_DECODE(mode) \
386  ((mode) == WP_API_EVENT_ENABLE) ? "Enable" : \
387  ((mode) == WP_API_EVENT_DISABLE) ? "Disable" : \
388  "(Unknown mode)"
389 
390 
401 #define WPTDM_A_BIT WAN_RBS_SIG_A
402 #define WPTDM_B_BIT WAN_RBS_SIG_B
403 #define WPTDM_C_BIT WAN_RBS_SIG_C
404 #define WPTDM_D_BIT WAN_RBS_SIG_D
405 
406 
417 #define WP_API_EVENT_RXHOOK_OFF 0x01
418 #define WP_API_EVENT_RXHOOK_ON 0x02
419 #define WP_API_EVENT_RXHOOK_FLASH 0x03
420 #define WP_API_EVENT_RXHOOK_DECODE(state) \
421  ((state) == WP_API_EVENT_RXHOOK_OFF) ? "Off-hook" : \
422  ((state) == WP_API_EVENT_RXHOOK_FLASH) ? "Flash" : \
423  ((state) == WP_API_EVENT_RXHOOK_ON) ? "On-hook" : \
424  "(Unknown state)"
425 
433 #define WP_API_EVENT_RING_PRESENT 0x01
434 #define WP_API_EVENT_RING_STOP 0x02
435 #define WP_API_EVENT_RING_DECODE(state) \
436  ((state) == WP_API_EVENT_RING_PRESENT) ? "Ring Present" : \
437  ((state) == WP_API_EVENT_RING_STOP) ? "Ring Stop" : \
438  "(Unknown state)"
439 
448 #define WP_API_EVENT_RING_TRIP_PRESENT 0x01
449 #define WP_API_EVENT_RING_TRIP_STOP 0x02
450 #define WP_API_EVENT_RING_TRIP_DECODE(state) \
451  ((state) == WP_API_EVENT_RING_TRIP_PRESENT) ? "Ring Present" : \
452  ((state) == WP_API_EVENT_RING_TRIP_STOP) ? "Ring Stop" : \
453  "(Unknown state)"
454 /*Link Status */
463 #define WP_API_EVENT_LINK_STATUS_CONNECTED 0x01
464 #define WP_API_EVENT_LINK_STATUS_DISCONNECTED 0x02
465 #define WP_API_EVENT_LINK_STATUS_DECODE(status) \
466  ((status) == WP_API_EVENT_LINK_STATUS_CONNECTED) ? "Connected" : \
467  ((status) == WP_API_EVENT_LINK_STATUS_DISCONNECTED) ? "Disconnected" : \
468  "Unknown"
469 
470 /*Polarity Reversal for FXO */
479 #define WP_API_EVENT_POL_REV_POS_TO_NEG 0x01
480 #define WP_API_EVENT_POL_REV_NEG_TO_POS 0x02
481 #define WP_API_EVENT__POL_REV_NEG_TO_POS WP_API_EVENT_POL_REV_NEG_TO_POS
482 #define WP_API_EVENT_POLARITY_REVERSE_DECODE(polarity_reverse) \
483  ((polarity_reverse) == WP_API_EVENT_POL_REV_POS_TO_NEG) ? "+ve to -ve" : \
484  ((polarity_reverse) == WP_API_EVENT_POL_REV_NEG_TO_POS) ? "-ve to +ve" : \
485  "Unknown"
486 
502 #define WP_API_EVENT_TONE_DIAL 0x01
503 #define WP_API_EVENT_TONE_BUSY 0x02
504 #define WP_API_EVENT_TONE_RING 0x03
505 #define WP_API_EVENT_TONE_CONGESTION 0x04
506 #define WP_API_EVENT_TONE_DTMF 0x05
507 #define WP_API_EVENT_TONE_FAXCALLING 0x06
508 #define WP_API_EVENT_TONE_FAXCALLED 0x07
509 
510 /* BRI channels list */
519 #define WAN_BRI_BCHAN1 0x01
520 #define WAN_BRI_BCHAN2 0x02
521 #define WAN_BRI_DCHAN 0x03
522 
523 
531 #define WP_PORT_NAME_FORM "wanpipe%d"
532 #define WP_INTERFACE_NAME_FORM "wanpipe%d_if%d"
533 #define WP_CTRL_DEV_NAME "wanpipe_ctrl"
534 #define WP_CONFIG_DEV_NAME "wanpipe"
535 #define WP_TIMER_DEV_NAME_FORM "wanpipe_timer%d"
536 #define WP_LOGGER_DEV_NAME "wanpipe_logger"
537 
538 #pragma pack(1)
539 
540 
547 typedef struct wanpipe_chan_stats
548 {
549  unsigned int rx_packets; /* total packets received */
550  unsigned int tx_packets; /* total packets transmitted */
551  unsigned int rx_bytes; /* total bytes received */
552  unsigned int tx_bytes; /* total bytes transmitted */
553 
554  unsigned int rx_errors; /* total counter of receiver errors. see 'detailed rx_errors' */
555  unsigned int tx_errors; /* total counter of transmitter errors. see 'detailed tx_errors' */
556 
557  unsigned int rx_dropped; /* Counter of dropped received packets.
558  * Possible cause: internal driver error, check Driver Message Log. */
559  unsigned int tx_dropped; /* Counter of dropped transmit packets.
560  * Possible cause: internal driver error, check Driver Message Log. */
561  unsigned int multicast; /* Linux Network Interface: multicast packets received */
562  unsigned int collisions; /* Linux Network Interface: eth collisions counter */
563 
564  /* detailed rx_errors: */
565  unsigned int rx_length_errors; /* Received HDLC frame is longer than the MRU.
566  * Usualy means "no closing HDLC flag". */
567  unsigned int rx_over_errors; /* Receiver ring buff overflow at driver level (not at hardware) */
568  unsigned int rx_crc_errors; /* Received HDLC frame with CRC error.
569  * Possible cause: bit errors on the line. */
570  unsigned int rx_frame_errors; /* Received HDLC frame alignment error */
571  unsigned int rx_fifo_errors; /* Receiver FIFO overrun at hardware level.
572  * Possible cause: driver was too slow to re-program Rx DMA. */
573  unsigned int rx_missed_errors; /* deprecated */
574 
575  /* detailed tx_errors */
576  unsigned int tx_aborted_errors; /* deprecated. The same as tx_fifo_errors. */
577  unsigned int tx_carrier_errors; /* counter of times transmitter was not in operational state */
578 
579  unsigned int tx_fifo_errors; /* Transmitter FIFO overrun at hardware level.
580  * Possible cause: driver was too slow to re-program Tx DMA. */
581  unsigned int tx_heartbeat_errors;/* deprecated */
582  unsigned int tx_window_errors; /* deprecated */
583 
584  unsigned int tx_idle_packets; /* Counter of Idle Tx Data transmissions.
585  * Occurs in Voice/BitStream mode.
586  * Cause: User application supplies data too slowly. */
587 
588  unsigned int errors; /* Total of ALL errors. */
589 
590  /* current state of transmitter queue */
591  unsigned int current_number_of_frames_in_tx_queue;
592  unsigned int max_tx_queue_length;
593 
594  /* current state of receiver queue */
595  unsigned int current_number_of_frames_in_rx_queue;
596  unsigned int max_rx_queue_length;
597 
598  /* current state of Event queue */
599  unsigned int max_event_queue_length;
600  unsigned int current_number_of_events_in_event_queue;
601 
602  unsigned int rx_events; /* Total counter of all API Events. (On/Off Hook, DTMF, Ring...)*/
603  unsigned int rx_events_dropped; /* Counter of discarded events due to Rx Event queue being full.
604  * Possible cause: application too slow to "read" the events.*/
605  unsigned int rx_events_tone; /* Counter of Tone Events, such as DTMF. */
606 
607  /* HDLC-level abort condition */
608  unsigned int rx_hdlc_abort_counter; /* HDLC-level abort is considered an error by Sangoma HDLC engine.
609  * But, since it is a part of HDLC standard, an application may choose to ignore it. */
610 
612 
613 
614 #define WP_AFT_CHAN_ERROR_STATS(chan_stats,var) chan_stats.var++;chan_stats.errors++
615 
616 #define WP_AFT_RX_ERROR_SUM(chan_stats) chan_stats.rx_errors+ \
617  chan_stats.rx_dropped+ \
618  chan_stats.rx_length_errors + \
619  chan_stats.rx_crc_errors + \
620  chan_stats.rx_frame_errors + \
621  chan_stats.rx_fifo_errors + \
622  chan_stats.rx_missed_errors + \
623  chan_stats.rx_hdlc_abort_counter
624 
625 #define WP_AFT_TX_ERROR_SUM(chan_stats) chan_stats.tx_errors+ \
626  chan_stats.tx_dropped + \
627  chan_stats.tx_aborted_errors + \
628  chan_stats.tx_carrier_errors + \
629  chan_stats.tx_fifo_errors+ \
630  chan_stats.tx_heartbeat_errors + \
631  chan_stats.tx_window_errors
632 
633 typedef struct _DRIVER_VERSION {
634  unsigned int major;
635  unsigned int minor;
636  unsigned int minor1;
637  unsigned int minor2;
639 
640 #define WANPIPE_API_CMD_SZ 512
641 #define WANPIPE_API_DEV_CFG_MAX_SZ 337
642 
643 /* The the union size is max-cmd-result-span-chan-data_len */
644 #define WANPIPE_API_CMD_SZ_UNION WANPIPE_API_CMD_SZ - (sizeof(unsigned int)*3) - (sizeof(unsigned char)*2)
645 
646 
647 /* Each time you add a parameter to the wanpipe_api_dev_cfg_t you must update
648  WANPIPE_API_CMD_RESERVED_SZ as well as WANPIPE_API_DEV_CFG_SZ */
649 
650 /* rxflashtime hw_ec,hw_fax,loop */
651 #define WANPIPE_API_CMD_RESERVED_SZ 128 - sizeof(int)*1 - sizeof(char)*3
652 
653 /* The sizeof WANPIPE_API_DEV_CFG_SZ must account for every variable in
654  wanpipe_api_dev_cfg_t strcture */
655 
656 /* 20 int 4 chars */
657 #define WANPIPE_API_DEV_CFG_SZ sizeof(int)*20 + sizeof(char)*4 + WANPIPE_API_CMD_RESERVED_SZ + sizeof(wanpipe_chan_stats_t)
658 
659 
669 typedef struct wanpipe_api_dev_cfg
670 {
671  unsigned int hw_tdm_coding; /* Set/Get HW TDM coding: uLaw muLaw */
672  unsigned int hw_mtu_mru; /* Set/Get HW TDM MTU/MRU */
673  unsigned int usr_period; /* Set/Get User Period in ms */
674  unsigned int tdm_codec; /* Set/Get TDM Codec: SLinear */
675  unsigned int power_level; /* Set/Get Power level treshold */
676  unsigned int rx_disable; /* Enable/Disable Rx */
677  unsigned int tx_disable; /* Enable/Disable Tx */
678  unsigned int usr_mtu_mru; /* Set/Get User TDM MTU/MRU */
679  unsigned int ec_tap; /* Echo Cancellation Tap */
680  unsigned int rbs_poll; /* Enable/Disable RBS Polling */
681  unsigned int rbs_rx_bits; /* Rx RBS Bits */
682  unsigned int rbs_tx_bits; /* Tx RBS Bits */
683  unsigned int hdlc; /* HDLC based device */
684  unsigned int idle_flag; /* IDLE flag to Tx */
685  unsigned int fe_alarms; /* FE Alarms detected */
686  unsigned char fe_status; /* FE status - Connected or Disconnected */
687  unsigned int hw_dtmf; /* HW DTMF enabled */
688  unsigned int open_cnt; /* Open cnt */
689  unsigned int rx_queue_sz;
690  unsigned int tx_queue_sz;
691  /* Any new paramets should decrement the reserved size */
692  unsigned int rxflashtime; /* Set Rxflash time for Wink-Flash */
693  unsigned char hw_ec;
694  unsigned char hw_fax;
695  unsigned char loop;
696 
697  unsigned char reserved[WANPIPE_API_CMD_RESERVED_SZ];
698  /* Duplicate the structure below */
699  wanpipe_chan_stats_t stats; /* TDM Statistics */
701 
702 
714 typedef struct wanpipe_api_cmd
715 {
716  unsigned int cmd;
717  unsigned int result;
718  unsigned char span;
719  unsigned char chan;
721  union {
722  struct {
723  unsigned int hw_tdm_coding;
724  unsigned int hw_mtu_mru;
725  unsigned int usr_period;
726  unsigned int tdm_codec;
727  unsigned int power_level;
728  unsigned int rx_disable;
729  unsigned int tx_disable;
730  unsigned int usr_mtu_mru;
731  unsigned int ec_tap;
732  unsigned int rbs_poll;
733  unsigned int rbs_rx_bits;
734  unsigned int rbs_tx_bits;
735  unsigned int hdlc;
736  unsigned int idle_flag;
737  unsigned int fe_alarms;
738  unsigned char fe_status;
739  unsigned int hw_dtmf;
740  unsigned int open_cnt;
741  unsigned int rx_queue_sz;
742  unsigned int tx_queue_sz;
743  /* Any new paramets should decrement the reserved size */
744  unsigned int rxflashtime;
745  unsigned char hw_ec;
746  unsigned char hw_fax;
747  unsigned char loop;
748 
749  unsigned char reserved[WANPIPE_API_CMD_RESERVED_SZ];
751  };
753  wan_driver_version_t version;
754  wan_iovec_list_t iovec_list;
755  wan_api_ss7_cfg_status_t ss7_cfg_status;
756  struct {
757  unsigned char data[WANPIPE_API_CMD_SZ_UNION];
758  unsigned int data_len;
759  };
760  };
762 
763 /* \brief Initialize 'span' in wanpipe_api_cmd_t */
764 #define WANPIPE_API_CMD_INIT_SPAN(wp_cmd_ptr, span_no) ((wp_cmd_ptr)->span = (unsigned char)span_no)
765 
766 /* \brief Initialize 'channel' in wanpipe_api_cmd_t */
767 #define WANPIPE_API_CMD_INIT_CHAN(wp_cmd_ptr, chan_no) ((wp_cmd_ptr)->chan = (unsigned char)chan_no)
768 
775 typedef struct wanpipe_api_callbacks
776 {
777  int (*wp_rbs_event)(sng_fd_t fd, unsigned char rbs_bits);
778  int (*wp_dtmf_event)(sng_fd_t fd, unsigned char dtmf, unsigned char type, unsigned char port);
779  int (*wp_rxhook_event)(sng_fd_t fd, unsigned char hook_state);
780  int (*wp_ring_detect_event)(sng_fd_t fd, unsigned char ring_state);
781  int (*wp_ring_trip_detect_event)(sng_fd_t fd, unsigned char ring_state);
782  int (*wp_fe_alarm_event)(sng_fd_t fd, unsigned int fe_alarm_event);
783  int (*wp_link_status_event)(sng_fd_t fd, unsigned int link_status_event);
785 
796 typedef struct wanpipe_api
797 {
801 
802 /* \brief Initialize 'span' in wanpipe_api_t->wp_cmd */
803 #define WANPIPE_API_INIT_SPAN(wanpipe_api_ptr, span_no) WANPIPE_API_CMD_INIT_SPAN(&wanpipe_api_ptr->wp_cmd, span_no)
804 
805 /* \brief Initialize 'channel' in wanpipe_api_t->wp_cmd */
806 #define WANPIPE_API_INIT_CHAN(wanpipe_api_ptr, chan_no) WANPIPE_API_CMD_INIT_CHAN(&wanpipe_api_ptr->wp_cmd, chan_no)
807 
808 #pragma pack()
809 
810 
811 /***************************************************/
814 #endif
wanpipe_api_events
Events available on wanpipe api device.
unsigned char state
unsigned int rbs_rx_bits
unsigned char fe_status
unsigned int rxflashtime
unsigned int tx_queue_sz
wanpipe_api_cmds
Commands used with WANPIPE_IOCTL_API_CMD IOCTL.
WANPIPE(tm) Driver API Headers and Defines.
Wanpipe API Device Command Structure used with WANPIPE_IOCTL_API_CMD.
unsigned int rx_queue_sz
unsigned int usr_mtu_mru
TDM API Device Configuration Structure.
unsigned int hw_tdm_coding
BERT status and statistics.
unsigned int rbs_poll
int sng_fd_t
Windows/Unix file handle abstraction.
Wanpipe API Callback Structure.
int HANDLE
file handle type int, Ported from Windows
Definition: libsangoma.h:258
wanpipe_api_cmd_t wp_cmd
unsigned int rx_disable
TDM API channel statistics.
unsigned char span
wanpipe_api_callbacks_t wp_callback
unsigned int open_cnt
Wanpipe API Event Structure.
Fixed-length List of Memory Descriptors.
unsigned int fe_alarms
unsigned int hw_mtu_mru
WANPIPE_IOCTL_CODE
Wanpipe IOCTL Commands.
unsigned int ec_tap
unsigned char chan
wp_api_event_t event
Wanpipe API Command Structure.
WANPIPE_IOCTL_PIPEMON_CMDS
Commands used with WANPIPE_IOCTL_PIPEMON IOCTL.
unsigned int rbs_tx_bits
unsigned int errors
unsigned int synchonized_count
wanpipe_chan_stats_t stats
unsigned int tx_disable
unsigned int result
unsigned int usr_period
unsigned int tdm_codec
unsigned int idle_flag
wanpipe_cdev_ctrl_cmds
Commands used with WANPIPE_IOCTL_CDEV_CTRL IOCTL.
unsigned int hw_dtmf
unsigned int power_level