diff -dur include/aft_analog.h /usr/include/wanpipe/aft_analog.h
--- include/aft_analog.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/aft_analog.h	2009-07-14 13:02:00.000000000 -0400
@@ -39,6 +39,7 @@
 
 void aft_analog_fifo_adjust(sdla_t *card,u32 level);
 
+#define IS_A700_ANALOG_CARD(card) (card->adptr_type == AFT_ADPTR_FLEXBRI && card->comm_port == 1)
 
 #endif
 
diff -dur include/aft_bri.h /usr/include/wanpipe/aft_bri.h
--- include/aft_bri.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/aft_bri.h	2009-07-14 13:02:00.000000000 -0400
@@ -69,6 +69,7 @@
 	return card->fe.bri_param.use_512khz_recovery_clock;	
 }
 
+#define IS_A700_CARD(card) (card->adptr_type == AFT_ADPTR_FLEXBRI) 
 
 #endif/* WAN_KERNEL */
 
Only in /usr/include/wanpipe/: aft_core.h
Only in /usr/include/wanpipe/: aft_core_hwiface.h
Only in /usr/include/wanpipe/: aft_core_options.h
Only in /usr/include/wanpipe/: aft_core_private.h
Only in /usr/include/wanpipe/: aft_core_prot.h
Only in /usr/include/wanpipe/: aft_core_user.h
Only in /usr/include/wanpipe/: aft_core_utils.h
diff -dur include/if_wanpipe_common.h /usr/include/wanpipe/if_wanpipe_common.h
--- include/if_wanpipe_common.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/if_wanpipe_common.h	2009-07-14 13:02:00.000000000 -0400
@@ -19,20 +19,16 @@
 
 #if defined(WAN_KERNEL)
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <wanpipe_debug.h>
-# include <wanpipe_common.h>
-# include <wanpipe_kernel.h>
-#elif defined(__LINUX__)
+#if defined(__LINUX__)
 # include <linux/version.h>
-# include <linux/wanpipe_debug.h>
-# include <linux/wanpipe_common.h>
-# include <linux/wanpipe_kernel.h>
-# include <linux/if_wanpipe.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_debug.h>
-# include <wanpipe_common.h>
-# include <wanpipe_kernel.h>
+#endif
+
+# include "wanpipe_debug.h"
+# include "wanpipe_common.h"
+# include "wanpipe_kernel.h"
+
+#if defined(__LINUX__)
+# include "if_wanpipe.h"
 #endif
 
 
@@ -125,25 +121,39 @@
 	void 		*lip;
 	unsigned int    lip_prot;
 #elif defined(__WINDOWS__)
-
-	void		*prot_ptr;
-	netdevice_t*	dev;
-	unsigned char	state;
-	unsigned char	usedby;
-
+	/* !!! IMPORTANT !!! <- Do not move this parameter (GENERIC-PPP) */
+	void*		*prot_ptr;
+	netdevice_t 	*next;		/*slave;*/
 	void		*card;	
+	struct net_device_stats	if_stats;
+	
+	atomic_t receive_block;
+	atomic_t command;
+	atomic_t disconnect;
+	
+	struct sock *sk;		/* Wanpipe Sock bind's here */ 
+	
+	wan_tasklet_t wanpipe_task;    /* Immediate BH handler task */
+	
+	unsigned char rw_bind;			  /* Sock bind state */
+	unsigned char usedby;
+	unsigned char state;
+	unsigned char svc;
+	unsigned short lcn;
+	unsigned int config_id;
+	
+	unsigned long	used;
+	unsigned long	api_state;
+	netdevice_t	*dev;
+	wan_skb_queue_t rx_queue;
+	wan_tasklet_t	bh_task;
+	wan_timer_t	dev_timer;
 
-	void* sk;
-
-	void 		*lip;
-
-	//A104 additions
 	unsigned int	protocol;
-	wan_tasklet_t	bh_task;
 
-	//ADSL additions
-	wan_tasklet_t	wanpipe_task;    /* Immediate BH handler task */
+	void 		*lip;
 	unsigned int    lip_prot;
+
 #endif
 	int			is_netdev;
 	wanpipe_common_iface_t	iface;
@@ -279,7 +289,7 @@
 	wanpipe_common_t *common = (wanpipe_common_t*)chan_ptr;
 	
 	if (!wan_test_and_clear_bit(WAN_API_INIT,&common->used)){
-		DEBUG_EVENT("%s: Error: Failed to unregister API!\n",
+		DEBUG_TEST("%s: Error: Failed to unregister API!\n",
 				devname);
 		return -EINVAL;
 	}
Only in /usr/include/wanpipe/: oct6100_api
diff -dur include/sdla_56k.h /usr/include/wanpipe/sdla_56k.h
--- include/sdla_56k.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_56k.h	2009-07-14 13:02:00.000000000 -0400
@@ -85,14 +85,6 @@
 
 #ifdef WAN_KERNEL
 
-#if defined(__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__)
-/*# include <sdla_front_end.h>*/
-#elif defined (__WINDOWS__)
-//# include <sdla_front_end.h>
-#else
-//# include <linux/sdla_front_end.h>
-#endif
-
 typedef struct {
 	unsigned char	RLOS_56k;
 	unsigned char	RR8_reg_56k;
diff -dur include/sdla_adsl.h /usr/include/wanpipe/sdla_adsl.h
--- include/sdla_adsl.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_adsl.h	2009-07-14 13:02:00.000000000 -0400
@@ -22,17 +22,7 @@
 #  define __SDLA_ADSL_H
 
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <sdla_adsl_iface.h>
-#elif defined(__WINDOWS__)
-# include <sdla_adsl_iface.h>
-#elif defined(__LINUX__) || defined(__KERNEL__)
-# include <linux/sdla_adsl_iface.h>
-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <sdla_adsl_iface.h>
-#else
-# error "Unsuported OS!"
-#endif
+#include "sdla_adsl_iface.h"
 
 #define ADSL_TEST_DRIVER_RESPONSE	0x01
 #define	ADSL_READ_DRIVER_VERSION	0x02    	
@@ -80,7 +70,7 @@
 {
 	wanpipe_common_t 	common;
 	void*			pAdapter;
-	char			if_name[IFNAMSIZ];
+	char			if_name[WAN_IFNAME_SZ];
 	u_char			macAddr[6];
 	atomic_t		udp_pkt_len;
 	unsigned char 		udp_pkt_data[sizeof(wan_udp_pkt_t)];
Only in include/: sdla_aft_te1.h
Only in include/: sdla_aft_te1_iface.h
diff -dur include/sdla_aft_te3.h /usr/include/wanpipe/sdla_aft_te3.h
--- include/sdla_aft_te3.h	2009-07-02 11:44:41.000000000 -0400
+++ /usr/include/wanpipe/sdla_aft_te3.h	2009-07-14 13:02:00.000000000 -0400
@@ -43,13 +43,6 @@
 #define XILINX_HDLC_RX_INTR_PENDING_REG	0x54
 
 
-/* Possible RX packet errors */ 
-enum {
-	WP_FIFO_ERROR_BIT,
-	WP_CRC_ERROR_BIT,
-	WP_ABORT_ERROR_BIT,
-};
-
 /* Maximum number of frames in a fifo
  * where frame lengths vary from 1 to 4 bytes */
 #define WP_MAX_FIFO_FRAMES	7
@@ -1066,103 +1059,6 @@
         unsigned char data[MAX_DATA_SIZE];
 };
 
-#pragma pack(1)
-typedef struct {
-	unsigned char	error_flag;
-	unsigned short	time_stamp;
-	unsigned char	reserved[13];
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr;
-        unsigned char  	data[1];
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	attr;
-	unsigned char   misc_Tx_bits;
-	unsigned char  	reserved[14];
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr;
-	unsigned char	data[1];
-} api_tx_element_t;
-
-/* the operational statistics structure */
-typedef struct {
-
-        /* Data frame transmission statistics */
-        unsigned long Data_frames_Tx_count ;
-        /* # of frames transmitted */
-        unsigned long Data_bytes_Tx_count ;
-        /* # of bytes transmitted */
-        unsigned long Data_Tx_throughput ;
-        /* transmit throughput */
-        unsigned long no_ms_for_Data_Tx_thruput_comp ;
-        /* millisecond time used for the Tx throughput computation */
-        unsigned long Tx_Data_discard_lgth_err_count ;
-
-        /* Data frame reception statistics */
-        unsigned long Data_frames_Rx_count ;
-        /* number of frames received */
-        unsigned long Data_bytes_Rx_count ;
-        /* number of bytes received */
-        unsigned long Data_Rx_throughput ;
-        /* receive throughput */
-        unsigned long no_ms_for_Data_Rx_thruput_comp ;
-        /* millisecond time used for the Rx throughput computation */
-        unsigned long Rx_Data_discard_short_count ;
-        /* received Data frames discarded (too short) */
-        unsigned long Rx_Data_discard_long_count ;
-        /* received Data frames discarded (too long) */
-        unsigned long Rx_Data_discard_inactive_count ;
-        /* received Data frames discarded (link inactive) */
-
-        /* Incomming frames with a format error statistics */
-        unsigned short Rx_frm_incomp_CHDLC_hdr_count ;
-        /* frames received of with incomplete Cisco HDLC header */
-        unsigned short Rx_frms_too_long_count ;
-        /* frames received of excessive length count */
-
-       /* CHDLC link active/inactive and loopback statistics */
-        unsigned short link_active_count ;
-        /* number of times that the link went active */
-        unsigned short link_inactive_modem_count ;
-        /* number of times that the link went inactive (modem failure) */
-        unsigned short link_inactive_keepalive_count ;
-        /* number of times that the link went inactive (keepalive failure) */
-        unsigned short link_looped_count ;
-        /* link looped count */
-
-        unsigned long Data_frames_Tx_realign_count;
-
-} aft_op_stats_t;
-
-typedef struct {
-        unsigned short Rx_overrun_err_count;
-        unsigned short Rx_crc_err_count ;               /* receiver CRC error count */
-        unsigned short Rx_abort_count ;         /* abort frames recvd count */
-        unsigned short Rx_hdlc_corrupiton;      /* receiver disabled */
-        unsigned short Rx_pci_errors;           /* missed tx underrun interrupt count */
-        unsigned short Rx_dma_descr_err;        /*secondary-abort frames tx count */
-        unsigned short DCD_state_change_count ; /* DCD state change */
-        unsigned short CTS_state_change_count ; /* CTS state change */
-
-        unsigned short Tx_pci_errors;           /* missed tx underrun interrupt count */
-        unsigned short Tx_dma_errors;           /* missed tx underrun interrupt count */
-
-        unsigned int Tx_pci_latency;            /* missed tx underrun interrupt count */
-        unsigned int Tx_dma_len_nonzero;        /* Tx dma descriptor len not zero */
-
-} aft_comm_err_stats_t;
-
-
-#pragma pack()
-
-#undef  wan_udphdr_data
-#define wan_udphdr_data	wan_udphdr_u.aft.data
-
 /*==========================================
  * Board CPLD Interface Section
  *
@@ -1230,34 +1126,6 @@
 		 		 sizeof(wan_cmd_t))
 
  
-enum {
-        ROUTER_UP_TIME = 0x50,
-        ENABLE_TRACING,
-        DISABLE_TRACING,
-        GET_TRACE_INFO,
-        READ_CODE_VERSION,
-        FLUSH_OPERATIONAL_STATS,
-        OPERATIONAL_STATS,
-        READ_OPERATIONAL_STATS,
-        READ_CONFIGURATION,
-        READ_COMMS_ERROR_STATS,
-        FLUSH_COMMS_ERROR_STATS,
-        AFT_LINK_STATUS
-};
-
-#define UDPMGMT_SIGNATURE		"AFTPIPEA"
-
-/* the line trace status element presented by the frame relay code */
-typedef struct {
-        unsigned char flag	; /* ready flag */
-        unsigned short length   ; /* trace length */
-        unsigned char rsrv0[2]  ; /* reserved */
-        unsigned char attr      ; /* trace attributes */
-        unsigned short tmstamp  ; /* time stamp */
-        unsigned char rsrv1[4]  ; /* reserved */
-        unsigned long offset    ; /* buffer absolute address */
-}aft_trc_el_t;
-
 
 typedef struct wp_rx_element
 {
@@ -1349,10 +1217,5 @@
 #endif /* WAN_KERNEL */
 
 
-#if defined(__LINUX__)
-enum {
-	SIOC_AFT_CUSTOMER_ID = SIOC_WANPIPE_DEVPRIVATE
-};
-#endif
 
 #endif
diff -dur include/sdla_asyhdlc.h /usr/include/wanpipe/sdla_asyhdlc.h
--- include/sdla_asyhdlc.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_asyhdlc.h	2009-07-14 13:02:00.000000000 -0400
@@ -44,7 +44,9 @@
 #define FLUSH_GLOBAL_STATISTICS				0x05	/* flush the global statistics */
 #define SET_MODEM_STATUS						0x06	/* set the status of DTR and/or RTS */
 #define READ_MODEM_STATUS						0x07	/* read the current status of CTS and DCD */
+#undef READ_COMMS_ERROR_STATS
 #define READ_COMMS_ERROR_STATS				0x08	/* read the communication error statistics */
+#undef FLUSH_COMMS_ERROR_STATS
 #define FLUSH_COMMS_ERROR_STATS				0x09	/* flush the communication error statistics */
 #define READ_ASY_CODE_VERSION					0x20	/* read the code version */
 #define SET_ASY_INTERRUPT_TRIGGERS			0x30	/* set the application interrupt triggers */
@@ -477,7 +479,7 @@
 
 
 
-
+#undef UDPMGMT_SIGNATURE
 #define UDPMGMT_SIGNATURE	"CTPIPEAB"
 #define UDPMGMT_SIGNATURE_LEN	8
 
@@ -514,28 +516,6 @@
 } trace_pkt_t;
 #endif
 
-typedef struct {
-	unsigned char	error_flag	;
-	unsigned short	time_stamp	;
-	unsigned char	reserved[13]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        unsigned char  	data[1]    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	attr		;
-	unsigned char   misc_Tx_bits	;
-	unsigned char  	reserved[14]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	unsigned char	data[1]		;
-} api_tx_element_t;
-
 /* Special UDP drivers management commands */
 #define CPIPE_ENABLE_TRACING				0x50
 #define CPIPE_DISABLE_TRACING				0x51
diff -dur include/sdla_atm.h /usr/include/wanpipe/sdla_atm.h
--- include/sdla_atm.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_atm.h	2009-07-14 13:02:00.000000000 -0400
@@ -43,14 +43,19 @@
 #define FLUSH_GLOBAL_STATISTICS				0x05	/* flush the global statistics */
 #define SET_MODEM_STATUS						0x06	/* set the status of DTR and/or RTS */
 #define READ_MODEM_STATUS						0x07	/* read the current status of CTS and DCD */
+#undef READ_COMMS_ERROR_STATS
 #define READ_COMMS_ERROR_STATS				0x08	/* read the communication error statistics */
+
+#undef FLUSH_COMMS_ERROR_STATS
 #define FLUSH_COMMS_ERROR_STATS				0x09	/* flush the communication error statistics */
 #define SET_TRACE_CONFIGURATION				0x0A	/* set the line trace configuration */
 #define READ_TRACE_CONFIGURATION				0x0B	/* read the line trace configuration */
 #define READ_TRACE_STATISTICS					0x0C	/* read the trace statistics */
+#undef FLUSH_TRACE_STATISTICS
 #define FLUSH_TRACE_STATISTICS				0x0D	/* flush the trace statistics */
 
 /* PHY-level interface commands */
+#undef 	PHY_READ_CODE_VERSION
 #define PHY_READ_CODE_VERSION					0x20	/* read the ATM code version */
 #define PHY_READ_EXCEPTION_CONDITION		0x21	/* read a PHY-level exception condition from the adapter */
 #define PHY_SET_CONFIGURATION					0x22	/* set the PHY-level configuration */
@@ -658,9 +663,10 @@
 #define TIMER_APP_INT_PEND		PHY_TIMER_INT_PEND
 #define TRACE_APP_INT_PEND		PHY_TRACE_INT_PEND
 
-
+#undef READ_CODE_VERSION
 #define READ_CODE_VERSION		PHY_READ_CODE_VERSION
 
+#undef READ_CONFIGURATION
 #define READ_CONFIGURATION		PHY_READ_CONFIGURATION
 #define SET_CONFIGURATION		PHY_SET_CONFIGURATION
 
@@ -670,8 +676,6 @@
 #define SET_INTERRUPT_TRIGGERS		PHY_SET_INTERRUPT_TRIGGERS
 #define READ_INTERRUPT_TRIGGERS		PHY_READ_INTERRUPT_TRIGGERS
 
-#define UDPMGMT_SIGNATURE		"ATMPIPEA"
-
 //#define FT1_MONITOR_STATUS_CTRL		DFLT_TEMPLATE_VALUE
 //#define ENABLE_READ_FT1_STATUS		DFLT_TEMPLATE_VALUE
 //#define ENABLE_READ_FT1_OP_STATS	DFLT_TEMPLATE_VALUE		
@@ -686,12 +690,7 @@
 //#define GET_TRACE_INFO			DFLT_TEMPLATE_VALUE
 
 enum {
-	ROUTER_UP_TIME = 0x50,
-	FT1_READ_STATUS,
-	SET_FT1_MODE,
-	ENABLE_TRACING,	
-	DISABLE_TRACING,
-	GET_TRACE_INFO,
+	FT1_READ_STATUS = WANPIPE_PROTOCOL_PRIVATE,
 	FT1_MONITOR_STATUS_CTRL,
 	ENABLE_READ_FT1_STATUS,
 	ENABLE_READ_FT1_OP_STATS,
@@ -703,7 +702,7 @@
 #define	ATM_TRACE_PDU   0x02
 #define ATM_TRACE_DATA  0x04
 
-
+#undef READ_OPERATIONAL_STATS
 #define READ_OPERATIONAL_STATS		PHY_READ_OPERATIONAL_STATS
 //#define SET_TRACE_CONFIGURATION		DFLT_TEMPLATE_VALUE
 //#define TRACE_ACTIVE			DFLT_TEMPLATE_VALUE	
diff -dur include/sdla_bitstrm.h /usr/include/wanpipe/sdla_bitstrm.h
--- include/sdla_bitstrm.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_bitstrm.h	2009-07-14 13:02:00.000000000 -0400
@@ -46,7 +46,9 @@
 #define FLUSH_GLOBAL_STATISTICS				0x05	/* flush the global statistics */
 #define SET_MODEM_STATUS						0x06	/* set the status of DTR and/or RTS */
 #define READ_MODEM_STATUS						0x07	/* read the current status of CTS and DCD */
+#undef	READ_COMMS_ERROR_STATS
 #define READ_COMMS_ERROR_STATS				0x08	/* read the communication error statistics */
+#undef	FLUSH_COMMS_ERROR_STATS
 #define FLUSH_COMMS_ERROR_STATS				0x09	/* flush the communication error statistics */
 
 /* BSTRM-level interface commands */
@@ -443,52 +445,30 @@
 } SHARED_MEMORY_INFO_STRUCT;
 
 
+/* Special UDP drivers management commands */
+#define BPIPE_ROUTER_UP_TIME				WANPIPEMON_ROUTER_UP_TIME
+#define BPIPE_ENABLE_TRACING				WANPIPEMON_ENABLE_TRACING
+#define BPIPE_DISABLE_TRACING				WANPIPEMON_DISABLE_TRACING
+#define BPIPE_GET_TRACE_INFO				WANPIPEMON_GET_TRACE_INFO
 
- 
-
-
-typedef struct {
-	unsigned char	error_flag	;
-	unsigned short	time_stamp	;
-	unsigned char	channel		;
-	unsigned char   direction	;
-	unsigned char	reserved[11]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        unsigned char   data[1]    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	attr		;
-	unsigned char  	reserved[15]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	unsigned char	data[1]		;
-} api_tx_element_t;
+#define CPIPE_GET_IBA_DATA					WANPIPEMON_GET_IBA_DATA
 
+#define BPIPE_FT1_READ_STATUS				WANPIPEMON_DRIVER_STAT_IFSEND
+#define BPIPE_DRIVER_STAT_IFSEND			WANPIPEMON_DRIVER_STAT_IFSEND
+#define BPIPE_DRIVER_STAT_INTR				WANPIPEMON_DRIVER_STAT_INTR
+#define BPIPE_DRIVER_STAT_GEN				WANPIPEMON_DRIVER_STAT_GEN
+#define BPIPE_FLUSH_DRIVER_STATS			WANPIPEMON_FLUSH_DRIVER_STATS
 
-/* Special UDP drivers management commands */
-#define BPIPE_ENABLE_TRACING				0x50
-#define BPIPE_DISABLE_TRACING				0x51
-#define BPIPE_GET_TRACE_INFO				0x52
-#define BPIPE_GET_IBA_DATA				0x53
-#define BPIPE_FT1_READ_STATUS				0x54
-#define BPIPE_DRIVER_STAT_IFSEND			0x55
-#define BPIPE_DRIVER_STAT_INTR				0x56
-#define BPIPE_DRIVER_STAT_GEN				0x57
-#define BPIPE_FLUSH_DRIVER_STATS			0x58
-#define BPIPE_ROUTER_UP_TIME				0x59
 
 
 /* modem status changes */
 #define DCD_HIGH			0x08
 #define CTS_HIGH			0x20
 
-#define UDPMGMT_SIGNATURE	"BTPIPEAB"
+#ifdef UDPMGMT_SIGNATURE
+ #undef UDPMGMT_SIGNATURE
+ #define UDPMGMT_SIGNATURE	"BTPIPEAB"
+#endif
 /* valid ip_protocol for UDP management */
 #define UDPMGMT_UDP_PROTOCOL 0x11
 
diff -dur include/sdla_bri.h /usr/include/wanpipe/sdla_bri.h
--- include/sdla_bri.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_bri.h	2009-07-14 13:02:00.000000000 -0400
@@ -24,18 +24,20 @@
 #ifndef	__SDLA_BRI_H
 # define __SDLA_BRI_H
 
-#if defined(__LINUX__)
-# include <linux/xhfc24succ.h>
-#else
-# include <xhfc24succ.h>
-#endif
+
+#include "xhfc24succ.h"
 
 /*******************************************************************************
 **			  DEFINES and MACROS
 *******************************************************************************/
 
 #define IS_BRI_CARD(card)		IS_BRI_FEMEDIA(&(card)->fe)
-#define IS_BRI_CLK(card)		card->fe.fe_cfg.cfg.bri.clock_mode
+
+#define BRI_FE_CFG(fe_cfg)		(fe_cfg.cfg.bri)
+
+#define BRI_FE_CLK(fe_cfg)		BRI_FE_CFG(fe_cfg).clock_mode
+
+#define BRI_CARD_CLK(card)		BRI_FE_CLK(card->fe.fe_cfg)
 
 #define WAN_BRI_START_CHANNEL		1
 
@@ -50,6 +52,7 @@
 #define MAX_BRI_MODULES			12
 #define MAX_BRI_CHANNELS		2	/* Number of channels per device */
 #define MAX_BRI_LINES			(MAX_BRI_MODULES*MAX_BRI_CHANNELS)
+#define A700_MAX_BRI_LINES		4
 
 /*	
 	The maximum number of BRI timeslots is 32.
@@ -188,7 +191,11 @@
 
 #else
 
-#warning "WAN_DEBUG_FE - Debugging Defined"
+#if defined(__WINDOWS__)
+# pragma message("WAN_DEBUG_FE - Debugging Defined")
+#else
+# warning "WAN_DEBUG_FE - Debugging Defined"
+#endif
 
 /* NT/TE */
 # define WRITE_BRI_REG(mod_no,reg,val)					\
diff -dur include/sdla_bscmp.h /usr/include/wanpipe/sdla_bscmp.h
--- include/sdla_bscmp.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_bscmp.h	2009-07-14 13:02:00.000000000 -0400
@@ -21,9 +21,11 @@
 #define FLUSH_BSC_ERROR_STATISTICS     0x0C
 #define FLUSH_BSC_TEXT_BUFFERS         0x0D
 #define SET_CONFIGURATION              0x0E
+#undef READ_CONFIGURATION
 #define READ_CONFIGURATION             0x0F
 #define SET_MODEM_STATUS               0x10
 #define READ_MODEM_STATUS              0x11
+#undef READ_CODE_VERSION         
 #define READ_CODE_VERSION              0x12
 #define ADD_STATION						0x20
 #define DELETE_STATION					0x21
@@ -113,27 +115,6 @@
 	unsigned char station_flags	;
 }ADD_STATION_STRUCT;
 
-typedef struct {
-	unsigned char	station		;
-	unsigned short	time_stamp	;
-	unsigned char	reserved[13]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        void *   	data    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	station		;
-	unsigned char   misc_tx_rx_bits ;
-	unsigned char  	reserved[14]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	void *		data		;
-} api_tx_element_t;
 
 #define SIOC_WANPIPE_EXEC_CMD	SIOC_WANPIPE_DEVPRIVATE
 
diff -dur include/sdla_bscstrm.h /usr/include/wanpipe/sdla_bscstrm.h
--- include/sdla_bscstrm.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_bscstrm.h	2009-07-14 13:02:00.000000000 -0400
@@ -233,28 +233,6 @@
 #define RX_EXCESSIVE_LGTH_ERR_INT_LVL  0x10   /* the received block was too long (interrupt level) */
 #define RX_EXCESSIVE_LGTH_ERR_APP_LVL  0x20   /* the received block was too long (application level) */
 
-typedef struct {
-	unsigned char	station		;
-	unsigned short	time_stamp	;
-	unsigned char	reserved[13]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        unsigned char 	data[1]    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	station		;
-	unsigned char   misc_tx_rx_bits ;
-	unsigned char  	reserved[14]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	unsigned char	data[1]		;
-} api_tx_element_t;
-
 #pragma pack()
 
 #define SIOC_WANPIPE_EXEC_CMD	SIOC_WANPIPE_DEVPRIVATE
diff -dur include/sdla_chdlc.h /usr/include/wanpipe/sdla_chdlc.h
--- include/sdla_chdlc.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_chdlc.h	2009-07-14 13:02:00.000000000 -0400
@@ -32,14 +32,11 @@
 #define _SDLA_CHDLC_H
 
 #if defined(__LINUX__)
-# include <linux/if_wanpipe.h>
-# include <linux/wanpipe_sppp_iface.h>
-#elif defined(__WINDOWS__)
-#if defined(__KERNEL__)
-# include <wanpipe_sppp_iface.h>
+# include "if_wanpipe.h"
 #endif
-#else
-# include <wanpipe_sppp_iface.h>
+
+#if defined (__KERNEL__)
+# include "wanpipe_sppp_iface.h"
 #endif
 
 /*------------------------------------------------------------------------
@@ -92,7 +89,11 @@
 #define FLUSH_GLOBAL_STATISTICS		0x05
 #define SET_MODEM_STATUS		0x06	/* set status of DTR or RTS */
 #define READ_MODEM_STATUS		0x07	/* read status of CTS and DCD */
-#define READ_COMMS_ERROR_STATS		0x08	
+
+#undef  READ_COMMS_ERROR_STATS
+#define READ_COMMS_ERROR_STATS		0x08
+
+#undef 	FLUSH_COMMS_ERROR_STATS
 #define FLUSH_COMMS_ERROR_STATS		0x09
 #define SET_TRACE_CONFIGURATION		0x0A	/* set the line trace config */
 #define READ_TRACE_CONFIGURATION	0x0B	/* read the line trace config */
@@ -106,13 +107,15 @@
 #define FT1_MONITOR_STATUS_CTRL		0x1C	/* set the status of the FT1 monitoring */
 
 #define READ_FT1_OPERATIONAL_STATS	0x1D	/* read the S508/FT1 operational statistics */
+
+#undef 	SET_FT1_MODE
 #define SET_FT1_MODE			0x1E	/* set the operational mode of the S508/FT1 module */
 
 /* CHDLC-level interface commands */
-/*#define READ_CHDLC_CODE_VERSION		0x20*/	
+#define READ_CHDLC_CODE_VERSION		0x20	
 #define READ_CHDLC_EXCEPTION_CONDITION	0x21	/* read exception condition from the adapter */
 #define SET_CHDLC_CONFIGURATION		0x22
-/*#define READ_CHDLC_CONFIGURATION	0x23*/
+#define READ_CHDLC_CONFIGURATION	0x23
 #define ENABLE_CHDLC_COMMUNICATIONS	0x24
 #define DISABLE_CHDLC_COMMUNICATIONS	0x25
 #define READ_CHDLC_LINK_STATUS		0x26
@@ -132,27 +135,18 @@
 /* read application interrupt trigger configuration */
 
 /* Special UDP drivers management commands */
-#define CPIPE_ENABLE_TRACING				0x50
-#define CPIPE_DISABLE_TRACING				0x51
-#define CPIPE_GET_TRACE_INFO				0x52
-#define CPIPE_GET_IBA_DATA				0x53
-#define DIGITAL_LOOPTEST				CPIPE_GET_IBA_DATA
-#define CPIPE_FT1_READ_STATUS				0x54
-#define CPIPE_DRIVER_STAT_IFSEND			0x55
-#define CPIPE_DRIVER_STAT_INTR				0x56
-#define CPIPE_DRIVER_STAT_GEN				0x57
-#define CPIPE_FLUSH_DRIVER_STATS			0x58
-#define CPIPE_ROUTER_UP_TIME				0x59
+#define CPIPE_ROUTER_UP_TIME				WANPIPEMON_ROUTER_UP_TIME
+#define CPIPE_ENABLE_TRACING				WANPIPEMON_ENABLE_TRACING
+#define CPIPE_DISABLE_TRACING				WANPIPEMON_DISABLE_TRACING
+#define CPIPE_GET_TRACE_INFO				WANPIPEMON_GET_TRACE_INFO
+#define DIGITAL_LOOPTEST					WANPIPEMON_DIGITAL_LOOPTEST
+#define CPIPE_GET_IBA_DATA					WANPIPEMON_GET_IBA_DATA
+#define CPIPE_FT1_READ_STATUS				WANPIPEMON_FT1_READ_STATUS
+#define CPIPE_DRIVER_STAT_IFSEND			WANPIPEMON_DRIVER_STAT_IFSEND
+#define CPIPE_DRIVER_STAT_INTR				WANPIPEMON_DRIVER_STAT_INTR
+#define CPIPE_DRIVER_STAT_GEN				WANPIPEMON_DRIVER_STAT_GEN	
+#define CPIPE_FLUSH_DRIVER_STATS			WANPIPEMON_FLUSH_DRIVER_STATS
 
-#if 0
-#define CPIPE_MPPP_TRACE_ENABLE				0x60
-#define CPIPE_MPPP_TRACE_DISABLE			0x61
-#define CPIPE_TE1_56K_STAT				0x62	/* TE1_56K */
-#define CPIPE_GET_MEDIA_TYPE				0x63	/* TE1_56K */
-#define CPIPE_FLUSH_TE1_PMON				0x64	/* TE1     */
-#define CPIPE_READ_REGISTER				0x65	/* TE1_56K */
-#define CPIPE_TE1_CFG					0x66	/* TE1     */
-#endif
 
 /* Driver specific commands for API */
 #define	CHDLC_READ_TRACE_DATA		0xE4	/* read trace data */
@@ -706,7 +700,14 @@
 } ft1_exec_t;
 
 
+/* By default UDPMGMT Signature is AFT, if user
+   includes the sdla_chdlc.h file then its assumed that
+   they wan't to use legacy API variant */
+#ifdef UDPMGMT_SIGNATURE
+#undef UDPMGMT_SIGNATURE
 #define UDPMGMT_SIGNATURE	"CTPIPEAB"
+#endif
+
 #define UDPMGMT_SIGNATURE_LEN	8
 
 
@@ -742,30 +743,6 @@
 } trace_pkt_t;
 #endif
 
-typedef struct {
-	unsigned char	error_flag	;
-	unsigned short	time_stamp	;
-	unsigned int	sec		;
-	unsigned int    usec		;
-	unsigned char	reserved[5]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        unsigned char  	data[1]    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	attr		;
-	unsigned char   misc_Tx_bits	;
-	unsigned char  	reserved[14]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	unsigned char	data[1]		;
-} api_tx_element_t;
-
 #endif  //HDLC_PROT_ONLY
 /* ----------------------------------------------------------------------------
  *   Constants for the SET_FT1_CONFIGURATION/READ_FT1_CONFIGURATION command
diff -dur include/sdladrv.h /usr/include/wanpipe/sdladrv.h
--- include/sdladrv.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdladrv.h	2009-07-14 13:02:00.000000000 -0400
@@ -68,13 +68,16 @@
 **			I N C L U D E S				**	
 ******************************************************************
 */
-
-
 #if defined(__LINUX__)
 # include <linux/version.h>
-# include <linux/wanpipe_kernel.h>
-# include <linux/sdlasfm.h>
-#elif defined(__FreeBSD__)
+#endif
+
+#include "wanpipe_kernel.h"
+#include "sdlasfm.h"
+#include "sdlapci.h"
+#include "wanpipe_api.h"
+
+#if defined(__FreeBSD__)
 # if defined(__SDLADRV__)
 #  if defined(SDLA_AUTO_PROBE)
 #   include <sdla_bsd.h>
@@ -86,8 +89,6 @@
 # ifdef __SDLADRV__
 #  include <dev/ic/sdla_dev.h>
 # endif
-#elif defined(__WINDOWS__)
-# include <wanpipe_kernel.h>
 #endif
 
 /*
@@ -107,59 +108,67 @@
 #define	SDLA_MAXIORANGE		4	/* maximum I/O port range */
 #define	SDLA_WINDOWSIZE		0x2000	/* default dual-port memory window size */
 
-/* */
-#define SDLA_MEMBASE			0x01
-#define SDLA_MEMEND			0x02
-#define SDLA_MEMSIZE			0x03
-#define SDLA_IRQ			0x04
-#define SDLA_ADAPTERTYPE		0x05
-#define SDLA_CPU			0x06
-#define SDLA_SLOT			0x07
-#define SDLA_IOPORT			0x08
-#define SDLA_IORANGE			0x09
-#define SDLA_CARDTYPE			0x0A
-#define SDLA_DMATAG			0x0B
-#define SDLA_MEMORY			0x0C
-#define SDLA_PCIEXTRAVER		0x0D
-#define SDLA_HWTYPE			0x0E
-#define SDLA_BUS			0x0F
-#define SDLA_BASEADDR			0x10
-#define SDLA_COREREV			0x11
-#define SDLA_HWCPU_USEDCNT		0x12
-#define SDLA_ADAPTERSUBTYPE		0x13
-#define SDLA_HWEC_NO			0x14
-#define SDLA_COREID			0x15
-#define SDLA_PCIEXPRESS			0x16
-#define SDLA_PORTS_NO			0x17
-#define SDLA_HWPORTUSED			0x18
-#define SDLA_HWPORTREG			0x19
-#define SDLA_PORT_MAP			0x1A
-#define SDLA_RECOVERY_CLOCK_FLAG	0x1B
-#define SDLA_HWPORTREGMAP		0x1C
+enum {
+       SDLA_MEMBASE            = 0x01,
+       SDLA_MEMEND,
+       SDLA_MEMSIZE,
+       SDLA_IRQ,
+       SDLA_ADAPTERTYPE,
+       SDLA_CPU,
+       SDLA_SLOT,
+       SDLA_IOPORT,
+       SDLA_IORANGE,
+       SDLA_CARDTYPE,
+       SDLA_DMATAG,
+       SDLA_MEMORY,
+       SDLA_PCIEXTRAVER,
+       SDLA_HWTYPE,
+       SDLA_BUS,
+       SDLA_BASEADDR,
+       SDLA_COREREV,
+       SDLA_HWCPU_USEDCNT,
+       SDLA_ADAPTERSUBTYPE,
+       SDLA_HWEC_NO,
+       SDLA_COREID,
+       SDLA_PCIEXPRESS,
+       SDLA_CHANS_NO,
+       SDLA_HWPORTUSED,
+       SDLA_HWLINEREG,
+       SDLA_HWLINEREGMAP,
+       SDLA_CHANS_MAP,
+       SDLA_RECOVERY_CLOCK_FLAG,
+	   SDLA_HWTYPE_USEDCNT
+};
 
-#define SDLA_MAX_CPUS		2
+#define SDLA_MAX_CPUS			2
 
 /* Serial card - 2, A104 - 4, A108 - 8, A200/A400 - 1, A500-24  */
-#define SDLA_MAX_HWDEVS		32
-#define SDLA_MAX_HWPORTS	32
+#define SDLA_MAX_HWDEVS			32
+#define SDLA_MAX_HWPORTS		32
 
 /* Status values */
-#define SDLA_MEM_RESERVED	0x0001
-#define SDLA_MEM_MAPPED		0x0002
-#define SDLA_IO_MAPPED		0x0004
-#define SDLA_PCI_ENABLE		0x0008
+#define SDLA_MEM_RESERVED		0x0001
+#define SDLA_MEM_MAPPED			0x0002
+#define SDLA_IO_MAPPED			0x0004
+#define SDLA_PCI_ENABLE			0x0008
 
-#define SDLA_NAME_SIZE		20
+#define SDLA_NAME_SIZE			20
 
 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# define PCI_DMA_FROMDEVICE	1
-# define PCI_DMA_TODEVICE	2
+# define PCI_DMA_FROMDEVICE		1
+# define PCI_DMA_TODEVICE		2
 #endif
 
+#define SDLA_ISA_CARD           0
+#define SDLA_PCI_CARD           1
+#define SDLA_PCI_EXP_CARD       2
+#define SDLA_USB_CARD		3
+
 #define SDLA_MAGIC(hw)		WAN_ASSERT((hw)->magic != SDLADRV_MAGIC)
 #define SDLA_MAGIC_RC(hw,rc)	WAN_ASSERT_RC((hw)->magic != SDLADRV_MAGIC, (rc))
 #define SDLA_MAGIC_VOID(hw)	WAN_ASSERT_VOID((hw)->magic != SDLADRV_MAGIC)
 
+
 /*
 ******************************************************************
 **			T Y P E D E F S				**	
@@ -196,21 +205,33 @@
 typedef dma_addr_t		sdla_dma_addr_t;
 typedef struct pci_dev*		sdla_pci_dev_t;
 #elif defined(__WINDOWS__)
+
 typedef void *		        sdla_mem_handle_t;
-typedef	unsigned long 		sdla_base_addr_t;
-/* Dma addresses are 32-bits wide!!! */
-typedef u32			dma_addr_t;
-typedef dma_addr_t		sdla_dma_addr_t;
+typedef	LONGLONG			sdla_base_addr_t; /* LONGLONG is 64 bit*/
+typedef dma_addr_t			sdla_dma_addr_t;
 typedef struct pci_dev*		sdla_pci_dev_t;
+extern 
+sdla_base_addr_t 
+pci_resource_start(
+	IN struct pci_dev *pci_dev, 
+	IN int resource_index
+	);
+
 #else
 # warning "Undefined types sdla_mem_handle_t/sdla_base_addr_t!"
 #endif
 
-/*
-******************************************************************
+/*****************************************************************
 **			M A C R O S				**
-******************************************************************
-*/
+*****************************************************************/
+
+
+#define IS_HWCARD_ISA(hwcard)		((hwcard)->hw_type == SDLA_ISA_CARD)
+#define IS_HWCARD_PCI(hwcard)		((hwcard)->hw_type == SDLA_PCI_CARD)
+#define IS_HWCARD_PCIE(hwcard)		((hwcard)->hw_type == SDLA_PCI_EXP_CARD)
+#define IS_HWCARD_USB(hwcard)		((hwcard)->hw_type == SDLA_USB_CARD)
+
+
 #if defined(__FreeBSD__)
 # if defined(__i386__)
 #  define virt_to_phys(x) kvtop((caddr_t)x)
@@ -227,10 +248,25 @@
 #elif defined(__LINUX__) 
 #elif defined(__WINDOWS__)
 # define phys_to_virt(x) NULL
+/*
+static sdla_dma_addr_t virt_to_phys(void *virt_buf)
+{
+	sdla_dma_addr_t ph;
+	FUNC_NOT_IMPL();
+	memset(&ph, 0x00, sizeof(sdla_dma_addr_t));
+	return ph;
+}
+*/
 #else
 # warning "Undefined virt_to_phys/phys_to_virt macros!"
 #endif
 
+#if defined(__WINDOWS__)
+#define INIT_PHYSICAL_ADDR(phaddr)	memset(&phaddr, 0x00, sizeof(sdla_dma_addr_t))
+#else
+#define INIT_PHYSICAL_ADDR(phaddr)	phaddr = (sdla_dma_addr_t)NULL;
+#endif
+
 #define IS_SDLA_PCI(hw)		(hw->type == SDLA_S514 || hw->type == SDLA_ADSL)
 #define IS_SDLA_ISA(hw)		(hw->type == SDLA_S508)
 
@@ -276,8 +312,8 @@
 	u32			max_len;
 
 	sdla_dma_addr_t		dma_addr;	/* physical address */
-	u32			dma_len;	/* total dma data len */
-	u32			dma_map_len;	/* actual dma mapped len (address range) */
+	u32			dma_len;			/* total dma data len */
+	u32			dma_map_len;		/* actual dma mapped len (address range) */
 	netskb_t 		*skb;
 	u32			index;
 
@@ -286,7 +322,7 @@
 	u32			reg;
 
 	u8			pkt_error;
-	void*			dma_virt;
+	void*		dma_virt;
 	u32			dma_offset;
 	u32			dma_toggle;
 #if defined(__FreeBSD__)
@@ -301,12 +337,12 @@
 	bus_dma_segment_t	dmaseg;
 	int			rsegs;
 #elif defined(__WINDOWS__)
-	void*			vAddr;
-	PHYSICAL_ADDRESS	physicalAddr;
+	sdla_mem_handle_t	virtualAddr;
+	sdla_dma_addr_t		physicalAddr;
+	PDMA_ADAPTER	DmaAdapterObject;
 #endif
 } wan_dma_descr_t;
 
-
 typedef struct sdla_hw_probe
 {
 	int				internal_used;
@@ -317,131 +353,281 @@
 	WAN_LIST_ENTRY(sdla_hw_probe)	next;
 } sdla_hw_probe_t;
 
+typedef struct sdlahw_isa_ 
+{
+	unsigned int		ioport;
+	unsigned 		io_range;	/* I/O port range */
+	unsigned char 		regs[SDLA_MAXIORANGE];	/* was written to registers */
+	unsigned 		pclk;		/* CPU clock rate, kHz */
 
-/*
- * This structure keeps common parameters per physical card.
- */
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+	bus_space_tag_t		iot;		/* adapter I/O port tag */
+	bus_space_handle_t	ioh;		/* adapter I/O port handle */
+	bus_space_tag_t		memt;
+	bus_dma_tag_t		dmat;
+#endif
+
+} sdlahw_isa_t;
+
+typedef struct sdlahw_pci_ 
+{
+	unsigned int		slot_no;
+	unsigned int		bus_no;
+	sdla_pci_dev_t		pci_dev;	/* PCI config header info */
+	sdla_pci_dev_t		pci_bridge_dev;	/* PCI Bridge config header info */
+	unsigned int		pci_bridge_slot;/* PCI Bridge slot number */
+	unsigned int		pci_bridge_bus;	/* PCI Bridge bus number */
+} sdlahw_pci_t;
+
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+
+#define SDLA_USB_OPMODE_TRANNING	0x00
+#define SDLA_USB_OPMODE_VOICE		0x01
+#define SDLA_USB_OPMODE_API		0x02
+
+struct wan_urb {
+	void		*pvt;
+	int		id;
+	int		next_off;
+	unsigned int	ready;
+	struct urb	urb;
+};
+
+/* move these define in source file */
+#define WP_USB_CHUNKSIZE	8
+#define WP_USB_FRAMESCALE	1
+#define WP_USB_RXTX_CHUNKSIZE	(WP_USB_CHUNKSIZE*WP_USB_FRAMESCALE)	//16
+#define WP_USB_MAX_CHUNKSIZE	(WP_USB_CHUNKSIZE*WP_USB_FRAMESCALE)	//16
+
+#define MAX_READ_URB_COUNT	1
+#define MAX_WRITE_URB_COUNT	2
+#define MAX_USB_RX_LEN		(4*WP_USB_RXTX_CHUNKSIZE)
+#define MAX_USB_TX_LEN		(4*WP_USB_RXTX_CHUNKSIZE)
+#define MAX_READ_BUF_LEN	(MAX_USB_RX_LEN*100)
+#define MAX_WRITE_BUF_LEN	(MAX_USB_TX_LEN*100)
+#define MAX_USB_CTRL_CMD_LEN	(WP_USB_TIMESCALE*8)	//16			/* bytes */
+
+#define WP_USB_BUSID(hwcard)	((hwcard)->u_usb.usb_dev) ? (hwcard)->u_usb.usb_dev->dev.bus_id : "Unknown"
+typedef struct {
+
+	int		core_notready_cnt;
+
+	int		cmd_overrun;
+	int		cmd_timeout;
+	int		cmd_invalid;
+
+	int		rx_sync_err_cnt;
+	int		rx_start_fr_err_cnt;
+	int		rx_start_err_cnt;
+	int		rx_cmd_reset_cnt;
+	int		rx_cmd_drop_cnt;
+	int		rx_cmd_unknown;
+	int		rx_overrun_cnt;
+	int		rx_underrun_cnt;
+	int		tx_overrun_cnt;
+	int		tx_notready_cnt;
+
+	unsigned char	fifo_status;
+	unsigned char	uart_status;
+	unsigned char	hostif_status;
+
+} sdla_usb_comm_err_stats_t;
+
+
+typedef struct sdlahw_usb_
+{
+	int		opmode;		/* Voice or API Data protocol */
+
+# if defined(__LINUX__)
+	struct usb_device	*usb_dev;
+	struct usb_interface	*usb_intf;
+# endif
+
+////////////////////////////////
+        int 		urbcount_read;
+	int		urb_read_ind;
+	struct wan_urb	dataread[MAX_READ_URB_COUNT];
+	
+        int 		urbcount_write;
+	int		urb_write_ind;
+        struct wan_urb	datawrite[MAX_WRITE_URB_COUNT];
+
+	char		readchunk[2][WP_USB_MAX_CHUNKSIZE * 2+1];
+	char		writechunk[2][WP_USB_MAX_CHUNKSIZE * 2+1];
+	u8		regs[2][110];		/* register shadow */
+
+	wan_spinlock_t	cmd_lock;
+	wan_spinlock_t	lock;
+
+	int		rxtx_len;		/* number of data bytes in record */
+	int		rxtx_count;		/* number records in single transcation */
+	int		rxtx_total_len;		/* total number of data bytes in record */
+ 	
+	int		rxtx_buf_len;		/* total number of bytes in transcation */
+	int		read_buf_len;		/* size of read cycle buffer */
+	int		write_buf_len;		/* size of write cycle buffer */
+ 		
+	int		rx_sync;
+	int		next_rx_ind;
+	int		next_read_ind;
+	char		readbuf[MAX_READ_BUF_LEN+MAX_USB_RX_LEN+10];	// 10 for safety 
+
+	int		next_tx_ind;
+	int		next_write_ind;
+	char		writebuf[MAX_WRITE_BUF_LEN+MAX_USB_TX_LEN+10];	// 10 for safety 
+
+	char		idlebuf[MAX_USB_TX_LEN+1];
+
+	wan_tasklet_t	bh_task;
+
+	unsigned char	ctrl_idle_pattern;
+
+	unsigned int	status;
+
+	wan_skb_queue_t	tx_cmd_list;
+	wan_skb_queue_t	tx_cmd_free_list;
+	wan_skb_queue_t	rx_cmd_list;
+	wan_skb_queue_t	rx_cmd_free_list;
+
+	void		(*isr_func)(void*);
+	void		*isr_arg;
+
+	// Statistics 
+	sdla_usb_comm_err_stats_t	stats;
+
+///////////////////////////////
+} sdlahw_usb_t;
+#else
+#define WP_USB_BUSID(hwcard)	"usb not supported"
+#endif 
+
+/* This structure keeps common parameters per physical card */
 typedef struct sdlahw_card {
 	int 				internal_used;
 	unsigned int		hw_type;	/* ISA/PCI */
 	unsigned int		type;		/* S50x/S514/ADSL/SDLA_AFT */
 	unsigned char		cfg_type;	/* Config card type WANOPT_XXX */
-	unsigned int		adptr_type;	/* Adapter type (subvendor ID) */
+	unsigned int		adptr_type;	/* Adapter type */
 	unsigned char		adptr_subtype;	/* Adapter Subtype (Normal|Shark) */
 	unsigned char		adptr_name[SDLA_NAME_SIZE];
 	unsigned char		core_id;	/* SubSystem ID [0..7] */
 	unsigned char		core_rev;	/* SubSystem ID [8..15] */
 	unsigned char 		pci_extra_ver;
-	unsigned int		slot_no;
-	unsigned int		bus_no;
-	unsigned int		ioport;
 	unsigned int		recovery_clock_flag; /* 1 - already used, 0 - not used */
-#if defined(__LINUX__)
-	sdla_pci_dev_t		pci_dev;	/* PCI config header info */
-#else
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	bus_space_tag_t		iot;		/* adapter I/O port tag */
-	bus_space_tag_t		memt;
-#endif
-	sdla_pci_dev_t		pci_dev;	/* PCI config header info */
-#endif
-	sdla_pci_dev_t		pci_bridge_dev;	/* PCI Bridge config header info */
-	unsigned int		pci_bridge_slot;/* PCI Bridge slot number */
-	unsigned int		pci_bridge_bus;	/* PCI Bridge bus number */
+
+	union {
+		sdlahw_isa_t	isa;
+		sdlahw_pci_t	pci;
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+		sdlahw_usb_t	usb;
+#endif 
+	} u_hwif;
+#define u_isa	u_hwif.isa
+#define u_pci	u_hwif.pci
+#define u_usb	u_hwif.usb
+
 	wan_spinlock_t		pcard_lock;	/* lock per physical card for FE */
 	wan_spinlock_t		pcard_ec_lock;	/* lock per physical card for EC */
-	wan_smp_flag_t		fe_rw_flag;
+#if 0
+	/* moved to cpu, type */
+	wan_smp_flag_t		fe_rw_flag;	
+#endif
 	unsigned char		adptr_security;	/* Adapter security (AFT cards) */
 	u16			hwec_chan_no;	/* max hwec channels number */
 	int			hwec_ind;	/* hwec index */
-	WAN_LIST_ENTRY(sdlahw_card)	next;
 	unsigned char		cpld_rev;
+
+#if defined(__WINDOWS__)
+	u16		number_of_ports;/* Number of ports/lines on the card. Initialized exactly one time,
+							when add_pci_hw() called for the card for the FIRST time. */
+#endif
+
+	WAN_LIST_ENTRY(sdlahw_card)	next;
 } sdlahw_card_t;
 
+typedef struct {
+	   int			usage;
+       int			total_line_no;
+       u_int32_t	line_map;
+	
+	   wan_smp_flag_t		fe_rw_flag;	
+	   wan_spinlock_t		pcard_lock;	/* lock per physical card for FE */
+} sdlahw_info_t;
 
-/*----------------------------------------------------------------------------
- * Adapter hardware configuration. Pointer to this structure is passed to all
- * APIs.
- */
 struct sdlahw_;
 typedef struct sdlahw_cpu
 {
-	int			internal_used;
-	int			used;
-	u16			status;
-	unsigned 		fwid;		/* firmware ID */
+	unsigned			magic;
+	int					internal_used;
+	int					used;
+
+	u16					status;
+	unsigned 			fwid;		/* firmware ID */
 #if defined(__NetBSD__) || defined(__OpenBSD__)
-	bus_space_handle_t	ioh;		/* adapter I/O port handle */
-	bus_dma_tag_t		dmat;
+	bus_space_handle_t		ioh;		/* adapter I/O port handle */
+	bus_dma_tag_t			dmat;
 #endif
-	int 			irq;		/* interrupt request level */
+	int 				irq;		/* interrupt request level */
 #if (defined(__FreeBSD__) && __FreeBSD_version >= 450000)
 	void*			irqh[SDLA_MAX_HWDEVS];
 #endif
 	unsigned int		cpu_no;		/* PCI CPU Number */
-	char 			auto_pci_cfg;	/* Auto PCI configuration */
 	sdla_mem_handle_t	dpmbase;	/* dual-port memory base */
 	sdla_base_addr_t 	mem_base_addr;
-	unsigned 		dpmsize;	/* dual-port memory size */
-	unsigned 		pclk;		/* CPU clock rate, kHz */
+	unsigned 			dpmsize;	/* dual-port memory size */
 	unsigned long 		memory;		/* memory size */
 	sdla_mem_handle_t	vector;		/* local offset of the DPM window */
-	unsigned 		io_range;	/* I/O port range */
-	unsigned char 		regs[SDLA_MAXIORANGE];	/* was written to registers */
-
-	unsigned 		reserved[5];
-	//unsigned char		hw_info[100];
 
-	/* */
-	unsigned		magic;
 # if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-	void			*sdla_dev;		/* used only for FreeBSD/OpenBSD */
+	void				*sdla_dev;              /* used only for FreeBSD/OpenBSD */
 # endif
-	u16			configured;
+	u16					configured;
 
-	int			max_ports;	/* number of ports */
+	int					max_lines_num;  /* maximum number of ports */
 
-	u_int32_t		port_map;	/* installed modules for A200/A400/ISDN */
-	int			reg_port[SDLA_MAX_HWDEVS];
+	sdlahw_info_t		lines_info[MAX_ADPTRS];
 
-	u_int32_t		reg_port_map;	/* configured port */
+	u_int32_t			reg_line_map;   /* configured port */
+	int					reg_line[SDLA_MAX_HWDEVS];
 	struct sdlahw_dev	*hwdev[SDLA_MAX_HWDEVS];
-		
-	void			*port_ptr_isr_array[SDLA_MAX_HWDEVS];
 
-	sdlahw_card_t		*hwcard;
-	WAN_LIST_ENTRY(sdlahw_cpu)	next;
+	void				*line_ptr_isr_array[SDLA_MAX_HWDEVS];
+
+	sdlahw_card_t                   *hwcard;
+	WAN_LIST_ENTRY(sdlahw_cpu)      next;
 #if defined(__WINDOWS__)
 	PHYSICAL_ADDRESS unmapped_memory_base;/* memory BEFORE it was mapped in to virtual space */
-	ulong_t	unmapped_memory_length;/* actual memory aperture size */
+	ulong_t unmapped_memory_length;/* actual memory aperture size */
 #endif
+
 } sdlahw_cpu_t;
 
 typedef struct sdlahw_port_
 {
-	int			used;
-	char			*devname;
+	int					used;
+	char				*devname;
 	sdla_hw_probe_t		*hwprobe;
 } sdlahw_port_t;
 
 typedef struct sdlahw_dev
 {
-	int			internal_used;
-	int			used;
+	int				internal_used;
+	int				magic;
+	int				used;	
 	char			*devname;
-	unsigned		magic;
-	unsigned int		port_no;	/* Port number per CPU (line) */
-//	sdla_hw_probe_t		*hwprobe;
-	sdlahw_cpu_t*		hwcpu;
-	int			max_port_no;
-	sdlahw_port_t		hwport[SDLA_MAX_HWPORTS];
+	unsigned int	adptr_type;
+	unsigned char	cfg_type;
+	unsigned int	line_no;        /* Port number per CPU (line) */
 
-	WAN_LIST_ENTRY(sdlahw_dev)	next;
-#if defined(__WINDOWS__)
-	void *level1_dev_pdx;
-#endif
-} sdlahw_t;
+	int				max_chans_num;          /* maximum number of channels (timeslots) */
+	u_int32_t		chans_map;              /* channels map per hw device (A200/A400/ISDN) */
+
+	int				max_port_no;
+	sdlahw_port_t	hwport[SDLA_MAX_HWPORTS];
 
+	sdlahw_cpu_t	*hwcpu;
+	WAN_LIST_ENTRY(sdlahw_dev)      next;
+} sdlahw_t;
 
 typedef struct sdlahw_iface
 {
@@ -452,9 +638,10 @@
 	int		(*hw_halt)(void*);
 	int		(*intack)(void*, uint32_t);
 	int		(*read_int_stat)(void*, uint32_t*);
-	int		(*mapmem)(void*, unsigned long);
+	int		(*mapmem)(void*, ulong_ptr_t);
 	int		(*check_mismatch)(void*, unsigned char);
 	int 		(*getcfg)(void*, int, void*);
+	int 		(*get_totalines)(void*,int*);
 	int 		(*setcfg)(void*, int, void*);
 	int		(*isa_read_1)(void* hw, unsigned int offset, u8*);
 	int		(*isa_write_1)(void* hw, unsigned int offset, u8);
@@ -516,15 +703,28 @@
 	void		(*busdma_free)(void *phw, wan_dma_descr_t*);
 	int		(*busdma_load)(void *phw, wan_dma_descr_t*, u32);
 	void		(*busdma_unload)(void *phw, wan_dma_descr_t*);
-	void		(*busdma_map)(void *phw, wan_dma_descr_t*, void *buf, int len, int map_len, int dir);
+	void		(*busdma_map)(void *phw, wan_dma_descr_t*, void *buf, int len, int map_len, int dir, void *skb);
 	void		(*busdma_unmap)(void *phw, wan_dma_descr_t*, int dir);
 	void		(*busdma_sync)(void *phw, wan_dma_descr_t*, int ndescr, int single, int dir);
 	char*		(*hwec_name)(void *phw);
 	int		(*get_hwec_index)(void *phw);
+
+	/* usb function interface (FIXME) */
+	int		(*usb_cpu_read)(void *phw, unsigned char off, unsigned char *data);
+	int		(*usb_cpu_write)(void *phw, unsigned char off, unsigned char data);
+	int		(*usb_write_poll)(void *phw, unsigned char off, unsigned char data);
+	int		(*usb_read_poll)(void *phw, unsigned char off, unsigned char *data);
+	int		(*usb_rxevent_enable)(void *phw, int, int);
+	int		(*usb_rxevent)(void *phw, int, u8*, int);
+	int		(*usb_rxtx_data_init)(void *phw, int, unsigned char**, unsigned char**);
+	int		(*usb_rxdata_enable)(void *phw, int enable);
+	int		(*usb_rxdata)(void *phw, unsigned char*, int);
+	int		(*usb_txdata)(void *phw, unsigned char*, int);
+	int		(*usb_txdata_ready)(void *phw);
+	int		(*usb_err_stats)(void *phw, void*, int);
+	int		(*usb_flush_err_stats)(void *phw);
 	void		(*reset_fe)(void*);
-#if defined(__WINDOWS__)
-	sdlahw_t *hw;
-#endif
+
 } sdlahw_iface_t;
 
 typedef struct sdla_hw_type_cnt
@@ -540,10 +740,25 @@
 	unsigned char aft_isdn_adapters;
 	unsigned char aft_56k_adapters;
 	unsigned char aft_serial_adapters;
-	unsigned char aft_a600_adapters;	
+	unsigned char aft_a600_adapters;
+	unsigned char aft_a700_adapters;
+	
 	unsigned char aft_x_adapters;
+	unsigned char usb_adapters;
 }sdla_hw_type_cnt_t;
 
+typedef struct sdladrv_callback_ {
+	int (*add_device)(char*, void*);
+	int (*delete_device)(char*);
+} sdladrv_callback_t;
+
+#if defined(SDLADRV_HW_IFACE)
+typedef struct sdladrv_hw_probe_iface {
+	int (*add_pci_hw)(struct pci_dev *pci_dev, int slot, int bus, int irq);
+	int (*delete_pci_hw)(struct pci_dev *pci_dev, int slot, int bus, int irq);
+	sdlahw_card_t* (*search_sdlahw_card)(u8 hw_type, int slot, int bus);
+} sdladrv_hw_probe_iface_t;
+#endif
 
 /****** Function Prototypes *************************************************/
 
@@ -554,6 +769,11 @@
 EXTERN void *sdla_get_hw_adptr_cnt(void);
 EXTERN void* sdla_register	(sdlahw_iface_t* hw_iface, wandev_conf_t*,char*);
 EXTERN int sdla_unregister	(void**, char*);
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+EXTERN int sdla_get_hw_usb_adptr_cnt(void);
+#endif
+EXTERN int sdla_get_hwinfo(hardware_info_t *hwinfo, int card_no);
+
 
 #ifdef __SDLADRV__
 
@@ -569,16 +789,16 @@
 	hwcard = hwcpu->hwcard;
 #if defined(__FreeBSD__)
 # if (__FreeBSD_version > 400000)
-	return pci_get_bus(hwcard->pci_dev);
+	return pci_get_bus(hwcard->u_pci.pci_dev);
 # else
-	return hwcard->pci_dev->bus;
+	return hwcard->u_pci.pci_dev->bus;
 # endif
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
-	return hwcard->pci_dev->pa_bus;
+	return hwcard->u_pci.pci_dev->pa_bus;
 #elif defined(__LINUX__)
-	return ((struct pci_bus*)hwcard->pci_dev->bus)->number;
+	return ((struct pci_bus*)hwcard->u_pci.pci_dev->bus)->number;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # warning "sdla_get_pci_bus: Not supported yet!"
 #endif
@@ -597,16 +817,16 @@
 	hwcard = hwcpu->hwcard;
 #if defined(__FreeBSD__)
 # if (__FreeBSD_version > 400000)
-	return pci_get_slot(hwcard->pci_dev);
+	return pci_get_slot(hwcard->u_pci.pci_dev);
 # else
-	return hwcard->pci_dev->slot;
+	return hwcard->u_pci.pci_dev->slot;
 # endif
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
-	return hwcard->pci_dev->pa_device;
+	return hwcard->u_pci.pci_dev->pa_device;
 #elif defined(__LINUX__)
-	return ((hwcard->pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK);
+	return ((hwcard->u_pci.pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # warning "sdla_get_pci_slot: Not supported yet!"
 #endif
@@ -634,14 +854,14 @@
 #elif defined(__LINUX__)
 	*handle = (sdla_mem_handle_t)ioremap(hwcpu->mem_base_addr+reg, size);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
-	/*
-	*handle = (sdla_mem_handle_t)MmMapIoSpace(
-		((PHYSICAL_ADDRESS)(hwcpu->mem_base_addr+reg)), (ULONG)size, MmNonCached);
+	{
+	PHYSICAL_ADDRESS tmpPA;
+	tmpPA.QuadPart = (hwcpu->mem_base_addr+reg);
+	*handle = MmMapIoSpace(tmpPA, (ULONG)size, MmNonCached);
+	}
 	if(*handle == NULL){
 		err = 1;
 	}
-	*/
 #else
 # warning "sdla_bus_space_map: Not supported yet!"
 #endif
@@ -669,8 +889,7 @@
 #elif defined(__LINUX__)
 	iounmap((void*)offset);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
-	/*MmUnmapIoSpace((void*)offset, size);*/
+	MmUnmapIoSpace(offset, size);
 #else
 # warning "sdla_bus_space_unmap: Not supported yet!"
 #endif
@@ -714,7 +933,7 @@
 	*pres = resource; 
 	return 0;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	/* request memory for exclusive use - was needed for NT4, not for XP - PnP takes care of it */
 	return 0;
 #else
 # warning "sdla_request_mem_region: Not supported yet!"
@@ -730,7 +949,7 @@
 #elif defined(__LINUX__)
 	release_mem_region(base_addr, len);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	/* release memory from exclusive use  */
 #else
 # warning "sdla_release_mem_region: Not supported yet!"
 #endif
@@ -739,22 +958,21 @@
 static __inline int 
 sdla_pci_enable_device(sdlahw_t* hw)
 {
-	sdlahw_card_t*	card;
+	sdlahw_card_t	*hwcard;
 	sdlahw_cpu_t	*hwcpu;
 
 	WAN_ASSERT(hw == NULL);
 	WAN_ASSERT(hw->hwcpu == NULL);
 	hwcpu = hw->hwcpu;
 	WAN_ASSERT(hwcpu->hwcard == NULL);
-	card = hwcpu->hwcard;
+	hwcard = hwcpu->hwcard;
 #if defined(__FreeBSD__)
-	return pci_enable_io(card->pci_dev, SYS_RES_MEMORY);
+	return pci_enable_io(hwcard->u_pci.pci_dev, SYS_RES_MEMORY);
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 	return 0;
 #elif defined(__LINUX__)
-	return pci_enable_device(card->pci_dev);
+	return pci_enable_device(hwcard->u_pci.pci_dev);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
 	return 0;
 #else
 # warning "sdla_release_mem_region: Not supported yet!"
@@ -765,23 +983,22 @@
 static __inline int 
 sdla_pci_disable_device(sdlahw_t* hw)
 {
-	sdlahw_card_t*	card;
+	sdlahw_card_t	*hwcard;
 	sdlahw_cpu_t	*hwcpu;
 
 	WAN_ASSERT(hw == NULL);
 	WAN_ASSERT(hw->hwcpu == NULL);
 	hwcpu = hw->hwcpu;
 	WAN_ASSERT(hwcpu->hwcard == NULL);
-	card = hwcpu->hwcard;
+	hwcard = hwcpu->hwcard;
 #if defined(__FreeBSD__)
-	return pci_disable_io(card->pci_dev, SYS_RES_MEMORY);
+	return pci_disable_io(hwcard->u_pci.pci_dev, SYS_RES_MEMORY);
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 	return 0;
 #elif defined(__LINUX__)
-	pci_disable_device(card->pci_dev);
+	pci_disable_device(hwcard->u_pci.pci_dev);
 	return 0;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
 	return 0;
 #else
 # warning "sdla_release_mem_region: Not supported yet!"
@@ -789,27 +1006,24 @@
 #endif
 }
 
-
-
 static __inline void 
 sdla_pci_set_master(sdlahw_t* hw)
 {
-	sdlahw_card_t*	card;
+	sdlahw_card_t	*hwcard;
 	sdlahw_cpu_t	*hwcpu;
 
 	WAN_ASSERT1(hw == NULL);
 	WAN_ASSERT1(hw->hwcpu == NULL);
 	hwcpu = hw->hwcpu;
 	WAN_ASSERT1(hwcpu->hwcard == NULL);
-	card = hwcpu->hwcard;
+	hwcard = hwcpu->hwcard;
 #if defined(__FreeBSD__)
-	pci_enable_busmaster(card->pci_dev);
+	pci_enable_busmaster(hwcard->u_pci.pci_dev);
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 	return;
 #elif defined(__LINUX__)
-	pci_set_master(card->pci_dev);
+	pci_set_master(hwcard->u_pci.pci_dev);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
 #else
 # warning "sdla_pci_set_master: Not supported yet!"
 #endif
@@ -819,31 +1033,45 @@
 static __inline void
 sdla_get_pci_base_resource_addr(sdlahw_t* hw, int pci_offset, sdla_base_addr_t *base_addr)
 {
-	sdlahw_card_t*	card;
+	sdlahw_card_t	*hwcard;
 	sdlahw_cpu_t	*hwcpu;
 
 	WAN_ASSERT1(hw == NULL);
 	WAN_ASSERT1(hw->hwcpu == NULL);
 	hwcpu = hw->hwcpu;
 	WAN_ASSERT1(hwcpu->hwcard == NULL);
-	card = hwcpu->hwcard;
+	hwcard = hwcpu->hwcard;
 
 #if defined(__FreeBSD__)
 # if (__FreeBSD_version > 400000)
-	*base_addr = (sdla_base_addr_t)pci_read_config(card->pci_dev, pci_offset, 4);
+	*base_addr = (sdla_base_addr_t)pci_read_config(hwcard->u_pci.pci_dev, pci_offset, 4);
 # else
-	*base_addr = (sdla_base_addr_t)ci_cfgread(card->pci_dev, pci_offset, 4);
+	*base_addr = (sdla_base_addr_t)ci_cfgread(hwcard->u_pci.pci_dev, pci_offset, 4);
 # endif
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
-	*base_addr = (sdla_base_addr_t)pci_conf_read(card->pci_dev->pa_pc, card->pci_dev->pa_tag, pci_offset);
+	*base_addr = (sdla_base_addr_t)pci_conf_read(hwcard->u_pci.pci_dev->pa_pc, hwcard->u_pci.pci_dev->pa_tag, pci_offset);
 #elif defined(__LINUX__)
 	if (pci_offset == PCI_IO_BASE_DWORD){
-		*base_addr = (sdla_base_addr_t)pci_resource_start(card->pci_dev,0);
+		*base_addr = (sdla_base_addr_t)pci_resource_start(hwcard->u_pci.pci_dev,0);
 	}else{
-		*base_addr = (sdla_base_addr_t)pci_resource_start(card->pci_dev,1);
+		*base_addr = (sdla_base_addr_t)pci_resource_start(hwcard->u_pci.pci_dev,1);
 	}
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	switch(pci_offset)
+	{
+	case PCI_IO_BASE_DWORD:
+		/* first aperture */
+		*base_addr = (sdla_base_addr_t)pci_resource_start(hwcard->u_pci.pci_dev,0);
+		break;
+	case PCI_MEM_BASE0_DWORD:
+		/* second aperture */
+		*base_addr = (sdla_base_addr_t)pci_resource_start(hwcard->u_pci.pci_dev,1);
+		break;
+	default:
+		DEBUG_EVENT("%s(): line: %d: Error: invalid 'pci_offset' (memory aperture) requested: 0x%X\n",
+			__FUNCTION__, __LINE__, pci_offset);
+		break;
+	}
 #else
 # warning "sdla_get_pci_base_resource_addr: Not supported yet!"
 #endif
@@ -854,7 +1082,7 @@
 
 static __inline int __sdla_bus_read_4(void* phw, unsigned int offset, u32* value)
 {
-	sdlahw_t*	hw = (sdlahw_t*)phw;
+	sdlahw_t	*hw = (sdlahw_t*)phw;
 	sdlahw_cpu_t	*hwcpu;
 	unsigned int	retry=3;
 
@@ -881,7 +1109,7 @@
 	*value = 0;
 # warning "__sdla_bus_read_4: Not supported yet!"
 #endif
-
+			  
 		if (offset == 0x40 && *value == (u32)-1) {
 			if (WAN_NET_RATELIMIT()){
 			DEBUG_EVENT("%s:%d: wanpipe PCI Error: Illegal Register read: 0x%04X = 0x%08X\n",
@@ -899,7 +1127,7 @@
 
 static __inline int __sdla_bus_write_4(void* phw, unsigned int offset, u32 value) 
 {
-	sdlahw_t*	hw = (sdlahw_t*)phw;
+	sdlahw_t	*hw = (sdlahw_t*)phw;
 	sdlahw_cpu_t	*hwcpu;
 
 	WAN_ASSERT(hw == NULL);
@@ -907,6 +1135,7 @@
 	hwcpu = hw->hwcpu;
 	WAN_ASSERT(hwcpu->hwcard == NULL);	
 	SDLA_MAGIC(hwcpu);
+
 	if (!(hwcpu->status & SDLA_MEM_MAPPED)) return 0;
 
 #if defined(__FreeBSD__)
@@ -923,24 +1152,6 @@
 	return 0;
 }
 
-
-static __inline u32 SDLA_REG_OFF(sdlahw_card_t	*hwcard, u32 reg)
-{
-	if (hwcard == NULL) {
-		DEBUG_EVENT("sdladrv: Critical error: hw or hw->cpu is NULL\n");
-		return reg;
-	}
-	
-	if (hwcard->adptr_type == AFT_ADPTR_A600) {
-		if (reg < 0x100) {
-			return (reg+0x1000);
-		} else {
-			return (reg+0x2000);
-		}
-	}
-	return reg;
-}
-
 static __inline int __sdla_is_same_hwcard(void* phw1, void *phw2)
 {
 	sdlahw_cpu_t	*hwcpu1, *hwcpu2;
@@ -965,7 +1176,10 @@
 	WAN_ASSERT_RC(hw == NULL, 0);
 	WAN_ASSERT_RC(hw->hwcpu == NULL, 0);
 	hwcpu = hw->hwcpu;
- 	return &hwcpu->port_ptr_isr_array[0];
+
+	// return &hwcpu->port_ptr_isr_array[0];
+ 	//return &hwcpu->used_type[hw->cfg_type].port_ptr_isr_array[0];
+	return &hwcpu->line_ptr_isr_array[0];
 }
 
 static __inline void __sdla_push_ptr_isr_array(void *phw, void *card, int line)
@@ -979,7 +1193,10 @@
 	if (line >= SDLA_MAX_HWDEVS) {
 		return;
 	}
- 	hwcpu->port_ptr_isr_array[line]=card;
+	// hwcpu->port_ptr_isr_array[line]=card;
+ 	//hwcpu->used_type[hw->cfg_type].port_ptr_isr_array[line]=card;
+	//hwcpu->used_type[0].port_ptr_isr_array [line]=card;
+	hwcpu->line_ptr_isr_array[hw->line_no]=card;
 } 
 
 static __inline void __sdla_pull_ptr_isr_array(void *phw, void *card, int line)
@@ -992,11 +1209,33 @@
 	hwcpu = hw->hwcpu;
 	if (line >= SDLA_MAX_HWDEVS) {
         	return;
-	}	
-	hwcpu->port_ptr_isr_array[line]=NULL;
+	}
+	
+	//hwcpu->port_ptr_isr_array[line]=NULL;
+	//hwcpu->used_type[hw->cfg_type].port_ptr_isr_array[line]=NULL;
+	//hwcpu->used_type[0].port_ptr_isr_array[line]=NULL;
+	hwcpu->line_ptr_isr_array[hw->line_no]=NULL;
 	return;
 }  
 
+static __inline u32 SDLA_REG_OFF(sdlahw_card_t	*hwcard, u32 reg)
+{
+	if (hwcard == NULL) {
+		DEBUG_EVENT("sdladrv: Critical error: hw or hw->cpu is NULL\n");
+		return reg;
+	}
+	
+	if (hwcard->adptr_type == AFT_ADPTR_A600) {
+		if (reg < 0x100) {
+			return (reg+0x1000);
+		} else {
+			return (reg+0x2000);
+		}
+	}
+	
+	return reg;
+}
+
 
 #undef EXTERN 
 #endif	/* _SDLADRV_H */
Only in include/: sdladrv.h.orig
diff -dur include/sdla_fr.h /usr/include/wanpipe/sdla_fr.h
--- include/sdla_fr.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_fr.h	2009-07-14 13:02:00.000000000 -0400
@@ -23,7 +23,7 @@
 #ifndef	_SDLA_FR_H
 #define	_SDLA_FR_H
 
-#include <linux/wanpipe_fr_iface.h>
+#include "wanpipe_fr_iface.h"
 
 /*----------------------------------------------------------------------------
  * Notes:
@@ -543,28 +543,7 @@
         unsigned int UDP_DRVSTATS_mgmt_passed_to_stack;
         unsigned int UDP_DRVSTATS_mgmt_no_socket;
 } drvstats_gen_t;
-
-typedef struct {
-        unsigned char   attr      	;
-        unsigned short  time_stamp      ;
-        unsigned char   reserved[13]    ;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t    api_rx_hdr      ;
-        void *          data            ;
-} api_rx_element_t;
-
-typedef struct {
-        unsigned char   attr            ;
-        unsigned char   reserved[15]    ;
-} api_tx_hdr_t;
-
-typedef struct {
-        api_tx_hdr_t    api_tx_hdr      ;
-        void *          data            ;
-} api_tx_element_t;
-
+	
 
 #pragma pack()
 
diff -dur include/sdla_front_end.h /usr/include/wanpipe/sdla_front_end.h
--- include/sdla_front_end.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_front_end.h	2009-07-14 13:02:00.000000000 -0400
@@ -9,6 +9,13 @@
 #define _SDLA_FRONT_END_H_
 
 
+# include "sdla_56k.h"
+# include "sdla_te1.h"
+# include "sdla_te3.h"
+# include "sdla_remora.h"
+# include "sdla_bri.h"
+# include "sdla_serial.h"
+
 /*
 *************************************************************************
 *			  DEFINES AND MACROS				*	
@@ -273,11 +280,11 @@
 
 } sdla_fe_lbmode_t;
 
-
 /* Front-End status */
-#define FE_STATUS_DECODE(fe_status)					\
-		(fe_status == FE_DISCONNECTED)  ? "disconnected" :\
-		(fe_status == FE_CONNECTED)     ? "connected" :	\
+#define FE_STATUS_DECODE(fe_status)							\
+		(fe_status == FE_UNITIALIZED)	? "unitialized"	:	\
+		(fe_status == FE_DISCONNECTED)  ? "disconnected":	\
+		(fe_status == FE_CONNECTED)     ? "connected"	:	\
 						      "unknown"
 
 #define WAN_FE_STATUS_DECODE(fe)	FE_STATUS_DECODE((fe)->fe_status)
@@ -308,7 +315,8 @@
 #define WAN_FE_LINENO(fe)	FE_LINENO(&((fe)->fe_cfg))
 #define WAN_FE_TXTRISTATE(fe)	FE_TXTRISTATE(&((fe)->fe_cfg))
 #define WAN_FE_TDMV_LAW(fe)	FE_TDMV_LAW(&((fe)->fe_cfg))
-#define WAN_FE_NETWORK_SYNC(fe)	FE_NETWORK_SYNC(&((fe)->fe_cfg))
+
+#define WAN_FE_NETWORK_SYNC(fe)		FE_NETWORK_SYNC(&((fe)->fe_cfg))
 
 #define FE_MEDIA_DECODE(fe)	MEDIA_DECODE(&((fe)->fe_cfg))
 #define FE_LCODE_DECODE(fe)	LCODE_DECODE(&((fe)->fe_cfg))
@@ -493,13 +501,9 @@
 	int 		(*write_framer)(void*,unsigned short,unsigned short);
 	unsigned int 	(*read_framer)(void*,unsigned short);
 	void		(*reset_fe)(void*);
-
 	WRITE_FRONT_END_REG_T	*write_fe_reg;
 	READ_FRONT_END_REG_T	*read_fe_reg;
 	READ_FRONT_END_REG_T	*__read_fe_reg;
-#if defined(__WINDOWS__)
-	int remora_modules_counter;/* set in wp_remora_config() */
-#endif
 } sdla_fe_t;
 
 /*
@@ -520,11 +524,7 @@
 } sdla_fe_iface_t;
 #endif
 
-#if defined(__LINUX__)
-# include <linux/wanpipe_events.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_events.h> /* for wan_event_ctrl_t */
-#endif
+#include "wanpipe_events.h"
 
 /* 
 ** Sangoma Front-End interface structure (new version)
@@ -568,7 +568,7 @@
 	/* Get front end media type string */
 	char*		(*get_fe_media_string)(void);
 	/* Set Line-loopback modes */
-	int		(*set_fe_lbmode)(sdla_fe_t*, unsigned char, unsigned char);
+	int		(*set_fe_lbmode)(sdla_fe_t*, u_int8_t, u_int8_t, u_int32_t);
 	/* Update Alarm Status for proc file system */
 	int		(*update_alarm_info)(sdla_fe_t*, struct seq_file*, int*);
 	/* Update PMON Status for proc file system */
@@ -599,7 +599,7 @@
 	/* Event Control */
 	int		(*event_ctrl)(sdla_fe_t*, wan_event_ctrl_t*);
 	/* Front-End watchdog */
-	int		(*watchdog)(sdla_fe_t*);
+	int		(*watchdog)(void * card);
 	/* Transmit ISDN BRI D-chan data */
 	int		(*isdn_bri_dchan_tx)(sdla_fe_t*, void*, unsigned int);
 	/* Receive ISDN BRI D-chan data */
diff -dur include/sdla_mp_fr.h /usr/include/wanpipe/sdla_mp_fr.h
--- include/sdla_mp_fr.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_mp_fr.h	2009-07-14 13:02:00.000000000 -0400
@@ -5,13 +5,6 @@
 #include <linux/sdla_chdlc.h>
 #include <linux/sdla_fr.h>
 
-
-#undef  wan_udphdr_data
-#define wan_udphdr_data	wan_udphdr_u.data
-
-#undef  wan_udp_data
-#define wan_udp_data  wan_udp_hdr.wan_udphdr_data
-
 #undef MAX_FR_CHANNELS
 #undef HIGHEST_VALID_DLCI
 
diff -dur include/sdlapci.h /usr/include/wanpipe/sdlapci.h
--- include/sdlapci.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdlapci.h	2009-07-14 13:02:00.000000000 -0400
@@ -44,6 +44,7 @@
 #define SANGOMA_PCI_4_SHARK_DEVICE	0x0100	/* A104D */
 #define SANGOMA_PCI_A200_SHARK_DEVICE	0x0040	/* A200 (D) */
 #define SANGOMA_PCI_A056_SHARK_DEVICE	0x0020	/* A056 */
+#define SANGOMA_PCI_B600_SHARK_DEVICE	0x0025	/* B600 */
 #endif
 
 /* Definition for identifying and finding PLX PCI bridge adapters */
@@ -63,6 +64,14 @@
 #define A300_UTE3_SUBSYS_VENDOR			0xA020	/* A300 with T3/E3 (unchannelized) */
 #define A305_CT3_SUBSYS_VENDOR			0xA030	/* A305 with T3 (channelized) */
 
+#define S5141_SERIAL_SUBSYS_VENDOR		0x0011	/* S5141, single CPU, serial */
+#define S5142_SERIAL_SUBSYS_VENDOR		0x0012	/* S5142, dual CPU, serial */
+#define S5143_SERIAL_SUBSYS_VENDOR		0x0013	/* S5143, single CPU, FT1 */
+#define S5144_SERIAL_SUBSYS_VENDOR		0x0014	/* S5144, single CPU, T1/E1 */
+#define S5145_SERIAL_SUBSYS_VENDOR		0x0015	/* S5145, single CPU, 56K */
+#define S5147_SERIAL_SUBSYS_VENDOR		0x0017  /* S5147, dual CPU, T1/E1 */
+#define S5148_SERIAL_SUBSYS_VENDOR		0x0018	/* S5148, single CPU, T1/E1 */
+
 #define AFT_1TE1_SHARK_SUBSYS_VENDOR		0xA111	/* A101-SHARK T1/E1 1 lines */
 #define AFT_2TE1_SHARK_SUBSYS_VENDOR		0xA112	/* A102-SHARK T1/E1 2 lines */
 #define AFT_4TE1_SHARK_SUBSYS_VENDOR		0xA113	/* A104-SHARK T1/E1 4 lines */
@@ -73,6 +82,7 @@
 #define A400_REMORA_SHARK_SUBSYS_VENDOR		0xA400	/* AFT-REMORA SHARK analog board */
 
 #define AFT_ISDN_BRI_SHARK_SUBSYS_VENDOR	0xA500	/* AFT-ISDN BRI SHARK board */
+#define A700_SHARK_SUBSYS_VENDOR		0xA700	/* AFT-700 SHARK FLEX-BRI board */
 #define AFT_56K_SHARK_SUBSYS_VENDOR		0xA056	/* AFT-56K SHARK board */
 
 #define AFT_A600_SUBSYS_VENDOR			0xA600	/* AFT-600 Series board */
@@ -119,7 +129,7 @@
 #define AFT8_PCI_MEM_SIZE	0x1FFFF
 
 #define XILINX_PCI_CMD_REG	0x04
-#define XILINX_PCI_LATENCY_REG  0x0C
+#define XILINX_PCI_LATENCY_REG  0x0D
 
 /* Local PCI register offsets */ 
 #define PCI_VENDOR_ID_WORD	0x00		/* vendor ID */
@@ -179,5 +189,4 @@
 #define PCI_DEVICE_ID_GSI_ADSL      PCI_DEVICE_ID_GSI_PULSAR
 #define PCI_DEVICE_ID_GSI_ADSL_V2   0xD001
 
-
 #endif	/* _SDLAPCI_H */
diff -dur include/sdla_ppp.h /usr/include/wanpipe/sdla_ppp.h
--- include/sdla_ppp.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_ppp.h	2009-07-14 13:02:00.000000000 -0400
@@ -27,7 +27,7 @@
  *	GNU C		Linux		
  */
 
-#include <linux/wanpipe_sppp_iface.h>
+#include "wanpipe_sppp_iface.h"
 
 #pragma pack(1)
 
@@ -335,33 +335,37 @@
 
 
 #define FT1_MONITOR_STATUS_CTRL                         0x80
-#define SET_FT1_MODE                                    0x81
+//#define SET_FT1_MODE                                    0x81
 
 
 
 /* Special UDP drivers management commands */
-#define PPIPE_ENABLE_TRACING                            0x20
-#define PPIPE_DISABLE_TRACING                           0x21
-#define PPIPE_GET_TRACE_INFO                            0x22
-#define PPIPE_GET_IBA_DATA                              0x23
-#define PPIPE_KILL_BOARD     				0x24
-#define PPIPE_FT1_READ_STATUS                           0x25
-#define PPIPE_DRIVER_STAT_IFSEND                        0x26
-#define PPIPE_DRIVER_STAT_INTR                          0x27
-#define PPIPE_DRIVER_STAT_GEN                           0x28
-#define PPIPE_FLUSH_DRIVER_STATS                        0x29
-#define PPIPE_ROUTER_UP_TIME                            0x30
-#define PPIPE_TE1_56K_STAT 	    			0x40	/* TE1_56K */
+#define PPIPE_ENABLE_TRACING                            WANPIPEMON_ENABLE_TRACING
+#define PPIPE_DISABLE_TRACING                           WANPIPEMON_DISABLE_TRACING
+#define PPIPE_GET_TRACE_INFO                            WANPIPEMON_GET_TRACE_INFO
+#define PPIPE_GET_IBA_DATA                              WANPIPEMON_GET_IBA_DATA
+
+#define PPIPE_FT1_READ_STATUS                           WANPIPEMON_FT1_READ_STATUS
+#define PPIPE_DRIVER_STAT_IFSEND                        WANPIPEMON_DRIVER_STAT_IFSEND
+#define PPIPE_DRIVER_STAT_INTR                          WANPIPEMON_DRIVER_STAT_INTR
+#define PPIPE_DRIVER_STAT_GEN                           WANPIPEMON_DRIVER_STAT_GEN
+#define PPIPE_FLUSH_DRIVER_STATS                        WANPIPEMON_FLUSH_DRIVER_STATS
+#define PPIPE_ROUTER_UP_TIME                            WANPIPEMON_ROUTER_UP_TIME
+#define PPIPE_TE1_56K_STAT 	    				0x40	/* TE1_56K */
 #define PPIPE_GET_MEDIA_TYPE	 	    		0x41	/* TE1_56K */
-#define PPIPE_FLUSH_TE1_PMON 	   			0x42	/* TE1     */
-#define PPIPE_READ_REGISTER 	   			0x43	/* TE1_56K */
-#define PPIPE_TE1_CFG 		   			0x44	/* TE1     */
+#define PPIPE_FLUSH_TE1_PMON 	   				0x42	/* TE1     */
+#define PPIPE_READ_REGISTER 	   				0x43	/* TE1_56K */
+#define PPIPE_TE1_CFG 		   					0x44	/* TE1     */
 
-#define DISABLE_TRACING 				0x00
+//#define DISABLE_TRACING 					0x00
 #define TRACE_SIGNALLING_FRAMES				0x01
-#define TRACE_DATA_FRAMES				0x02
+#define TRACE_DATA_FRAMES					0x02
 
+#ifdef UDPMGMT_SIGNATURE
+#undef UDPMGMT_SIGNATURE
 #define UDPMGMT_SIGNATURE    "PTPIPEAB"
+#endif
+
 #define UDPDRV_SIGNATURE     "DRVSTATS"
 #define UDPMGMT_UDP_PROTOCOL 0x11
 
Only in /usr/include/wanpipe/: sdla_remora_analog.h
diff -dur include/sdla_remora.h /usr/include/wanpipe/sdla_remora.h
--- include/sdla_remora.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_remora.h	2009-07-14 13:02:00.000000000 -0400
@@ -22,14 +22,12 @@
 # define EXTERN extern
 #endif
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <sdla_remora_proslic.h>
-#elif defined(__WINDOWS__)
-# include <sdla_remora_proslic.h>
-# include <wanpipe_events.h>
-#else
-# include <linux/sdla_remora_proslic.h>
-#endif
+# include "aft_core_options.h"
+# include "sdla_a600_remora.h"
+# include "sdla_remora_proslic.h"
+# include "wanpipe_events.h"
+
+
 
 /*******************************************************************************
 **			  DEFINES and MACROS
@@ -37,10 +35,20 @@
 
 #define IS_FXOFXS_CARD(card)		IS_FXOFXS_FEMEDIA(&(card)->fe)
 
+#define IS_A200(fe) (((sdla_t*)(fe->card))->adptr_type == A200_ADPTR_ANALOG ||\
+		     ((sdla_t*)(fe->card))->adptr_type == A400_ADPTR_ANALOG)
+
+#define IS_A200_CARD(card) (card->adptr_type == A200_ADPTR_ANALOG || \
+				card->adptr_type == A400_ADPTR_ANALOG)
+
+#define IS_A700(fe) (((sdla_t*)(fe->card))->adptr_type == AFT_ADPTR_FLEXBRI)
+#define IS_A700_CARD(card) (card->adptr_type == AFT_ADPTR_FLEXBRI)
+
 #define WAN_RM_START_CHANNEL		1
 
 #define MAX_REMORA_MODULES		24
 #define MAX_FXOFXS_CHANNELS		MAX_REMORA_MODULES
+#define NUM_A700_ANALOG_PORTS	2
 
 #define MOD_TYPE_NONE			0
 #define MOD_TYPE_FXS			1
@@ -56,6 +64,11 @@
 #define MOD_CHAIN_DISABLED	0
 #define MOD_CHAIN_ENABLED	1
 
+#define A700_ANALOG_SPI_INTERFACE_REG 0x5C
+#define A700_ANALOG_SPI_CS_FXS_CHIP_0 0XFD
+#define A700_ANALOG_SPI_CS_FXS_CHIP_1 0XFE
+#define A700_ANALOG_SPI_MOD_START_BIT (1<<31)
+
 #define SPI_INTERFACE_REG	0x54
 
 #define MOD_SPI_ADDR_FXS_READ	0x80
@@ -90,17 +103,10 @@
 #define WAN_RM_OPERMODE_LEN	20
 
 /* Front-End UDP command */
-#if defined(__WINDOWS__)
-#define WAN_FE_TONES		13
-#define WAN_FE_RING		(WAN_FE_TONES + 1)
-#define WAN_FE_REGDUMP		(WAN_FE_TONES + 2)
-#define WAN_FE_STATS		(WAN_FE_TONES + 3)
-#else
 #define WAN_FE_TONES		(WAN_FE_UDP_CMD_START + 0)
-#define WAN_FE_RING		(WAN_FE_UDP_CMD_START + 1)
+#define WAN_FE_RING			(WAN_FE_UDP_CMD_START + 1)
 #define WAN_FE_REGDUMP		(WAN_FE_UDP_CMD_START + 2)
 #define WAN_FE_STATS		(WAN_FE_UDP_CMD_START + 3)
-#endif
 
 #define WAN_RM_SET_ECHOTUNE	_IOW (ZT_CODE, 63, struct wan_rm_echo_coefs)
 
@@ -157,7 +163,8 @@
 	int		fxo_txgain;
 
 	int		fxs_ringampl;
-	unsigned int	rm_mode; 	/*Analog Operation mode: default or tapping */
+	u_int8_t	rm_mode; 	/*Analog Operation mode: default or tapping */
+	u_int8_t	fake_polarity;
 } sdla_remora_cfg_t;
 
 typedef struct {
@@ -323,10 +330,10 @@
 
 	int	ring_detect;	
 	
-	int	offhook;			/* Xswitch */
+	int	offhook;		/* Xswitch */
 	int	battery;		/* Xswitch */
 	int	battdebounce;		/* Xswitch */
-	int	ringdebounce;		/* Xswitch */
+	int ringdebounce;
 	int	wasringing;
 	int	nobatttimer;
 	int	lastpol;
@@ -338,6 +345,16 @@
 	int	going_offhook;	/* current ohdebounce is for off-hk or on-hk */
 	
 	unsigned char	imask;		/* interrupt mask */
+
+	/*Additional for Zaptel mode*/
+#if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE)
+	int				echotune;	/* echo tune */
+	struct wan_rm_echo_coefs	echoregs;	/* echo tune */
+	int   				readcid;
+        unsigned int 			cidtimer;
+
+#endif
+
 } wp_remora_fxo_t;
 
 typedef struct {
@@ -357,12 +374,20 @@
 	int		debounce;
 	int		debouncehook;
 
+	/*Additional for Zaptel mode */
+	int	lasttxhook_update;
+	/*Flash/hook timer */
+
+	int		itimer;
+	int		rxflashtime;
+
 } wp_remora_fxs_t;
 
 typedef struct {
 	int		type;
 	int		chain;
 	unsigned long	events;
+	unsigned long 	lastcmd;
 
 #if 0
 #if defined(__WINDOWS__)
@@ -414,7 +439,18 @@
 	int		reg_dbg_busy;	
 	int		reg_dbg_ready;	
 	unsigned char	reg_dbg_value;
-	u32		access_counter;
+	/* use REG_SHADOW in all modes */
+	unsigned char	reg0shadow[MAX_REMORA_MODULES];	/* read> fxs: 68 fxo: 5 */
+	unsigned char	reg1shadow[MAX_REMORA_MODULES];	/* read> fxs: 64 fxo: 29 */
+	unsigned char	reg2shadow[MAX_REMORA_MODULES];	/* read> fxs: 64 fxo: 29 */
+	unsigned char	reg3shadow[MAX_REMORA_MODULES]; /* read > fxs : 19 for Ring/Trip Evnet , FXO no use yet */
+	unsigned char	reg4shadow[MAX_REMORA_MODULES]; /* read > fxs : 20 for DTMF Evnet , FXO no use yet */
+
+	unsigned char	reg0shadow_write[MAX_REMORA_MODULES];	/* write> fxs: 68 fxo: 5 */
+	int		reg0shadow_update[MAX_REMORA_MODULES];
+	int		battdebounce;		/* global for FXO */
+	int		battthresh;		/* global for FXO */
+	int		wp_rm_chunk_size;	/* TDM API set as MTU for Zaptel set as ZT_CHUNK_SIZE */
 
 } sdla_remora_param_t;
 
@@ -425,6 +461,8 @@
 **			  FUNCTION PROTOTYPES
 *******************************************************************************/
 extern int	wp_remora_iface_init(void*, void*);
+extern int	wp_a700_remora_iface_init(void*, void*);
 
 #undef EXTERN
 #endif	/* __SDLA_REMORA_H */
+
diff -dur include/sdla_remora_proslic.h /usr/include/wanpipe/sdla_remora_proslic.h
--- include/sdla_remora_proslic.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_remora_proslic.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,5 +1,8 @@
 /* ProSlic Header File - sdla_remora_proslic.h */
 
+#ifndef __SDLA_REMORA_PROSLIC_H__
+#define __SDLA_REMORA_PROSLIC_H__
+
 typedef struct {
 	unsigned char address;
 	unsigned char altaddr;
@@ -188,3 +191,6 @@
 #define	CM_BIAS_RINGING	40
 #define	DCDC_MIN_V	41
 #define	DCDC_XTRA	42
+
+#endif
+
Only in /usr/include/wanpipe/: sdla_remora_tdmv.h
diff -dur include/sdlasfm.h /usr/include/wanpipe/sdlasfm.h
--- include/sdlasfm.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdlasfm.h	2009-07-14 13:02:00.000000000 -0400
@@ -31,11 +31,6 @@
 #define	SFM_MAX_SDLA	16	/* max number of compatible adapters */
 
 /* Adapter types */
-#if defined(__WINDOWS__)
-#define INVALID_DEVICE_TYPE		0x0000
-#define MAX_NUM_OF_CPUS	2
-#endif
-
 #define SDLA_S502A	5020
 #define SDLA_S502E	5021
 #define SDLA_S503	5030
@@ -45,6 +40,7 @@
 #define SDLA_S514	5140
 #define SDLA_ADSL	6000
 #define SDLA_AFT	7000
+#define SDLA_USB	7001
 
 /* S514 PCI adapter CPU numbers */
 #define S514_CPU_A	'A'
@@ -122,53 +118,38 @@
 } sfm_t;
 
 /* settings for the 'adapter_type' */
-#define S5141_ADPTR_1_CPU_SERIAL	0x0011	/* S5141, single CPU, serial */
-#define S5142_ADPTR_2_CPU_SERIAL	0x0012	/* S5142, dual CPU, serial */
-#define S5143_ADPTR_1_CPU_FT1		0x0013	/* S5143, single CPU, FT1 */
-#define S5144_ADPTR_1_CPU_T1E1		0x0014	/* S5144, single CPU, T1/E1 */
-#define S5145_ADPTR_1_CPU_56K		0x0015	/* S5145, single CPU, 56K */
-#define S5147_ADPTR_2_CPU_T1E1		0x0017  /* S5147, dual CPU, T1/E1 */
-#define S5148_ADPTR_1_CPU_T1E1		0x0018	/* S5148, single CPU, T1/E1 */
-
-#define S518_ADPTR_1_CPU_ADSL		0x0018	/* S518, adsl card */
-
-#define A101_ADPTR_TE1_MASK		0x0040	/* Single T1/E1 type mask  */
-#define A101_ADPTR_1TE1			0x0041	/* 1 Channel T1/E1  */
-#define A101_ADPTR_2TE1			0x0042	/* 2 Channels T1/E1 */
-
-#define A104_ADPTR_TE1_MASK		0x0080	/* Quad T1/E1 type mask  */
-#define A104_ADPTR_4TE1			0x0081	/* Quad line T1/E1 */
-#define A104_ADPTR_4TE1_PCIX		0x0082	/* Quad line T1/E1 PCI Express */
-
-#define A108_ADPTR_TE1_MASK		0x0200	/* 8 Channels T1/E1 type mask  */
-#define A108_ADPTR_8TE1			0x0201	/* 8 Channels T1/E1 */
-
-#define A100_ADPTR_T3E3_MASK		0x0100	/* T3/E3  type mask */
-#define A100_ADPTR_U_1TE3		0x0101	/* 1 Channel T3/E3 (Proto) */
-#define A300_ADPTR_U_1TE3		0x0102	/* 1 Channel T3/E3 (unchannelized) */
-#define A305_ADPTR_C_1TE3		0x0104	/* 1 Channel T3/E3 (channelized) */
-
-#define A200_ADPTR_ANALOG_MASK		0x0400	/* AFT-200 REMORA analog board mask */
-#define A200_ADPTR_ANALOG		0x0401	/* AFT-200 REMORA analog board */
-
-#define A400_ADPTR_ANALOG_MASK		0x0800	/* AFT-400 REMORA analog board mask */
-#define A400_ADPTR_ANALOG		0x0801	/* AFT-400 REMORA analog board */
-
-#define AFT_ADPTR_ISDN_MASK		0x1000	/* AFT ISDN BRI board mask */
-#define AFT_ADPTR_ISDN			0x1001	/* AFT ISDN BRI board */
-
-#define AFT_ADPTR_56K_MASK		0x2000	/* AFT 56K board mask */
-#define AFT_ADPTR_56K			0x2001	/* AFT 56K board */
-
-#define AFT_ADPTR_SERIAL_MASK		0x4000	/* AFT Serial base board mask */
-#define AFT_ADPTR_2SERIAL_V35X21	0x4001	/* AFT-A142 2 Port V.35/X.21 board */
-#define AFT_ADPTR_4SERIAL_V35X21	0x4002	/* AFT-A144 4 Port V.35/X.21 board */
-#define AFT_ADPTR_2SERIAL_RS232		0x4003	/* AFT-A142 2 Port RS232 board */
-#define AFT_ADPTR_4SERIAL_RS232		0x4004	/* AFT-A144 4 Port RS232 board */
+enum {
+	S5141_ADPTR_1_CPU_SERIAL = 0x01,/* S5141, single CPU, serial */
+	S5142_ADPTR_2_CPU_SERIAL,	/* S5142, dual CPU, serial */
+	S5143_ADPTR_1_CPU_FT1,		/* S5143, single CPU, FT1 */
+	S5144_ADPTR_1_CPU_T1E1,		/* S5144, single CPU, T1/E1 */
+	S5145_ADPTR_1_CPU_56K,		/* S5145, single CPU, 56K */
+	S5147_ADPTR_2_CPU_T1E1,		/* S5147, dual CPU, T1/E1 */
+	S5148_ADPTR_1_CPU_T1E1,		/* S5148, single CPU, T1/E1 */
+	S518_ADPTR_1_CPU_ADSL,		/* S518, adsl card */
+	A101_ADPTR_1TE1,		/* 1 Channel T1/E1  */
+	A101_ADPTR_2TE1,		/* 2 Channels T1/E1 */
+	A104_ADPTR_4TE1,		/* Quad line T1/E1 */
+	A104_ADPTR_4TE1_PCIX,		/* Quad line T1/E1 PCI Express */
+	A108_ADPTR_8TE1,		/* 8 Channels T1/E1 */
+	A100_ADPTR_U_1TE3,		/* 1 Channel T3/E3 (Proto) */
+	A300_ADPTR_U_1TE3,		/* 1 Channel T3/E3 (unchannelized) */
+	A305_ADPTR_C_1TE3,		/* 1 Channel T3/E3 (channelized) */	
+	A200_ADPTR_ANALOG,		/* AFT-200 REMORA analog board */
+	A400_ADPTR_ANALOG,		/* AFT-400 REMORA analog board */
+	AFT_ADPTR_ISDN,			/* AFT ISDN BRI board */
+	AFT_ADPTR_56K,			/* AFT 56K board */
+	AFT_ADPTR_2SERIAL_V35X21,	/* AFT-A142 2 Port V.35/X.21 board */
+	AFT_ADPTR_4SERIAL_V35X21,	/* AFT-A144 4 Port V.35/X.21 board */
+	AFT_ADPTR_2SERIAL_RS232,	/* AFT-A142 2 Port RS232 board */
+	AFT_ADPTR_4SERIAL_RS232,	/* AFT-A144 4 Port RS232 board */
+	U100_ADPTR,			/* USB board */
+	AFT_ADPTR_A600,			/* AFT A600 board */
+	AFT_ADPTR_FLEXBRI,		/* AFT-A700 FlexBRI board */
 
-/* Adapter types cannot be more than 2 bytes */
-#define AFT_ADPTR_A600_MASK             0x8100  /* AFT A600 board mask */
-#define AFT_ADPTR_A600                  0x8101  /* AFT A600 board */
+	AFT_ADPTR_LAST			/* NOTE: Keep it as a last line */
+};
+#define MAX_ADPTRS	AFT_ADPTR_LAST
 
 #define OPERATE_T1E1_AS_SERIAL		0x8000  /* For bitstreaming only 
 						 * Allow the applicatoin to 
@@ -310,7 +291,9 @@
 		(adapter_type == AFT_ADPTR_4SERIAL_V35X21) ? "AFT-A144" : \
 		(adapter_type == AFT_ADPTR_2SERIAL_RS232)  ? "AFT-A142" : \
 		(adapter_type == AFT_ADPTR_4SERIAL_RS232)  ? "AFT-A144" : \
+		(adapter_type == U100_ADPTR) 	 	   ? "U100"  : \
 		(adapter_type == AFT_ADPTR_A600)           ? "AFT-B600" : \
+		(adapter_type == AFT_ADPTR_FLEXBRI)  ? "AFT-B700" : \
 							     "UNKNOWN"
 			
 #define AFT_GET_SECURITY(security)					\
@@ -333,7 +316,20 @@
 		(adptr_subtype == AFT_SUBTYPE_SHARK)	? "SHARK" : ""
 
 #define AFT_PCITYPE_DECODE(hwcard)				\
-		((hwcard)->pci_bridge_dev) ? "PCIe" : "PCI"
+		((hwcard)->u_pci.pci_bridge_dev) ? "PCIe" : "PCI"
+
+#if defined(__WINDOWS__)
+#define AFT_PCIBRIDGE_DECODE(hwcard)		"not defined"
+#else
+#define AFT_PCIBRIDGE_DECODE(hwcard)							\
+		(!(hwcard)->u_pci.pci_bridge_dev) ? "NONE" :				\
+		 ((hwcard)->u_pci.pci_bridge_dev->vendor == PLX_VENDOR_ID &&		\
+		 (hwcard)->u_pci.pci_bridge_dev->device == PLX_DEVICE_ID) ? "PLX1" :   \
+		((hwcard)->u_pci.pci_bridge_dev->vendor == PLX_VENDOR_ID &&		\
+		 (hwcard)->u_pci.pci_bridge_dev->device == PLX2_DEVICE_ID) ? "PLX2" :  \
+		((hwcard)->u_pci.pci_bridge_dev->vendor == TUNDRA_VENDOR_ID &&		\
+		 (hwcard)->u_pci.pci_bridge_dev->device == TUNDRA_DEVICE_ID) ? "TUND" : "NONE"
+#endif
 
 #if defined(__WINDOWS__)
 #define DECODE_CARD_SUBTYPE(card_sub_type)						\
@@ -344,6 +340,7 @@
 		(card_sub_type == A104_4TE1_SUBSYS_VENDOR)	? "A104" :		\
 		(card_sub_type == AFT_4TE1_SHARK_SUBSYS_VENDOR)	? "A104D" :		\
 		(card_sub_type == AFT_8TE1_SHARK_SUBSYS_VENDOR)	? "A108D"  :	\
+		(card_sub_type == AFT_ADPTR_FLEXBRI)		? "B700"  :	\
 		(card_sub_type == A200_REMORA_SHARK_SUBSYS_VENDOR)? "A200"  : "Unknown"
 
 #define SDLA_CARD_TYPE_DECODE(cardtype)				\
Only in include/: sdlasfm.h.orig
diff -dur include/sdla_ss7.h /usr/include/wanpipe/sdla_ss7.h
--- include/sdla_ss7.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_ss7.h	2009-07-14 13:02:00.000000000 -0400
@@ -45,7 +45,9 @@
 #define FLUSH_GLOBAL_STATISTICS				0x05	/* flush the global statistics */
 #define SET_MODEM_STATUS						0x06	/* set the status of DTR and/or RTS */
 #define READ_MODEM_STATUS						0x07	/* read the current status of CTS and DCD */
+#undef READ_COMMS_ERROR_STATS
 #define READ_COMMS_ERROR_STATS				0x08	/* read the communication error statistics */
+#undef FLUSH_COMMS_ERROR_STATS
 #define FLUSH_COMMS_ERROR_STATS				0x09	/* flush the communication error statistics */
 #define SET_TRACE_CONFIGURATION				0x0A	/* set the line trace configuration */
 #define READ_TRACE_CONFIGURATION				0x0B	/* read the line trace configuration */
diff -dur include/sdla_tdmv.h /usr/include/wanpipe/sdla_tdmv.h
--- include/sdla_tdmv.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_tdmv.h	2009-07-14 13:02:00.000000000 -0400
@@ -29,15 +29,11 @@
 
 #if defined(WAN_KERNEL)
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
-# if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE_ECHOMASTER)
-#  include <wanpipe_edac_iface.h>
-# endif
-#else
+
 # if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE_ECHOMASTER)
-#  include <linux/wanpipe_edac_iface.h>
+#  include "wanpipe_edac_iface.h"
 # endif
-#endif
+
 
 /******************************************************************************
 **			  DEFINES and MACROS
@@ -67,6 +63,7 @@
 	int	brt_enable;
 	int	sig_intr_enable;
 	int	spanno;
+
 #if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE_ECHOMASTER)
 	wan_tdmv_rxtx_pwr_t chan_pwr[31];	
 #endif
@@ -94,9 +91,12 @@
 	int	(*init)(void*, wanif_conf_t*);
 	int	(*free)(wan_tdmv_t*);
 	int	(*polling)(void*);
-	int	(*buf_rotate)(void *pcard,u32,unsigned long);
+	int	(*buf_rotate)(void *pcard,u32,unsigned long,int);
 	int	(*ec_span)(void *pcard);
 
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+	int	(*update_regs)(void*, int, u8*);	/* USB-FXO */
+#endif
 } wan_tdmv_iface_t;
 
 /******************************************************************************
@@ -105,6 +105,9 @@
 EXTERN int wp_tdmv_te1_init(wan_tdmv_iface_t *iface);
 EXTERN int wp_tdmv_remora_init(wan_tdmv_iface_t *iface);
 EXTERN int wp_tdmv_bri_init(wan_tdmv_iface_t *iface);
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+EXTERN int wp_usb_tdmv_remora_init(wan_tdmv_iface_t *iface);
+#endif
 
 #ifdef CONFIG_PRODUCT_WANPIPE_TDM_VOICE_ECHOMASTER
 EXTERN int wp_tdmv_echo_check(wan_tdmv_t *wan_tdmv, void *current_ztchan, int channo);
Only in /usr/include/wanpipe/: sdla_tdmv.mar8.h
diff -dur include/sdla_te1_ds.h /usr/include/wanpipe/sdla_te1_ds.h
--- include/sdla_te1_ds.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_te1_ds.h	2009-07-14 13:02:00.000000000 -0400
@@ -102,6 +102,13 @@
 #define BIT_T1RCR2_RAIIE	0x02
 #define BIT_T1RCR2_RD4RM	0x01
 
+#define REG_E1RSAIMR		0x14
+#define BIT_E1RSAIMR_Rsa4IM	0x10
+#define BIT_E1RSAIMR_Rsa5IM	0x08
+#define BIT_E1RSAIMR_Rsa6IM	0x04
+#define BIT_E1RSAIMR_Rsa7IM	0x02
+#define BIT_E1RSAIMR_Rsa8IM	0x01
+
 #define REG_T1RBOCC		0x15
 #define BIT_T1RBOCC_RBR		0x80
 #define BIT_T1RBOCC_RBD1	0x02
@@ -147,6 +154,15 @@
 #define REG_E1RNAF		0x65
 #define BIT_E1RNAF_A		0x20
 
+#define REG_SaBITS		0x6E
+#define BIT_SaBITS_Sa4		0x10
+#define BIT_SaBITS_Sa5		0x08
+#define BIT_SaBITS_Sa6		0x04
+#define BIT_SaBITS_Sa7		0x02
+#define BIT_SaBITS_Sa8		0x01
+
+#define REG_Sa6CODE		0x6F
+
 #define REG_RMMR		0x80
 #define BIT_RMMR_FRM_EN		0x80
 #define BIT_RMMR_INIT_DONE	0x40
@@ -275,12 +291,14 @@
 #define REG_RLS6		0x95
 
 #define REG_RLS7		0x96
-#define BIT_RLS7_RRAI_CI	0x20
-#define BIT_RLS7_RAIS_CI	0x10
-#define BIT_RLS7_RSLC96		0x08
-#define BIT_RLS7_RFDLF		0x04
-#define BIT_RLS7_BC		0x02
-#define BIT_RLS7_BD		0x01
+#define BIT_RLS7_T1_RRAI_CI	0x20
+#define BIT_RLS7_T1_RAIS_CI	0x10
+#define BIT_RLS7_T1_RSLC96	0x08
+#define BIT_RLS7_T1_RFDLF	0x04
+#define BIT_RLS7_T1_BC		0x02
+#define BIT_RLS7_T1_BD		0x01
+#define BIT_RLS7_E1_Sa6CD	0x02
+#define BIT_RLS7_E1_SaXCD	0x01
 
 #define REG_RSS1		0x98
 #define BIT_RSS1_CH1		0x80
@@ -322,6 +340,9 @@
 #define BIT_RSS4_CH31		0x02
 #define BIT_RSS4_CH32		0x01
 
+#define REG_T1RSCD1		0x9C
+#define REG_T1RSCD2		0x9D
+
 #define REG_RIIR		0x9F
 #define BIT_RIIR_RLS7		0x40
 #define BIT_RIIR_RLS6		0x20
@@ -381,8 +402,8 @@
 #define BIT_RIM5_RNES		0x01
 
 #define REG_RIM7		0xA6
-#define BIT_RIM7_RSLC96		0x08
-#define BIT_RIM7_RFDLF		0x04
+#define BIT_RIM7_T1_RSLC96	0x08
+#define BIT_RIM7_T1_RFDLF	0x04
 #define BIT_RIM7_T1_BC		0x02
 #define BIT_RIM7_T1_BD		0x01
 
@@ -636,6 +657,9 @@
 		((len)==7) 		? BIT_TCR4_TC1 :	\
 		((len)==5)		? 0x00 : (BIT_TCR4_TC1|BIT_TCR4_TC0)
 		
+	
+
+
 #define REG_TXPC		0x18A
 #define BIT_TXPC_TBPDIR		0x04
 #define BIT_TXPC_TBPFUS		0x02
diff -dur include/sdla_te1.h /usr/include/wanpipe/sdla_te1.h
--- include/sdla_te1.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_te1.h	2009-07-14 13:02:00.000000000 -0400
@@ -75,27 +75,28 @@
 #define WAN_TE_SIG_INTR		0x02
 
 /* Framer Alarm bit mask */
-#define WAN_TE_BIT_FRAMER_ALARM_MASK	0x0000FFFF
-#define WAN_TE_BIT_LIU_ALARM_MASK	0x00F00000
-#define WAN_TE_BIT_ALOS_ALARM		0x00000001
-#define WAN_TE_BIT_LOS_ALARM		0x00000002
-#define WAN_TE_BIT_ALTLOS_ALARM		0x00000004
-#define WAN_TE_BIT_OOF_ALARM		0x00000008
-#define WAN_TE_BIT_RED_ALARM		0x00000010
-#define WAN_TE_BIT_AIS_ALARM		0x00000020
-#define WAN_TE_BIT_OOSMF_ALARM		0x00000040
-#define WAN_TE_BIT_OOCMF_ALARM		0x00000080
-#define WAN_TE_BIT_OOOF_ALARM		0x00000100
-#define WAN_TE_BIT_RAI_ALARM		0x00000200
-#define WAN_TE_BIT_YEL_ALARM		0x00000400
-#define WAN_TE_BIT_LOOPUP_CODE		0x00002000	
-#define WAN_TE_BIT_LOOPDOWN_CODE	0x00004000	
-#define WAN_TE_BIT_LIU_ALARM		0x00100000
-#define WAN_TE_BIT_LIU_ALARM_SC		0x00200000
-#define WAN_TE_BIT_LIU_ALARM_OC		0x00400000
-#define WAN_TE_BIT_LIU_ALARM_LOS	0x00800000
+#define WAN_TE_ALARM_LIU		0x80000000
+
+#define WAN_TE_ALARM_MASK_FRAMER    	0x0000FFFF
+#define WAN_TE_ALARM_MASK_LIU	    	0x00F00000
+#define WAN_TE_BIT_ALOS_ALARM		 0x00000001
+#define WAN_TE_BIT_LOS_ALARM		 0x00000002
+#define WAN_TE_BIT_ALTLOS_ALARM		 0x00000004
+#define WAN_TE_BIT_OOF_ALARM		 0x00000008
+#define WAN_TE_BIT_RED_ALARM		 0x00000010
+#define WAN_TE_BIT_AIS_ALARM		 0x00000020
+#define WAN_TE_BIT_OOSMF_ALARM		 0x00000040
+#define WAN_TE_BIT_OOCMF_ALARM		 0x00000080
+#define WAN_TE_BIT_OOOF_ALARM		 0x00000100
+#define WAN_TE_BIT_RAI_ALARM		 0x00000200
+#define WAN_TE_BIT_YEL_ALARM		 0x00000400
+#define WAN_TE_BIT_LOOPUP_CODE		 0x00002000	
+#define WAN_TE_BIT_LOOPDOWN_CODE	 0x00004000	
+#define WAN_TE_BIT_LIU_ALARM		 0x00100000
+#define WAN_TE_BIT_LIU_ALARM_SC		 0x00100000
+#define WAN_TE_BIT_LIU_ALARM_OC		 0x00200000
+#define WAN_TE_BIT_LIU_ALARM_LOS	 0x00400000
 
-#define WAN_TE_BIT_TE1_ALARM		0x8000	/* for Windows only */
 #define IS_TE_ALARM(alarm, mask)	(alarm & mask)
 #define IS_TE_ALOS_ALARM(alarm)		IS_TE_ALARM(alarm, WAN_TE_BIT_ALOS_ALARM)
 #define IS_TE_LOS_ALARM(alarm)		IS_TE_ALARM(alarm, WAN_TE_BIT_LOS_ALARM)
@@ -337,6 +338,9 @@
 						"Unknown"
 
 /* Front-End UDP command */
+
+#define WAN_FE_SET_LB_MODE	WAN_FE_LB_MODE
+
 #define WAN_FE_GET_STAT		(WAN_FE_UDP_CMD_START + 0)
 #define WAN_FE_LB_MODE		(WAN_FE_UDP_CMD_START + 1)
 #define WAN_FE_FLUSH_PMON	(WAN_FE_UDP_CMD_START + 2)
@@ -353,6 +357,7 @@
 #define WAN_TE_INTR_FXS_DTMF	0x08
 #define WAN_TE_INTR_PMON	0x10
 
+
 /*----------------------------------------------------------------------------
  * T1/E1 configuration structures.
  */
@@ -394,9 +399,6 @@
 	char		rxlevel[WAN_TE_RXLEVEL_LEN];
 } sdla_te_stats_t;
 
-/******************************************************************************
-**  BERT definitions
-**/
 #define WAN_TE_BERT_CMD_NONE	0x00
 #define WAN_TE_BERT_CMD_STOP	0x01
 #define WAN_TE_BERT_CMD_START	0x02
@@ -640,7 +642,7 @@
 	unsigned char	lb_tx_mode;
 	unsigned char	lb_tx_code;
 	unsigned long	lb_tx_cnt;
-	
+
 	unsigned long	critical;
 	
 	//unsigned char	timer_cmd;
Only in /usr/include/wanpipe/: sdla_usb_remora.h
diff -dur include/sdla_x25.h /usr/include/wanpipe/sdla_x25.h
--- include/sdla_x25.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_x25.h	2009-07-14 13:02:00.000000000 -0400
@@ -27,7 +27,7 @@
  */
 
 
-#include <linux/wanpipe_x25_kernel.h>
+#include "wanpipe_x25_kernel.h"
 
 #pragma pack(1)
 
diff -dur include/sdla_xilinx.h /usr/include/wanpipe/sdla_xilinx.h
--- include/sdla_xilinx.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/sdla_xilinx.h	2009-07-14 13:02:00.000000000 -0400
@@ -41,13 +41,6 @@
 #define XILINX_HDLC_RX_INTR_PENDING_REG	0x54
 
 
-/* Possible RX packet errors */ 
-enum {
-	WP_FIFO_ERROR_BIT,
-	WP_CRC_ERROR_BIT,
-	WP_ABORT_ERROR_BIT,
-};
-
 /* Maximum number of frames in a fifo
  * where frame lengths vary from 1 to 4 bytes */
 #define WP_MAX_FIFO_FRAMES	7
@@ -901,31 +894,6 @@
 };
 #endif
 
-#pragma pack(1)
-typedef struct {
-	unsigned char	error_flag;
-	unsigned short	time_stamp;
-	unsigned short	channel;
-	unsigned char	reserved[11];
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr;
-        unsigned char  	data[1];
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	attr;
-	unsigned char   misc_Tx_bits;
-	unsigned char  	reserved[14];
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr;
-	unsigned char	data[1];
-} api_tx_element_t;
-#pragma pack()
-
 #if !defined(__WINDOWS__)/* use 'wan_udphdr_aft_data'! */
 #undef  wan_udphdr_data
 #define wan_udphdr_data	wan_udphdr_u.aft.data
@@ -1008,39 +976,6 @@
 	TX_DMA_BUF_USED
 };
 
-#if !defined(__WINDOWS__) 
-enum {
-	ROUTER_UP_TIME = 0x50,
-	ENABLE_TRACING,	
-	DISABLE_TRACING,
-	GET_TRACE_INFO,
-	READ_CODE_VERSION,
-	FLUSH_OPERATIONAL_STATS,
-	OPERATIONAL_STATS,
-	READ_OPERATIONAL_STATS,
-	READ_CONFIGURATION,
-	READ_COMMS_ERROR_STATS,
-	FLUSH_COMMS_ERROR_STATS,
-	AFT_LINK_STATUS,
-	AFT_MODEM_STATUS,
-	AFT_HWEC_STATUS,
-	DIGITAL_LOOPTEST
-};
-#endif
-
-#define UDPMGMT_SIGNATURE		"AFTPIPEA"
-
-/* the line trace status element presented by the frame relay code */
-typedef struct {
-        unsigned char flag	; /* ready flag */
-        unsigned short length   ; /* trace length */
-        unsigned char rsrv0[2]  ; /* reserved */
-        unsigned char attr      ; /* trace attributes */
-        unsigned short tmstamp  ; /* time stamp */
-        unsigned char rsrv1[4]  ; /* reserved */
-        unsigned long offset    ; /* buffer absolute address */
-}aft_trc_el_t;
-
 
 typedef struct wp_rx_element
 {
@@ -1048,9 +983,6 @@
 	unsigned int reg;
 	unsigned int align;
 	unsigned char pkt_error;
-#if defined(__WINDOWS__)
-	api_header_t rx_info;
-#endif
 }wp_rx_element_t;
 
 
@@ -1152,21 +1084,6 @@
 	}	
 }
 
-static __inline int
-aft_get_num_of_slots(u32 total_slots, u32 chan_slots)
-{	
-	int num_of_slots=0;
-	u32 i;
-	for (i=0;i<total_slots;i++){
-		if (wan_test_bit(i,&chan_slots)){
-			num_of_slots++;
-		}
-	}
-
-	return num_of_slots;
-}
-
-
 #define AFT_TX_TIMEOUT 25
 #define AFT_RX_TIMEOUT 10
 #define AFT_MAX_WTD_TIMEOUT 250
@@ -1196,83 +1113,5 @@
 #endif /* WAN_KERNEL */
 
 
-#if defined(__LINUX__)
-enum {
-	SIOC_AFT_CUSTOMER_ID = SIOC_WANPIPE_DEVPRIVATE
-};
-#endif
-
-#pragma pack(1)
-
-/* the operational statistics structure */
-typedef struct {
-
-	/* Data frame transmission statistics */
-	unsigned long Data_frames_Tx_count ;	
-	/* # of frames transmitted */
-	unsigned long Data_bytes_Tx_count ; 	
-	/* # of bytes transmitted */
-	unsigned long Data_Tx_throughput ;	
-	/* transmit throughput */
-	unsigned long no_ms_for_Data_Tx_thruput_comp ;	
-	/* millisecond time used for the Tx throughput computation */
-	unsigned long Tx_Data_discard_lgth_err_count ;	
-
-	/* Data frame reception statistics */
-	unsigned long Data_frames_Rx_count ;	
-	/* number of frames received */
-	unsigned long Data_bytes_Rx_count ;	
-	/* number of bytes received */
-	unsigned long Data_Rx_throughput ;	
-	/* receive throughput */
-	unsigned long no_ms_for_Data_Rx_thruput_comp ;	
-	/* millisecond time used for the Rx throughput computation */
-	unsigned long Rx_Data_discard_short_count ;	
-	/* received Data frames discarded (too short) */
-	unsigned long Rx_Data_discard_long_count ;	
-	/* received Data frames discarded (too long) */
-	unsigned long Rx_Data_discard_inactive_count ;	
-	/* received Data frames discarded (link inactive) */
-
-	/* Incomming frames with a format error statistics */
-	unsigned short Rx_frm_incomp_CHDLC_hdr_count ;	
-	/* frames received of with incomplete Cisco HDLC header */
-	unsigned short Rx_frms_too_long_count ;		
-	/* frames received of excessive length count */
-
-	/* CHDLC link active/inactive and loopback statistics */
-	unsigned short link_active_count ;		
-	/* number of times that the link went active */
-	unsigned short link_inactive_modem_count ;	
-	/* number of times that the link went inactive (modem failure) */
-	unsigned short link_inactive_keepalive_count ;	
-	/* number of times that the link went inactive (keepalive failure) */
-	unsigned short link_looped_count ;		
-	/* link looped count */
-
-	unsigned long Data_frames_Tx_realign_count;
-
-} aft_op_stats_t;
-
-typedef struct {
-	unsigned int Rx_overrun_err_count;
-	unsigned int Rx_crc_err_count ;		/* receiver CRC error count */
-	unsigned int Rx_abort_count ; 	/* abort frames recvd count */
-	unsigned int Rx_hdlc_corrupiton;	/* receiver disabled */
-	unsigned int Rx_pci_errors;		/* missed tx underrun interrupt count */
-        unsigned int Rx_dma_descr_err;   	/*secondary-abort frames tx count */
-	unsigned int DCD_state_change_count ; /* DCD state change */
-	unsigned int CTS_state_change_count ; /* CTS state change */
-	
-	unsigned int Tx_pci_errors;		/* missed tx underrun interrupt count */
-	unsigned int Tx_dma_errors;		/* missed tx underrun interrupt count */
-	unsigned int Tx_pci_latency;		/* missed tx underrun interrupt count */
-	unsigned int Tx_dma_len_nonzero;	/* Tx dma descriptor len not zero */
-} aft_comm_err_stats_t;
-
- 
-
-#pragma pack()
-
 
 #endif
diff -dur include/ss7_linux.h /usr/include/wanpipe/ss7_linux.h
--- include/ss7_linux.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/ss7_linux.h	2009-07-14 13:02:00.000000000 -0400
@@ -51,28 +51,6 @@
 	unsigned char	data[1]		;
 } trace_pkt_t;
 
-typedef struct {
-	unsigned char	SIO	;
-	unsigned short	time_stamp	;
-	unsigned char	reserved[13]	;
-} api_rx_hdr_t;
-
-typedef struct {
-        api_rx_hdr_t	api_rx_hdr      ;
-        void *   	data    	;
-} api_rx_element_t;
-
-typedef struct {
-	unsigned char 	SIO		;
-	unsigned char  	reserved[15]	;
-} api_tx_hdr_t;
-
-typedef struct {
-	api_tx_hdr_t 	api_tx_hdr	;
-	void *		data		;
-} api_tx_element_t;
-
-
 /* modem status changes */
 #define DCD_HIGH	0x08
 #define CTS_HIGH	0x20
@@ -96,7 +74,11 @@
 #define TRACE_DATA			0x02
 
 #define UDPMGMT_UDP_PROTOCOL 0x11
-#define UDPMGMT_SIGNATURE    "CTPIPEAB"   /* "STPIPEAB" */
+
+#ifdef UDPMGMT_SIGNATURE
+# undef UDPMGMT_SIGNATURE
+# define UDPMGMT_SIGNATURE    "CTPIPEAB"   /* "STPIPEAB" */
+#endif
 
 
 #pragma pack()
Only in /usr/include/wanpipe/: wanec_iface_api.h
diff -dur include/wanec_iface.h /usr/include/wanpipe/wanec_iface.h
--- include/wanec_iface.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanec_iface.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,5 +1,5 @@
 /******************************************************************************
- * wanec_iface.h	
+ * wanec_iface.h
  *
  * Author: 	Alex Feldman  <al.feldman@sangoma.com>
  *
@@ -16,28 +16,22 @@
 #ifndef __WANEC_IFACE_H
 # define __WANEC_IFACE_H
 
-#if defined(__LINUX__)
-# include <linux/wanpipe_cfg.h>
-# include <linux/wanpipe_events.h>
-#elif defined(__WINDOWS__)
 
-#if defined(__KERNEL__)
+#if defined(__WINDOWS__)
+# if defined(__KERNEL__)
 # define _DEBUG
 # include <DebugOut.h>
-#else
-# include <windows.h>
-#endif
-
-#define MAX_EC_CHANS 256
-
-# include <wanpipe_defines.h>
-# include <wanpipe_includes.h>
-# include <wanpipe_events.h>
+# else
+#  include <windows.h>
+# endif
 
-#elif defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <wanpipe_events.h>
 #endif
 
+#include "wanpipe_includes.h"
+#include "wanpipe_defines.h"
+#include "wanpipe_cfg.h"
+#include "wanpipe_events.h"
+
 #if defined(__WINDOWS__)
 #include <oct6100_api.h>
 #else
@@ -63,50 +57,51 @@
 	WAN_EC_STATE_READY,
 	WAN_EC_STATE_CHIP_OPEN_PENDING,
 	WAN_EC_STATE_CHIP_OPEN,
-	WAN_EC_STATE_CHIP_READY
+	WAN_EC_STATE_CHAN_READY
 };
 #define WAN_EC_STATE_DECODE(state)						\
 	(state == WAN_EC_STATE_RESET)			? "Reset" :		\
 	(state == WAN_EC_STATE_READY)			? "Ready" :		\
 	(state == WAN_EC_STATE_CHIP_OPEN_PENDING)	? "Chip Open Pending" :	\
 	(state == WAN_EC_STATE_CHIP_OPEN)		? "Chip Open" :		\
-	(state == WAN_EC_STATE_CHIP_READY)		? "Chip Ready" :	\
+	(state == WAN_EC_STATE_CHAN_READY)		? "Channels Ready" :	\
 					"Unknown"
 
+#define MAX_EC_CHANS		256
+
 #define WAN_NUM_DTMF_TONES	16
-#define WAN_NUM_FAX_TONES	1
 #define WAN_NUM_PLAYOUT_TONES	16
 #define WAN_MAX_TONE_LEN	100
 
-typedef struct wanec_config_ 
+typedef struct wanec_config_
 {
 	u_int16_t		max_channels;
 	int			memory_chip_size;
 	UINT32			debug_data_mode;
-	PUINT8			imageData;	
+	PUINT8			imageData;
 	UINT32			imageSize;
 	int			imageLast;
 
 	wan_custom_conf_t	custom_conf;
 } wanec_config_t;
 
-typedef struct wanec_config_poll_ 
+typedef struct wanec_config_poll_
 {
 	int			cnt;
 } wanec_config_poll_t;
 
-typedef struct wanec_chip_stats_ 
+typedef struct wanec_chip_stats_
 {
 	int				reset;
 	tOCT6100_CHIP_STATS		f_ChipStats;
 } wanec_chip_stats_t;
 
-typedef struct wanec_chip_image_ 
+typedef struct wanec_chip_image_
 {
 	tOCT6100_CHIP_IMAGE_INFO	*f_ChipImageInfo;
 } wanec_chip_image_t;
 
-typedef struct wanec_chan_opmode_ 
+typedef struct wanec_chan_opmode_
 {
 	UINT32			opmode;
 } wanec_chan_opmode_t;
@@ -114,23 +109,23 @@
 typedef struct wanec_chan_mute_
 {
 	unsigned char		port_map;
-	
+
 } wanec_chan_mute_t;
 
-typedef struct wanec_chan_custom_ 
+typedef struct wanec_chan_custom_
 {
 	int			custom;
 	wan_custom_conf_t	custom_conf;
 } wanec_chan_custom_t;
 
-typedef struct wanec_chan_stats_ 
+typedef struct wanec_chan_stats_
 {
 	int				reset;
 	tOCT6100_CHANNEL_STATS		f_ChannelStats;
 } wanec_chan_stats_t;
 
 #define MAX_MONITOR_DATA_LEN	1024
-typedef struct wanec_chan_monitor_ 
+typedef struct wanec_chan_monitor_
 {
 	int			fe_chan;
 	int			data_mode;
@@ -140,9 +135,9 @@
 	UINT8			data[MAX_MONITOR_DATA_LEN+1];
 } wanec_chan_monitor_t;
 
-typedef struct wanec_buffer_config_ 
+typedef struct wanec_buffer_config_
 {
-	UINT8	buffer[WAN_MAX_TONE_LEN];	
+	UINT8	buffer[WAN_MAX_TONE_LEN];
 	PUINT8	data;
 	UINT32	size;
 	UINT32	pcmlaw;
@@ -150,7 +145,7 @@
 } wanec_buffer_config_t;
 
 #define MAX_EC_PLAYOUT_LEN	20
-typedef struct wanec_playout_ 
+typedef struct wanec_playout_
 {
 	UINT32	index;
 	UINT8	port;
@@ -161,16 +156,17 @@
 	INT32	gaindb;
 	BOOL	notifyonstop;
 	UINT32	user_event_id;
-	
+
 	CHAR	str[MAX_EC_PLAYOUT_LEN];
 	UINT32	delay;
 } wanec_playout_t;
 
-typedef struct wanec_dtmf_config_ 
+typedef struct wanec_tone_config_
 {
+	u_int8_t	id;		/* Tone id */
 	u_int8_t	port_map;	/* SOUT/ROUT */
 	u_int8_t	type;		/* PRESENT or STOP */
-} wanec_dtmf_config_t;
+} wanec_tone_config_t;
 
 
 /*===========================================================================*\
@@ -184,7 +180,7 @@
 	/* Interface name to driver (copied by calling process) */
 	unsigned char	devname[WAN_DRVNAME_SZ+1];
 	/*unsigned char	ifname[WAN_IFNAME_SZ+1];*/
-	
+
 	/* Board index. */
 	unsigned int	ulBoardId;
 
@@ -224,7 +220,7 @@
 	if (v & WAN_EC_VERBOSE_EXTRA2) DEBUG_EVENT(format,##msg)
 #endif
 
-#define WANEC_IGNORE	(TRUE+1)	
+#define WANEC_IGNORE	(TRUE+1)
 
 #define	WANEC_BYDEFAULT_NORMAL
 
@@ -236,7 +232,7 @@
 #define WAN_EC_BIT_CRIT_ERROR 	       	5
 #define WAN_EC_BIT_CRIT 	       	6
 
-#define WAN_EC_BIT_EVENT_DTMF 		4
+#define WAN_EC_BIT_EVENT_TONE 		4
 #define WAN_EC_BIT_EVENT_PLAYOUT	5
 
 #define WAN_EC_POLL_NONE		0x00
@@ -249,20 +245,20 @@
 struct wan_ec_confbridge_
 {
 	UINT32	ulHndl;
-	
+
 	WAN_LIST_ENTRY(wan_ec_confbridge_)	next;
 } wan_ec_confbridge_t;
 
 
 struct wan_ec_;
-typedef struct wan_ec_dev_ 
+typedef struct wan_ec_dev_
 {
 	char		*name;
 	char		devname[WAN_DRVNAME_SZ+1];
 	char		ecdev_name[WAN_DRVNAME_SZ+1];
 	int		ecdev_no;
 	sdla_t		*card;
-	
+
 	u_int8_t	fe_media;
 	u_int32_t	fe_lineno;
 	int		fe_start_chan, fe_stop_chan;
@@ -280,19 +276,23 @@
 	int		poll_channel;
 
 	u_int32_t	events;			/* enable events map */
+#if 0
+	/* NC: Moved to wan_ec device */
+	wan_ticks_t	lastint_ticks;
+#endif
 
 	struct wan_ec_	*ec;
 	WAN_LIST_ENTRY(wan_ec_dev_)	next;
 } wan_ec_dev_t;
 
-typedef struct wan_ec_ 
+typedef struct wan_ec_
 {
 	char		name[WAN_DRVNAME_SZ+1];
 	int		usage;
 	int		chip_no;
 	int		state;
-	int		ec_active;	
-	u_int16_t	max_channels;		/* max number of ec channels (security) */
+	int		ec_active;
+	u_int16_t	max_ec_chans;		/* max number of ec channels (security) */
 	int		confbridges_no;		/* number of opened conf bridges */
 	void		*ec_dev;
 	u_int32_t	intcount;
@@ -320,24 +320,20 @@
 	UINT32				ulDebugChannelHndl;
 	INT				DebugChannel;
 	UINT32				ulDebugDataMode;
-#if defined(__WINDOWS__)
-	struct wan_ec_dev_		*pEcDevMap[MAX_EC_CHANS*2];
-#else
 	struct wan_ec_dev_		**pEcDevMap;
-#endif
 	WAN_LIST_HEAD(wan_ec_dev_head_, wan_ec_dev_)			ec_dev_head;
 	WAN_LIST_HEAD(wan_ec_confbridge_head_, wan_ec_confbridge_)	ec_confbridge_head;
 	WAN_LIST_ENTRY(wan_ec_)				next;
 } wan_ec_t;
 
 #if 0
-typedef struct wanec_lip_reg 
+typedef struct wanec_lip_reg
 {
 	unsigned long init;
-	
+
 	void* (*reg) 	(void*, int);
 	int (*unreg)	(void*, void*);
-	
+
 	int (*ioctl)	(void);
 	int (*isr)	(void);
 
@@ -353,7 +349,7 @@
                 return 0;
         }
 
-        if (ec->ec_active >= ec->max_channels) {
+        if (ec->ec_active >= ec->max_ec_chans) {
                 return -EINVAL;
         }
 
Only in /usr/include/wanpipe/: wanec_tones.h
Only in /usr/include/wanpipe/: wan_mem_debug.h
diff -dur include/wanpipe_abstr.h /usr/include/wanpipe/wanpipe_abstr.h
--- include/wanpipe_abstr.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_abstr.h	2009-07-14 13:02:00.000000000 -0400
@@ -24,13 +24,9 @@
 #ifndef _WANPIPE_ABSTR_H
 #define _WANPIPE_ABSTR_H
 
-#if defined(__LINUX__)
-# include <linux/wanpipe_abstr_types.h>
-#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <wanpipe_abstr_types.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_abstr_types.h>
-#endif
+
+#include "wanpipe_abstr_types.h"
+
 
 extern unsigned char* 	wpabs_skb_data(void* skb);
 extern unsigned char* 	wpabs_skb_tail(void* skb);
@@ -43,7 +39,7 @@
 extern void 		wpabs_skb_copyback(void*, int, int, unsigned long); 
 #endif
 
-extern void 		wpabs_skb_copyback_user(void* skb, int off, int len, unsigned long cp);
+extern void 		wpabs_skb_copyback_user(void* skb, int off, int len, ulong_ptr_t cp);
 extern unsigned char* 	wpabs_skb_pull(void* skb, int len);
 extern unsigned char* 	wpabs_skb_put(void* skb, int len);
 extern unsigned char* 	wpabs_skb_push(void* skb, int len);
diff -dur include/wanpipe_abstr_types.h /usr/include/wanpipe/wanpipe_abstr_types.h
--- include/wanpipe_abstr_types.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_abstr_types.h	2009-07-14 13:02:00.000000000 -0400
@@ -16,22 +16,30 @@
 
 #if defined(__FreeBSD__)
 /******************* F R E E B S D ******************************/
-typedef int			wan_ticks_t; 
+typedef int					wan_ticks_t; 
+typedef unsigned long		ulong_ptr_t	
 #elif defined(__OpenBSD__)
 /******************* O P E N B S D ******************************/
-typedef int			wan_ticks_t; 
+typedef int					wan_ticks_t; 
+typedef unsigned long		ulong_ptr_t	
 #elif defined(__NetBSD__)
 /******************* N E T B S D ******************************/
-typedef int			wan_ticks_t; 
+typedef int					wan_ticks_t; 
+typedef unsigned long		ulong_ptr_t	
 #elif defined(__LINUX__)
 /*********************** L I N U X ******************************/
 typedef unsigned long		wan_ticks_t; 
-
+typedef unsigned long		ulong_ptr_t;	
+typedef unsigned long		wan_time_t; 
+typedef unsigned long		wan_suseconds_t; 
 #elif defined(__WINDOWS__)
 /******************* W I N D O W S ******************************/
 typedef unsigned long		wan_ticks_t; 
+typedef unsigned long		wan_time_t; 
+typedef unsigned long		wan_suseconds_t; 
 #endif
 
 
 
+
 #endif	/* __WANPIPE_ABSTR_TYPES_H */
Only in /usr/include/wanpipe/: wanpipe_api_deprecated.h
Only in /usr/include/wanpipe/: wanpipe_api.h
Only in /usr/include/wanpipe/: wanpipe_api_hdr.h
Only in /usr/include/wanpipe/: wanpipe_api_iface.h
Only in /usr/include/wanpipe/: wanpipe_api_legacy.h
diff -dur include/wanpipe_atm_iface.h /usr/include/wanpipe/wanpipe_atm_iface.h
--- include/wanpipe_atm_iface.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_atm_iface.h	2009-07-14 13:02:00.000000000 -0400
@@ -17,7 +17,7 @@
 #ifndef _SDLA_ATM_IFACE_H
 #define _SDLA_ATM_IFACE_H
 
-#include <linux/wanpipe_cfg.h>
+#include "wanpipe_cfg.h"
 
 extern int  wp_sar_register_device  (void *card, 
 		                     unsigned char *devname,
Only in /usr/include/wanpipe/: wanpipe_cdev_iface.h
diff -dur include/wanpipe_cfg_def.h /usr/include/wanpipe/wanpipe_cfg_def.h
--- include/wanpipe_cfg_def.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_cfg_def.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,27 +1,27 @@
 /*************************************************************************
-* wanpipe_cfg_def.h							 *
-*									 *
-*	WANPIPE(tm)	Wanpipe Global configuration defines 		 *
-*									 *
-* Author:	Alex Feldman <al.feldman@sangoma.com>			 *
-*========================================================================*
-* Aug 27, 2008	Alex Feldman	Initial version				 *
-*									 *
+* wanpipe_cfg_def.h														*
+*																		*
+*	WANPIPE(tm)	Wanpipe Global configuration defines 					*
+*																		*
+* Author:	Alex Feldman <al.feldman@sangoma.com>						*
+*=======================================================================*
+* Aug 27, 2008	Alex Feldman	Initial version							*
+*																		*
 *************************************************************************/
 
 #ifndef __WANPIPE_CFG_DEF_H__
 # define __WANPIPE_CFG_DEF_H__
 
 #if defined(__WINDOWS__)
-#define	WAN_IFNAME_SZ	IFNAMSIZ/* max length of the interface name */
-#define	WAN_DRVNAME_SZ	IFNAMSIZ/* max length of the link driver name */
-#define	WAN_ADDRESS_SZ	31	/* max length of the WAN media address */
+ #define	WAN_IFNAME_SZ	128		/* max length of the interface name */
 #else
-#define	WAN_IFNAME_SZ	15	/* max length of the interface name */
-#define	WAN_DRVNAME_SZ	15	/* max length of the link driver name */
-#define	WAN_ADDRESS_SZ	31	/* max length of the WAN media address */
+ #define	WAN_IFNAME_SZ	15		/* max length of the interface name */
 #endif
 
+#define	WAN_DRVNAME_SZ	WAN_IFNAME_SZ	/* max length of the link driver name */
+#define	WAN_ADDRESS_SZ	31		/* max length of the WAN media address */
+
+
 typedef enum {
     RFC_MODE_BRIDGED_ETH_LLC    = 0,
     RFC_MODE_BRIDGED_ETH_VC     = 1,
@@ -101,7 +101,8 @@
 #define WANOPT_AFT_56K		12
 #define WANOPT_AFT101		13
 #define WANOPT_AFT_SERIAL	14
-#define WANOPT_AFT600		15
+#define WANOPT_USB_ANALOG       15
+#define WANOPT_AFT600           16
 
 /*
  * Configuration options defines.
@@ -116,8 +117,8 @@
 
 /* intercace options */
 #define	WANOPT_RS232	0
-#define	WANOPT_V35		1
-#define WANOPT_X21		2
+#define	WANOPT_V35	1
+#define WANOPT_X21      3
 
 /* data encoding options */
 #define	WANOPT_NRZ	0
@@ -136,7 +137,6 @@
 /* clocking options */
 #define	WANOPT_EXTERNAL	0
 #define	WANOPT_INTERNAL	1
-#define	WANOPT_RECOVERY 2
 
 /* station options */
 #define	WANOPT_DTE		0
@@ -218,7 +218,7 @@
 #define WANOPT_NETWORK_SYNC_OUT	0x00
 #define WANOPT_NETWORK_SYNC_IN	0x01
 
-#define WAN_CLK_OUT_OSC         0x03
-#define WAN_CLK_OUT_LINE        0x04
+#define WAN_CLK_OUT_OSC		0x03
+#define WAN_CLK_OUT_LINE	0x04
 
 #endif /* __WANPIPE_CFG_DEF_H__ */
diff -dur include/wanpipe_cfg_fr.h /usr/include/wanpipe/wanpipe_cfg_fr.h
--- include/wanpipe_cfg_fr.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_cfg_fr.h	2009-07-14 13:02:00.000000000 -0400
@@ -29,12 +29,14 @@
 /*----------------------------------------------------------------------------
  * Frame relay specific link-level configuration.
  */
-#if defined(__WINDOWS__)
-# define DLCI_LIST_LEN MAX_NUMBER_OF_PROTOCOL_INTERFACES
-#else
-# define DLCI_LIST_LEN 100
+
+#ifndef MAX_NUMBER_OF_PROTOCOL_INTERFACES
+#define MAX_NUMBER_OF_PROTOCOL_INTERFACES 100
 #endif
 
+# define DLCI_LIST_LEN MAX_NUMBER_OF_PROTOCOL_INTERFACES
+
+
 typedef struct wan_fr_conf
 {
 	unsigned int signalling;	/* local in-channel signalling type */
@@ -49,9 +51,7 @@
 	unsigned char station;  	/* Node or CPE */
 	unsigned int eek_cfg;		/* EEK Request Reply Mode */
 	unsigned int eek_timer;		/* EEK Request Reply Timer */
-#if defined(__WINDOWS__)
 	unsigned char auto_dlci;	/* 1 - yes, 0 - no */
-#endif
 } wan_fr_conf_t;
 
 /* used by wanpipemon to get DLCI status */
@@ -68,3 +68,4 @@
 
 
 #endif /* __WANPIPE_CFG_FR_H__ */
+
diff -dur include/wanpipe_cfg.h /usr/include/wanpipe/wanpipe_cfg.h
--- include/wanpipe_cfg.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_cfg.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,102 +1,39 @@
+/*****************************************************************************
+* wanpipe_cfg.h	WANPIPE(tm) Sangoma Device Driver.
+******************************************************************************/
+
 #ifndef _WANPIPE_CFG_H_
 #define _WANPIPE_CFG_H_
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <sdla_56k.h>
-# include <sdla_te1.h>
-# include <sdla_te3.h>
-# include <sdla_remora.h>
-# include <sdla_a600_remora.h>
-# include <sdla_bri.h>
-# include <sdla_serial.h>
-# include <sdla_front_end.h>
-# include <wanpipe_cfg_def.h>
-# include <wanpipe_cfg_fr.h>
-# include <wanpipe_cfg_sppp.h>
-# include <wanpipe_cfg_hdlc.h>
-# include <wanpipe_cfg_atm.h>
-# include <wanpipe_cfg_lip.h>
-# include <wanpipe_cfg_adsl.h>
-#elif defined(__LINUX__)
-# include <linux/sdla_56k.h>
-# include <linux/sdla_te1.h>
-# include <linux/sdla_te3.h>
-# include <linux/sdla_remora.h>
-# include <linux/sdla_a600_remora.h>
-# include <linux/sdla_bri.h>
-# include <linux/sdla_serial.h>
-# include <linux/sdla_front_end.h>
-# include <linux/wanpipe_cfg_def.h>
-# include <linux/wanpipe_cfg_fr.h>
-# include <linux/wanpipe_cfg_sppp.h>
-# include <linux/wanpipe_cfg_hdlc.h>
-# include <linux/wanpipe_cfg_atm.h>
-# include <linux/wanpipe_cfg_lip.h>
-# include <linux/wanpipe_cfg_adsl.h>
-
-#ifndef wan_time_t 
-#define wan_time_t unsigned long
-#endif
-#ifndef wan_suseconds_t
-#define wan_suseconds_t unsigned long
-#endif
-
-#elif defined(__WINDOWS__)
-# include <sdla_56k.h>
-# include <sdla_te1.h>
-# include <sdla_te3.h>
-# include <sdla_bri.h>
-# include <sdla_remora.h>
-# include <sdla_a600_remora.h>
-# include <sdla_bri.h>
-# include <sdla_serial.h>
-# include <sdla_front_end.h>
-# include <wanpipe_cfg_structs.h>
-# include <wanpipe_cfg_def.h>
-# include <wanpipe_cfg_fr.h>
-# include <wanpipe_cfg_sppp.h>
-# include <wanpipe_cfg_hdlc.h>
-# include <wanpipe_cfg_atm.h>
-# include <wanpipe_cfg_lip.h>
-# include <wanpipe_cfg_adsl.h>
-#else
-# error "No OS Defined!"
-#endif
+# include "sdla_front_end.h"
+# include "wanpipe_cfg_def.h"
+# include "wanpipe_cfg_fr.h"
+# include "wanpipe_cfg_sppp.h"
+# include "wanpipe_cfg_hdlc.h"
+# include "wanpipe_cfg_atm.h"
+# include "wanpipe_cfg_lip.h"
+# include "wanpipe_cfg_adsl.h"
+# include "wanpipe_abstr_types.h"
 
-/* Miscellaneous */
-#if defined(__WINDOWS__)
+/* The user space applications need the 
+   wan_time_t define. However we cannot include
+   wanpipe_defines.h in kernel mode due to
+   binary only apps like adsl/fr/ppp */
+#if !defined(__KERNEL__)
+# include "wanpipe_defines.h"
+#endif	
 
 /* This is the maximum number of interfaces that any protocol may have.
 For example: a number of DLCIs. */
-#define MAX_NUMBER_OF_PROTOCOL_INTERFACES	(160)
-
+#ifndef MAX_NUMBER_OF_PROTOCOL_INTERFACES
+#define MAX_NUMBER_OF_PROTOCOL_INTERFACES	100
+#endif
 
-/********** compilation flags ************/
-/* compile protocols in the LIP layer */
-#define CONFIG_PRODUCT_WANPIPE_FR
-#define CONFIG_PRODUCT_WANPIPE_CHDLC
-#define CONFIG_PRODUCT_WANPIPE_PPP
-#define CONFIG_PRODUCT_WANPIPE_LAPB
 
-/* compile AFT T1/E1 code */
-#define CONFIG_PRODUCT_WANPIPE_AFT
-/* compile AFT A200 Analog code */
-#define CONFIG_PRODUCT_WANPIPE_AFT_RM
-/* compile HWEC code */
-#define CONFIG_WANPIPE_HWEC
-/* compile ADSL code */
-#define CONFIG_PRODUCT_WANPIPE_ADSL
-/* compile TDM API code */
-#define AFT_TDM_API_SUPPORT
-/* compile ISDN BRI code */
-#define CONFIG_PRODUCT_WANPIPE_AFT_BRI
-/* compile AFT Serial code */
-#define CONFIG_PRODUCT_WANPIPE_AFT_SERIAL
-/* compile A600 code */
-#define CONFIG_PRODUCT_WANPIPE_AFT_A600
-/********** end of compilation flags ************/
+/* Miscellaneous */
+#if defined(__WINDOWS__)
 
-/* Frame Relay definitions for sprotocol.dll 
+/* Frame Relay definitions for sprotocol.dll
 (the Protocol Configurator in Device Manager) */
 #define MIN_T391	5
 #define MAX_T391	30
@@ -112,12 +49,9 @@
 #define HIGHEST_VALID_DLCI	MAX_NUMBER_OF_PROTOCOL_INTERFACES
 #define LOWEST_VALID_DLCI	16
 /********** end of sprotocol.dll definitions ************/
-
-#else
-#define USED_BY_FIELD	30	/* max length of the used by field */
-
 #endif
 
+#define USED_BY_FIELD	128	/* max length of the used by field */
 
 
 enum wan_codec_format{
@@ -128,26 +62,24 @@
 
 /* Interface Operation Modes */
 enum {
-	WANPIPE,
-	API,
+	WANPIPE,		/* TCP/IP over CHDLC, Frame Relay, PPP... */
+	API,			/* Data OR Voice. Requires API Poll. */
 	BRIDGE,
 	BRIDGE_NODE,
 	SWITCH,
 	STACK,
 	ANNEXG,
 	TTY,
-	TDM_VOICE,
-	TDM_VOICE_DCHAN,
-	TDM_VOICE_API,
-#if defined(__WINDOWS__)
-	/* has to be here to keep backward compatibility! */
-	LIB_SANGOMA_API,
-	TDM_VOICE_API_V2,
-#endif
+	TDM_VOICE,		/* Asterisk/Zaptel support */
+	TDM_VOICE_DCHAN, /* Depricated. */
+	TDM_VOICE_API,	/* Linux: Sangoma Voice API support. Windows: Depricated. */
 	TDM_API,
 	WP_NETGRAPH,
 	TRUNK,
-	XMTP2_API
+	XMTP2_API,
+	TDM_SPAN_VOICE_API,	/* Voice API support. Delivers Voice stream from a Span of channels. */
+	TDM_CHAN_VOICE_API,	/* Voice API support. Delivers Voice stream from a single channel. */
+	API_LEGACY			/* Data OR Voice. Windows: Does NOT require API Poll. Linux: runs on Sangoma Socket interface. */
 };
 
 
@@ -203,7 +135,7 @@
 
 #define WANOPT_ADSL_CLOCK_OSCILLATOR            0x00
 #define WANOPT_ADSL_CLOCK_CRYSTAL               0x04
- 
+
 
 #define SDLA_DECODE_CARDTYPE(card_type)				\
 		(card_type == WANOPT_S50X) ?       "S50X" :		\
@@ -215,18 +147,20 @@
 		 card_type == WANOPT_AFT104 ||			\
 		 card_type == WANOPT_AFT108) ?     "A101/1D/A102/2D/4/4D/8" :	\
 		(card_type == WANOPT_AFT300) ?     "A300"  :	\
-		(card_type == WANOPT_AFT_ANALOG) ? "A200/400/600"  :	\
-		(card_type == WANOPT_AFT_ISDN) ?   "A500"  :	\
+		(card_type == WANOPT_AFT_ANALOG) ? "A200/A400/B600/B700"  :	\
+		(card_type == WANOPT_AFT_ISDN) ?   "A500/B700"  :	\
 		(card_type == WANOPT_AFT_56K) ?    "A056"  :	\
 		(card_type == WANOPT_AFT_SERIAL) ? "A14x"  :	\
-					"Unknown"
+		(card_type == WANOPT_USB_ANALOG) ? "U100"  :	\
+		(card_type == WANOPT_AFT600)   ?   "A600"  :	\
+						   "Unknown"
 
 #define COMPORT_DECODE(port)	(port == WANOPT_PRI) ? "PRI" : "SEC"
 
 #define STATE_DECODE(state)					\
 		((state == WAN_UNCONFIGURED) ? "Unconfigured" :	\
 		 (state == WAN_DISCONNECTED) ? "Disconnected" : \
-	         (state == WAN_CONNECTING) ? "Connecting" : 	\
+         (state == WAN_CONNECTING) ? "Connecting" : 	\
 		 (state == WAN_CONNECTED) ? "Connected": 	\
 		 (state == WAN_LIMIT) ? "Limit": 		\
 		 (state == WAN_DUALPORT) ? "DualPort": 		\
@@ -240,19 +174,19 @@
 #define INT_DECODE(interface)					\
 		(interface == WANOPT_RS232) ? "RS232" :	\
 		(interface == WANOPT_V35)	? "V35" :	\
-		(interface == WANOPT_X21)	? "X21" :	"Invalid"
+		"Invalid"
 
 #define SIGNALLING_DECODE(sig)					\
 		(sig == WANOPT_FR_ANSI) ? "ANSI" :	\
 		(sig == WANOPT_FR_Q933) ? "Q333" :	\
 		(sig == WANOPT_FR_LMI) ? "LMI" : "NO"
-		
+
 #define COMPORT_DECODE(port)	(port == WANOPT_PRI) ? "PRI" : "SEC"
 
 #define IP_MODE_DECODE(ip_mode)					\
 		(ip_mode == WANOPT_PPP_STATIC) ? "STATIC" :	\
 		(ip_mode == WANOPT_PPP_PEER) ? "PEER" : "HOST"
-		
+
 #define X25_STATION_DECODE(station)				\
 		(station == WANOPT_DTE) ? "DTE" : 		\
 		(station == WANOPT_DCE) ? "DCE" : "DXE"
@@ -262,10 +196,6 @@
 
 #define DEFAULT_TE_RX_SLEVEL 120
 
-/* Serial RTS/DTS control, default is alwasy HIGH */
-#define WANOPT_HIGH 	0
-#define WANOPT_LOW  	1
-
 typedef char devname_t[WAN_DRVNAME_SZ+1];
 
 
@@ -291,7 +221,7 @@
 	unsigned int  max_length_tx_data_block;
 	unsigned int  rx_complete_length;
 	unsigned int  rx_complete_timer;
-	
+
 	unsigned int  rbs_map;
 
 }wan_bitstrm_conf_t;
@@ -331,8 +261,8 @@
 	unsigned int ccitt_compat;   /* compatibility mode: 1988/1984/1980 */
 	unsigned int x25_conf_opt;   /* User defined x25 config optoins */
 	unsigned char LAPB_hdlc_only; /* Run in HDLC only mode */
-	unsigned char logging;        /* Control connection logging */  
-	unsigned char oob_on_modem; /* Whether to send modem 
+	unsigned char logging;        /* Control connection logging */
+	unsigned char oob_on_modem; /* Whether to send modem
 				       status to the user app */
 	unsigned char local_station_address;  /*Local Station address */
 	unsigned short defPktSize;
@@ -349,7 +279,7 @@
 	unsigned short	rtp_sample;
 	unsigned char	rtp_devname[WAN_IFNAME_SZ+1];
 	unsigned char	rtp_mac[WAN_IFNAME_SZ+1];
-	unsigned char	rtp_local_mac[WAN_IFNAME_SZ+1]; 
+	unsigned char	rtp_local_mac[WAN_IFNAME_SZ+1];
 }wan_rtp_conf_t;
 
 typedef struct wan_xilinx_conf
@@ -359,15 +289,6 @@
 	unsigned int	rbs;		/* Robbit signalling support */
 	unsigned int	data_mux_map;	/* Data mux map */
 	unsigned int	rx_crc_bytes;
-	unsigned char	serial_dtr_ctrl;
-	unsigned char	serial_rts_ctrl;
-#if defined(__WINDOWS__)
-	unsigned short num_of_ch;	/* Number of logical channels */
-	unsigned int   tdmv_span_no;
-	unsigned char  tdmv_hwec;
-	unsigned int   fe_ref_clock;
-	unsigned int   tdmv_dchan;
-#endif
 } wan_xilinx_conf_t;
 
 typedef struct wan_xilinx_conf_if
@@ -383,16 +304,19 @@
 	unsigned char 	ss7_mode;
 	unsigned char	ss7_lssu_size;
 	unsigned char	tdmv_master_if;
-/*	unsigned char   tdmv_hwec;	*/	/* Enable/Disable HW EC */
 	unsigned char   rbs_cas_idle;		/* Initial RBS/CAS value */
-/*	unsigned char   hwec_dtmf;	*/	/* Enable/Disable HW DTMF */
-/*	unsigned char   tdmv_hwec_map[50];*/	/* Enable/Disable HW EC */
 	unsigned char	hdlc_repeat;
-#if defined(__WINDOWS__)
-	unsigned char  tdmv_hwec;
-#endif
+	unsigned int	mtu_idle;
 }wan_xilinx_conf_if_t;
 
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+typedef struct wan_usb_conf_if
+{
+	int	notused;
+
+}wan_usb_conf_if_t;
+#endif
+
 
 typedef struct wan_ss7_conf
 {
@@ -437,32 +361,32 @@
 
 typedef struct wan_xdlc_conf {
 
-	unsigned char  station;		
+	unsigned char  station;
 	unsigned int   address;
 	unsigned int   max_I_field_length;
-	
+
 	unsigned int protocol_config;
 	unsigned int error_response_config;
-	unsigned int TWS_max_ack_count;	
-	
+	unsigned int TWS_max_ack_count;
+
 	unsigned int pri_slow_poll_timer;
 	unsigned int pri_normal_poll_timer;
 	unsigned int pri_frame_response_timer;
 	unsigned int sec_nrm_timer;
-	
+
 	unsigned int max_no_response_cnt;
 	unsigned int max_frame_retransmit_cnt;
 	unsigned int max_rnr_cnt;
-	
+
 	unsigned int window;
-	
+
 }wan_xdlc_conf_t;
 
 
 typedef struct wan_sdlc_conf {
 
-	unsigned char  station_configuration;		
-	unsigned int   baud_rate;	
+	unsigned char  station_configuration;
+	unsigned int   baud_rate;
 	unsigned short max_I_field_length;
 	unsigned short general_operational_config_bits;
 	unsigned short protocol_config_bits;
@@ -472,12 +396,12 @@
 	unsigned short pri_station_slow_poll_interval;
 	unsigned short permitted_sec_station_response_TO;
 	unsigned short no_consec_sec_TOs_in_NRM_before_SNRM_issued;
-	unsigned short max_lgth_I_fld_pri_XID_frame;		
-	unsigned short opening_flag_bit_delay_count;		
+	unsigned short max_lgth_I_fld_pri_XID_frame;
+	unsigned short opening_flag_bit_delay_count;
 	unsigned short RTS_bit_delay_count;
-	unsigned short CTS_timeout_1000ths_sec;	
-	unsigned char  SDLA_configuration;	
-	
+	unsigned short CTS_timeout_1000ths_sec;
+	unsigned char  SDLA_configuration;
+
 }wan_sdlc_conf_t;
 
 
@@ -570,34 +494,34 @@
 	unsigned short X25_statistics_options;
 	unsigned short packet_window;
 	unsigned short default_packet_size;
-	unsigned short maximum_packet_size; 
+	unsigned short maximum_packet_size;
 	unsigned short lowest_PVC;
 	unsigned short highest_PVC;
-	unsigned short lowest_incoming_channel;	
+	unsigned short lowest_incoming_channel;
 	unsigned short highest_incoming_channel;
-	unsigned short lowest_two_way_channel;	
+	unsigned short lowest_two_way_channel;
 	unsigned short highest_two_way_channel;
-	unsigned short lowest_outgoing_channel;		
-	unsigned short highest_outgoing_channel;		
-	unsigned short genl_facilities_supported_1;	
-	unsigned short genl_facilities_supported_2;	
-	unsigned short CCITT_facilities_supported;	
-	unsigned short non_X25_facilities_supported;	
-	unsigned short CCITT_compatibility;				
+	unsigned short lowest_outgoing_channel;
+	unsigned short highest_outgoing_channel;
+	unsigned short genl_facilities_supported_1;
+	unsigned short genl_facilities_supported_2;
+	unsigned short CCITT_facilities_supported;
+	unsigned short non_X25_facilities_supported;
+	unsigned short CCITT_compatibility;
 	unsigned short T10_T20;
 	unsigned short T11_T21;
 	unsigned short T12_T22;
-	unsigned short T13_T23;	
-	unsigned short T16_T26;	
+	unsigned short T13_T23;
+	unsigned short T16_T26;
 	unsigned short T28;
-	unsigned short R10_R20;		
-	unsigned short R12_R22;			
-	unsigned short R13_R23;			
+	unsigned short R10_R20;
+	unsigned short R12_R22;
+	unsigned short R13_R23;
 	unsigned char  dte;
 	unsigned char  mode;
 
-	unsigned char call_string   [X25_CALL_STR_SZ+1];	
-	
+	unsigned char call_string   [X25_CALL_STR_SZ+1];
+
 	/* Accept Call Information */
 	unsigned char accept_called [WAN_ADDRESS_SZ+1];
 	unsigned char accept_calling[WAN_ADDRESS_SZ+1];
@@ -608,7 +532,7 @@
 
 	unsigned int  call_backoff_timeout;
 	unsigned char call_logging;
-	
+
 	/* X25_SW X.25 switching */
 	unsigned char virtual_addr[WAN_ADDRESS_SZ+1];
 	unsigned char real_addr[WAN_ADDRESS_SZ+1];
@@ -618,23 +542,23 @@
 } wan_x25_if_conf_t;
 
 typedef struct dsp_parms {
-	
+
 	unsigned char	pad_type;	/* PAD type: HOST or TERM */
 	unsigned int T1;			/* Service Timeout perioud */
 	unsigned int T2;			/* PAD protocol timeout period */
 	unsigned int T3;			/* Timeout between two packets
 					 * of the same M_DATA */
-	unsigned char auto_ce;		/* Automaticaly send Circuit Enabled 
+	unsigned char auto_ce;		/* Automaticaly send Circuit Enabled
 					 * with ACCEPT CALL packet */
-	unsigned char auto_call_req;	/* Automaticaly re-send CALL REQUEST 
+	unsigned char auto_call_req;	/* Automaticaly re-send CALL REQUEST
 					 * if it was failed before (T1) */
 	unsigned char auto_ack;		/* Automaticaly send ACK for data */
 
 	unsigned short dsp_mtu;		/* MTU size for DSP level */
-	
+
 }wan_dsp_if_conf_t;
-	
-	
+
+
 #if 0
 /*----------------------------------------------------------------------------
  * T1/E1 configuration structures.
@@ -659,19 +583,21 @@
 #endif
 
 typedef struct wan_tdmv_conf_ {
-	
-	unsigned int   span_no;
+
+	unsigned char  span_no;
 	unsigned int   dchan;		/* hwHDLC: PRI SIG */
 	unsigned char  hw_dtmf;		/* TDMV Enable/Disable HW DTMF */
-	unsigned char  hw_fax_detect;   /* TDMV Enable/Disable HW FAX Detect, depends on DTMF */	
+	unsigned char  hw_fax_detect;	/* TDMV Enable/Disable HW FAX Calling */
+	unsigned char  hw_faxcalled;	/* TDMV Enable/Disable HW FAX Called */
 	unsigned char  sdla_tdmv_dummy_enable;
 } wan_tdmv_conf_t;
 
-typedef struct wan_hwec_conf_ 
+typedef struct wan_hwec_conf_
 {
 	unsigned int	clk_src;		/* Octasic Clock Source Port */
 	unsigned int	persist_disable;	/* HW EC Persist */
-	unsigned int	noise_reduction;	/* Noise Reduction control */
+	unsigned char	noise_reduction;			/* Noise Reduction control */
+	unsigned char	noise_reduction_disable;	/* Noise Reduction control - because now its on by default */
 	unsigned int	tone_disabler_delay;	/* delay in a fax mode */
 } wan_hwec_conf_t;
 
@@ -706,14 +632,15 @@
 	int dma;		/* DMA request level */
 	char S514_CPU_no[1];	/* S514 PCI adapter CPU number ('A' or 'B') */
 	unsigned PCI_slot_no;	/* S514 PCI adapter slot number */
-	char auto_pci_cfg;	/* S515 PCI automatic slot detection */
-	unsigned int comm_port;	/* Communication Port (PRI=0, SEC=1) */ 
+	char auto_hw_detect;	/* S515 PCI automatic slot detection */
+	char	usb_busid[30];	/* USB bus id string (FIXME: length is set to 30) (for USB devices) */
+	unsigned int comm_port;	/* Communication Port (PRI=0, SEC=1) */
 	unsigned int bps;	/* data transfer rate */
 	unsigned int mtu;	/* maximum transmit unit size */
-	unsigned udp_port;      /* UDP port for management */
+    unsigned udp_port;      /* UDP port for management */
 	unsigned char ttl;	/* Time To Live for UDP security */
 	unsigned char ft1;	/* FT1 Configurator Option */
-	char electrical_interface;		/* RS-232/V.35, etc. */
+    char electrical_interface;		/* RS-232/V.35, etc. */
 	char clocking;		/* external/internal */
 	char line_coding;	/* NRZ/NRZI/FM0/FM1, etc. */
 	char connection;	/* permanent/switched/on-demand */
@@ -730,11 +657,8 @@
 				/****** arbitrary data ***************/
 	unsigned data_size;	/* data buffer size */
 	void* data;		/* data buffer, e.g. firmware */
-#if defined(__WINDOWS__)
-	struct{
-#else
+
 	union{			/****** protocol-specific ************/
-#endif	
 		wan_x25_conf_t 		x25;	/* X.25 configuration */
 		wan_ppp_conf_t 		ppp;	/* PPP configuration */
 		wan_fr_conf_t 		fr;	/* frame relay configuration */
@@ -759,7 +683,7 @@
 	wan_hwec_conf_t		hwec_conf;
 	wan_rtp_conf_t  	rtp_conf;
 	wan_custom_conf_t	oct_conf;
-	
+
 	unsigned char line_idle; /* IDLE FLAG/ IDLE MARK */
 	unsigned char ignore_front_end_status;
 	unsigned int  max_trace_queue;
@@ -780,6 +704,10 @@
 
 } wandev_conf_t;
 
+#if defined(__WINDOWS__)
+#define WANCONFIG_AFT_FIRMWARE_UPDATE	89
+#endif
+
 /* 'config_id' definitions */
 #define	WANCONFIG_X25		101	/* X.25 link */
 #define	WANCONFIG_FR		102	/* frame relay link */
@@ -821,6 +749,7 @@
 #define WANCONFIG_AFT_ISDN_BRI	137	/* AFT ISDN BRI Driver */
 #define WANCONFIG_AFT_SERIAL	138	/* AFT Serial V32/RS232 Driver */
 #define WANCONFIG_LIP_HDLC	139	/* LIP HDLC protocol */
+#define WANCONFIG_USB_ANALOG	140	/* Wanpipe USB Driver */
 
 /*FIXME: This should be taken out, I just
 //used it so I don't break the apps that are
@@ -866,22 +795,52 @@
 	(protocol ==  WANCONFIG_LIP_HDLC)   ? "LIP HDLC" : \
 	(protocol ==  WANCONFIG_AFT_SERIAL)  ? "AFT Serial" : \
 	(protocol ==  WANCONFIG_AFT_ISDN_BRI)  ? "AFT BRI" : \
-	(protocol ==  WANCONFIG_TTY)	    ? "TTY" : "Unknown Protocol"
+	(protocol ==  WANCONFIG_TTY)	    ? "TTY" : \
+	(protocol ==  WANCONFIG_USB_ANALOG)  ? "USB Analog FXO/FXS" : \
+						"Unknown Protocol"
 
 
 typedef struct wan_tdmv_if_conf
 {
 	unsigned char	tdmv_echo_off;  /* TDMV echo disable */
 	unsigned char	tdmv_codec;     /* TDMV codec */
-	
+
 } wan_tdmv_if_conf_t;
 
 typedef struct wan_hwec_if_conf
 {
 	unsigned char	enable;	/* Enable/Disable HW EC */
-		
+
 } wan_hwec_if_conf_t;
 
+
+
+enum DEVICE_CONFIGURATION_RETURN_CODE{
+
+	DEVICE_CFG_OK = 1,
+	DEVICE_CFG_FAILED_COMMS_ENABLED,
+	DEVICE_CFG_FAILED_INVALID_LENGTH_OF_DATA_QUEUE,	//must be between MINIMUM_LENGTH_OF_DATA_QUEUE
+													//and MAXIMUM_LENGTH_OF_DATA_QUEUE
+
+	DEVICE_CFG_FAILED_INVALID_DATA_LENGTH,		//must be at least	MINIMUM_LENGTH_OF_DATA
+	DEVICE_CFG_FAILED_MEMORY_ALLOCATION_ERR
+};
+
+typedef struct _DEVICE_CONFIGURATION
+{
+	u_int8_t return_code;
+
+	u_int16_t maximum_length_of_rx_queue;
+	u_int16_t maximum_rx_data_length;		//including CRC bytes
+
+	u_int16_t maximum_length_of_tx_queue;
+	u_int16_t maximum_tx_data_length;		//not including CRC bytes
+
+	/* Number of received blocks of data before Receive event is indicated to API caller. */
+	u_int16_t buffer_multiplier_factor;
+}DEVICE_CONFIGURATION, *PDEVICE_CONFIGURATION;
+
+
 /*----------------------------------------------------------------------------
  * WAN interface (logical channel) configuration (for ROUTER_IFNEW IOCTL).
  */
@@ -891,12 +850,12 @@
 	unsigned 	config_id;		/* configuration identifier */
 	char 		name[WAN_IFNAME_SZ+1];	/* interface name, ASCIIZ */
 	char 		addr[WAN_ADDRESS_SZ+1];	/* media address, ASCIIZ */
-	char 		usedby[USED_BY_FIELD];	/* used by API or WANPIPE */
+	char 		usedby[USED_BY_FIELD+1];/* used by API or WANPIPE */
 	unsigned 	idle_timeout;		/* sec, before disconnecting */
 	unsigned 	hold_timeout;		/* sec, before re-connecting */
 	unsigned 	cir;			/* Committed Information Rate fwd,bwd*/
 	unsigned 	bc;			/* Committed Burst Size fwd, bwd */
-	unsigned 	be;			/* Excess Burst Size fwd, bwd */ 
+	unsigned 	be;			/* Excess Burst Size fwd, bwd */
 #ifdef ENABLE_IPV6
 	unsigned char 	enable_IPv4;	/* Enable or Disable IPv4 */
 	unsigned char 	enable_IPv6;	/* Enable or Disable IPv6 */
@@ -909,7 +868,7 @@
 	char 		local_addr[WAN_ADDRESS_SZ+1];/* local media address, ASCIIZ */
         unsigned char 	port;             /* board port */
         unsigned char 	protocol;         /* prococol used in this channel (TCPOX25 or X25) */
-	char 		pap;			/* PAP enabled or disabled */ 
+	char 		pap;			/* PAP enabled or disabled */
 	char 		chap;			/* CHAP enabled or disabled */
 #ifdef ENABLE_IPV6
 	unsigned char 	chap_userid[WAN_AUTHNAMELEN];	/* List of User Id */
@@ -930,12 +889,8 @@
 	unsigned 	keepalive_err_margin;	/* keepalive_error_tolerance */
 	unsigned 	slarp_timer;		/* SLARP request timer */
 	unsigned char 	ttl;			/* Time To Live for UDP security */
-#if defined(__WINDOWS__)
 	/* 'interface' is reserved for C++ compiler!! */
 	char 		electrical_interface;		/* RS-232/V.35, etc. */
-#else
-	char 		interface;		/* RS-232/V.35, etc. */
-#endif
 	char 		clocking;		/* external/internal */
 	unsigned 	bps;			/* data transfer rate */
 	unsigned 	mtu;			/* maximum transmit unit size */
@@ -944,37 +899,38 @@
 	unsigned char 	true_if_encoding; /* Set the dev->type to true board protocol */
 
 	unsigned char 	asy_data_trans;     /* async API options */
-        unsigned char 	rts_hs_for_receive; /* async Protocol options */
-        unsigned char 	xon_xoff_hs_for_receive;
+    unsigned char 	rts_hs_for_receive; /* async Protocol options */
+    unsigned char 	xon_xoff_hs_for_receive;
 	unsigned char 	xon_xoff_hs_for_transmit;
 	unsigned char 	dcd_hs_for_transmit;
 	unsigned char 	cts_hs_for_transmit;
 	unsigned char 	async_mode;
 	unsigned 	tx_bits_per_char;
 	unsigned 	rx_bits_per_char;
-	unsigned 	stop_bits;  
+	unsigned 	stop_bits;
 	unsigned char 	parity;
  	unsigned 	break_timer;
-        unsigned 	inter_char_timer;
+    unsigned 	inter_char_timer;
 	unsigned 	rx_complete_length;
 	unsigned 	xon_char;
 	unsigned 	xoff_char;
 	unsigned char 	receive_only;	/*  no transmit buffering (Y/N) */
-	
+
 	/* x25 media source address, ASCIIZ */
-	unsigned char x25_src_addr[WAN_ADDRESS_SZ+1];	 
+	unsigned char x25_src_addr[WAN_ADDRESS_SZ+1];
 	/* pattern match string in -d<string>
 	 * for accepting calls, ASCIIZ */
-	unsigned char accept_dest_addr[WAN_ADDRESS_SZ+1];   	
-	/* pattern match string in -s<string> 
+	unsigned char accept_dest_addr[WAN_ADDRESS_SZ+1];
+	/* pattern match string in -s<string>
 	 * for accepting calls, ASCIIZ */
-	unsigned char accept_src_addr[WAN_ADDRESS_SZ+1];    
-	/* pattern match string in -u<string> 
+	unsigned char accept_src_addr[WAN_ADDRESS_SZ+1];
+	/* pattern match string in -u<string>
 	 * for accepting calls, ASCIIZ */
 	unsigned char accept_usr_data[WAN_ADDRESS_SZ+1];
-	
+
 	unsigned char inarp_rx;		/* Receive Inverse ARP requests Y/N */
 	unsigned int  active_ch;
+	unsigned int  cfg_active_ch;
 	unsigned int  max_trace_queue;
 	unsigned char sw_dev_name[WAN_IFNAME_SZ+1];
 	unsigned char auto_cfg;
@@ -993,13 +949,12 @@
 	unsigned char single_tx_buf; 	/* Used in low latency applications */
 
 	unsigned char lip_prot;
-#if defined(__WINDOWS__)
+
 	DEVICE_CONFIGURATION device_cfg;
 	unsigned char line_mode[USED_BY_FIELD];
-	struct {
-#else
+	unsigned char interface_number;/* from 0 to 31 */
+
 	union {
-#endif
 		wan_atm_conf_if_t 	atm;  /* per interface configuration */
 		wan_x25_if_conf_t 	x25;
 		wan_lapb_if_conf_t 	lapb;
@@ -1046,7 +1001,7 @@
 
 typedef struct wanpipe_debug_msg_hdr_t {
 	int len;
-	wan_time_t	time;	//unsigned long time;
+	unsigned long time;
 } wanpipe_kernel_msg_hdr_t;
 
 
@@ -1058,34 +1013,30 @@
 	unsigned char	data_avail;
 	unsigned short	real_length;
 	unsigned short	time_stamp;
-	wan_time_t	sec;	//unsigned long	sec;
-	wan_suseconds_t	usec;	//unsigned long   usec;
-#if defined(__WINDOWS__)/* zero-sized array does not comply to ANSI 'C' standard! */
-	unsigned char	data[1];
-#else
+	wan_time_t	sec;		/* unsigned long	sec; */
+	wan_suseconds_t	usec;	/* unsigned long   usec; */
 	unsigned char	data[0];
-#endif
 } wan_trace_pkt_t;
 #pragma pack()
 
-#if defined(__WINDOWS__)
 
-#define ACU_MTU 2048
 #define MODE_OPTION_HDLC		"HDLC"
 #define MODE_OPTION_BITSTRM		"BitStream"
 #define ISDN_BRI_DCHAN			"BRI D-chan"
 
+/* Windows note: this macro is used as input to strcmp() ! */
 #define SDLA_DECODE_USEDBY_FIELD(usedby)			\
-	(usedby == WANPIPE)		? "WANPIPE"	:	\
-	(usedby == API)			? "API"		:	\
-	(usedby == BRIDGE)		? "BRIDGE"	:	\
+	(usedby == WANPIPE)			? "WANPIPE"	:		\
+	(usedby == API)				? "API"		:		\
+	(usedby == BRIDGE)			? "BRIDGE"	:		\
 	(usedby == BRIDGE_NODE)		? "BRIDGE_NODE" :	\
-	(usedby == SWITCH)		? "SWITCH"	:	\
-	(usedby == STACK)		? "STACK"	:	\
-	(usedby == TDM_VOICE_API)	? "TDM VOICE API" :	\
-	(usedby == TDM_VOICE_DCHAN)	? "TDM VOICE DCHAN" :	\
-	(usedby == LIB_SANGOMA_API)	? "LIB SANGOMA API" :	\
-	(usedby == TDM_VOICE_API_V2)	? "TDM VOICE API V2" :	\
+	(usedby == SWITCH)			? "SWITCH"	:		\
+	(usedby == STACK)			? "STACK"	:		\
+	(usedby == TDM_VOICE_API)	? "TDM_VOICE_API" :	\
+	(usedby == TDM_SPAN_VOICE_API)	? "TDM_SPAN_VOICE_API" :	\
+	(usedby == TDM_CHAN_VOICE_API)	? "TDM_CHAN_VOICE_API" :	\
+	(usedby == TDM_VOICE_DCHAN)	? "TDM_VOICE_DCHAN" :	\
+	(usedby == API_LEGACY)	? "API_LEGACY" :	\
 	(usedby == ANNEXG)		? "ANNEXG" :	"Unknown"
 
 #define CARD_WANOPT_DECODE(cardtype)				\
@@ -1099,18 +1050,19 @@
 	(cardtype == WANOPT_AFT_ANALOG) ? "WANOPT_AFT_ANALOG": 		\
 	(cardtype == WANOPT_AFT_56K) ? "WANOPT_AFT_56K": 		\
 	(cardtype == WANOPT_AFT300) ? "WANOPT_AFT300":	\
+	(cardtype == WANOPT_AFT600) ? "WANOPT_AFT600":  \
 	(cardtype == WANOPT_AFT_ISDN) ? "WANOPT_AFT_ISDN": "Invalid card")
 
 
 
 typedef struct _buffer_settings{
 	/* Number of received blocks of data before Receive event is indicated to API caller. */
-	u16 buffer_multiplier_factor;
+	unsigned short buffer_multiplier_factor;
 
 	/* Number of buffers for receiving or transmitting data on an API interface. */
 	/* EACH buffer will contain 'buffer_multiplier_factor' blocks of data before
 	   Receive event is indicated to API caller. */
-	u16 number_of_buffers_per_api_interface;
+	unsigned short number_of_buffers_per_api_interface;
 
 }buffer_settings_t;
 
@@ -1123,12 +1075,16 @@
 /* Structure used with START_PORT_VOLATILE_CONFIG and START_PORT_REGISTRY_CONFIG
    commands. The commands are defined in sang_api.h. */
 typedef struct {
-	unsigned int	command_code;		// Configuration Command Code
-	unsigned int	operation_status;	// operation completion status 
+	unsigned int	command_code;		/* Configuration Command Code */
+	unsigned int	operation_status;	/* operation completion status*/
+	unsigned short	port_no;			/* Port No */
 
 	/* Port configuration such T1 or E1... */
 	wandev_conf_t wandev_conf;
 
+	/* Number of interfaces in if_cfg array */
+	unsigned int	num_of_ifs;
+
 	/* Per-Interface configuration.
 	   For AFT card maximum NUM_OF_E1_CHANNELS (32) logic channels.
 	   Configuration of each logic channel ('active_ch', HDLC or Transparent...) */
@@ -1136,18 +1092,20 @@
 
 	buffer_settings_t buffer_settings;
 
-}port_cfg_t;
+}wanpipe_port_cfg_t;
 
+#define port_cfg_t wanpipe_port_cfg_t
 
+/* normal driver operation */
 #define DRV_MODE_NORMAL	0
+/* driver will run in 'AFT firmware update' mode */
 #define DRV_MODE_AFTUP	1
 
 /* cpecial id - when driver installed, it is "not configured".
-user has to select the protocol.*/
+user should select a protocol.*/
 #define WANCONFIG_NONE			10
 /* special id - for AFT firmware update */
-#define WANCONFIG_AFT_FIRMWARE_UPDATE	11
+/*#define WANCONFIG_AFT_FIRMWARE_UPDATE	11*/
 
-#endif/* __WINDOWS__) */
 
 #endif
diff -dur include/wanpipe_cfg_sppp.h /usr/include/wanpipe/wanpipe_cfg_sppp.h
--- include/wanpipe_cfg_sppp.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_cfg_sppp.h	2009-07-14 13:02:00.000000000 -0400
@@ -46,6 +46,7 @@
 #else
 	unsigned int keepalive_err_margin;
 #endif
+
 	unsigned char disable_magic;
 }wan_sppp_if_conf_t;
 
diff -dur include/wanpipe_codec.h /usr/include/wanpipe/wanpipe_codec.h
--- include/wanpipe_codec.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_codec.h	2009-07-14 13:02:00.000000000 -0400
@@ -22,14 +22,7 @@
 #define __WANPIPE_CODEC_H_
 
 
-
-#if (defined __FreeBSD__) | (defined __OpenBSD__)
-#include <wanpipe_codec_iface.h>
-#elif defined(__WINDOWS__)
-#include <wanpipe_codec_iface.h>
-#else
-#include <linux/wanpipe_codec_iface.h>
-#endif
+#include "wanpipe_codec_iface.h"
 
 
 #ifdef CONFIG_PRODUCT_WANPIPE_CODEC_SLINEAR_LAW
diff -dur include/wanpipe_common.h /usr/include/wanpipe/wanpipe_common.h
--- include/wanpipe_common.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_common.h	2009-07-14 13:02:00.000000000 -0400
@@ -21,15 +21,45 @@
 #ifndef	__WANPIPE_COMMON_H
 # define __WANPIPE_COMMON_H
 
-#if defined(__LINUX__)
-# include <linux/wanpipe_kernel.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_kernel.h>
-# include <wanpipe_skb.h>
-# include <sang_status_defines.h>
-#else
-# include <wanpipe_kernel.h>
+#if defined(WAN_KERNEL)
+# include "wanpipe_kernel.h"
 #endif
+# include "wanpipe_cfg_def.h"
+
+#if defined(__WINDOWS__)
+# if defined(WAN_KERNEL)
+#  include "wanpipe_skb.h"
+VOID
+free_dma_buffer(
+	IN	PDMA_ADAPTER	DmaAdapterObject,
+	IN	u32				DmaBufferLength,
+	IN	PVOID			virtual_addr,
+	IN	u32				physical_addr
+	);
+int
+allocate_dma_buffer(
+	IN	PDMA_ADAPTER	DmaAdapterObject,
+	IN	u32				DmaBufferLength,
+	OUT PVOID			*virtual_addr,
+	OUT u32				*physical_addr
+	);
+# endif/* WAN_KERNEL */
+# include <sang_status_defines.h>
+
+# if defined(WAN_KERNEL) && defined(NTSTRSAFE_USE_SECURE_CRT)
+#  define wan_snwprintf	RtlStringCbPrintfW
+#  define wan_strcpy	RtlStringCchCopy
+# else
+#  define wan_snwprintf	_snwprintf
+# endif
+
+# define strlcpy		strncpy
+# define strncasecmp	_strnicmp
+# define strcasecmp		_stricmp
+# define snprintf		_snprintf
+# define vsnprintf		_vsnprintf
+# define unlink			_unlink
+#endif/* __WINDOWS__ */
 
 /****************************************************************************
 **			D E F I N E S				
@@ -169,6 +199,8 @@
 	*(elm)->field.le_prev = WAN_LIST_NEXT((elm), field);		\
 } while (0)
 
+#define GFP_KERNEL 0
+
 #else
 # error "WAN_LISTx macros not supported yet!"
 #endif
@@ -217,6 +249,16 @@
 #  define WAN_NETIF_CARRIER_ON(dev)	
 #  define WAN_NETIF_CARRIER_OK(dev)	1	
 # else
+#if 0
+#  define WAN_NETIF_WAKE_QUEUE(dev)	do{ 				\
+					if (((wanpipe_common_t *)dev->priv)->usedby == TDM_VOICE){ \
+						DEBUG_EVENT("%s: TDM VOICE not waking but starting!!!!\n",dev->name); \
+						netif_start_queue(dev);			\
+					}else{						\
+						netif_wake_queue(dev);			\
+					}						\
+					}while(0)
+#endif
 #  define WAN_NETIF_WAKE_QUEUE(dev)	netif_wake_queue(dev);
 #  define WAN_NETIF_START_QUEUE(dev)	netif_start_queue(dev)
 #  define WAN_NETIF_STOP_QUEUE(dev)	netif_stop_queue(dev)
@@ -255,14 +297,23 @@
 
 #elif defined(__WINDOWS__)
 # define WAN_NET_RATELIMIT()		1
-# define WAN_NETIF_QUEUE_STOPPED(dev)	test_bit(0,&dev->tbusy)
-# define WAN_NETIF_UP(dev)		((dev)->flags&IFF_UP)
+
+# define WAN_NETIF_QUEUE_STOPPED(dev)	1 /*test_bit(0,&dev->tbusy)*/ /* must be always stopped so aft_core.c would call wanpipe_wake_stack() */
+# define WAN_NETIF_STOP_QUEUE(dev)	
+# define WAN_NETIF_START_QUEUE(dev)	
+
+//# define WAN_NETIF_QUEUE_STOPPED(dev)	test_bit(0,&dev->tbusy)
+//# define WAN_NETIF_STOP_QUEUE(dev)	set_bit(0, &dev->tbusy)
+//# define WAN_NETIF_START_QUEUE(dev)	dev->tbusy = 0;
+
 # define WAN_NETIF_WAKE_QUEUE(dev)	netif_wake_queue(dev)
-# define WAN_NETIF_START_QUEUE(dev)	netif_wake_queue(dev)
-# define WAN_NETIF_CARRIER_OFF(dev)	FUNC_NOT_IMPL
-# define WAN_NETIF_STOP_QUEUE(dev)	FUNC_NOT_IMPL
-# define WAN_IFQ_LEN(ifqueue)		skb_queue_len(ifqueue)
 
+# define WAN_NETIF_UP(dev)		((dev)->current_line_state == SANG_STATUS_LINE_CONNECTED)
+# define WAN_NETIF_CARRIER_OFF(dev)	if(0)DbgPrint("WAN_NETIF_CARRIER_OFF()\n")
+# define WAN_NETIF_CARRIER_ON(dev)	if(0)DbgPrint("WAN_NETIF_CARRIER_ON()\n")
+
+# define WAN_IFQ_LEN(ifqueue)		skb_queue_len(ifqueue)
+# define NET_ADMIN_CHECK()
 # define WARN_ON(a)
 
 #else
@@ -270,7 +321,7 @@
 #endif
 
 /* Update Network Interface statistics */
-#if defined(__LINUX__)
+#if defined(__LINUX__) || defined(__WINDOWS__)
 
 # define WAN_NETIF_STATS_INC_RX_PACKETS(common)		(common)->if_stats.rx_packets++
 # define WAN_NETIF_STATS_INC_TX_PACKETS(common)		(common)->if_stats.tx_packets++
@@ -286,19 +337,19 @@
 # define WAN_NETIF_STATS_INC_MULTICAST(common)		(common)->if_stats.multicast++
 # define WAN_NETIF_STATS_INC_COLLISIONS(common)		(common)->if_stats.collisions++
 # define WAN_NETIF_STATS_INC_RX_LENGTH_ERRORS(common)	(common)->if_stats.rx_length_errors++
-# define WAN_NETIF_STATS_INC_RX_OVER_ERRORS(common)		(common)->if_stats.rx_over_errors++
-# define WAN_NETIF_STATS_INC_RX_CRC_ERRORS(common)		(common)->if_stats.rx_crc_errors++
+# define WAN_NETIF_STATS_INC_RX_OVER_ERRORS(common)	(common)->if_stats.rx_over_errors++
+# define WAN_NETIF_STATS_INC_RX_CRC_ERRORS(common)	(common)->if_stats.rx_crc_errors++
 # define WAN_NETIF_STATS_INC_RX_FRAME_ERRORS(common)	(common)->if_stats.rx_frame_errors++
-# define WAN_NETIF_STATS_INC_RX_FIFO_ERRORS(common)		(common)->if_stats.rx_fifo_errors++
+# define WAN_NETIF_STATS_INC_RX_FIFO_ERRORS(common)	(common)->if_stats.rx_fifo_errors++
 # define WAN_NETIF_STATS_INC_RX_MISSED_ERRORS(common)	(common)->if_stats.rx_missed_errors++
 # define WAN_NETIF_STATS_INC_TX_ABORTED_ERRORS(common)	(common)->if_stats.tx_aborted_errors++
 # define WAN_NETIF_STATS_INC_TX_CARRIER_ERRORS(common)	(common)->if_stats.tx_carrier_errors++
 # define WAN_NETIF_STATS_TX_CARRIER_ERRORS(common)	(common)->if_stats.tx_carrier_errors
-# define WAN_NETIF_STATS_INC_TX_FIFO_ERRORS(common)		(common)->if_stats.tx_fifo_errors++
-# define WAN_NETIF_STATS_INC_TX_HEARTBEAT_ERRORS(common)	(common)->if_stats.tx_heartbeat_errors++
+# define WAN_NETIF_STATS_INC_TX_FIFO_ERRORS(common)	(common)->if_stats.tx_fifo_errors++
+# define WAN_NETIF_STATS_INC_TX_HEARTBEAT_ERRORS(common) (common)->if_stats.tx_heartbeat_errors++
 # define WAN_NETIF_STATS_INC_TX_WINDOW_ERRORS(common)	(common)->if_stats.tx_window_errors++
-# define WAN_NETIF_STATS_INC_RX_COMPRESSED(common)		(common)->if_stats.rx_compressed++
-# define WAN_NETIF_STATS_INC_TX_COMPRESSED(common)		(common)->if_stats.tx_compressed++
+# define WAN_NETIF_STATS_INC_RX_COMPRESSED(common)	(common)->if_stats.rx_compressed++
+# define WAN_NETIF_STATS_INC_TX_COMPRESSED(common)	(common)->if_stats.tx_compressed++
 
 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
 
@@ -330,36 +381,6 @@
 # define WAN_NETIF_STATS_INC_RX_COMPRESSED(common)	
 # define WAN_NETIF_STATS_INC_TX_COMPRESSED(common)
 
-#elif defined(__WINDOWS__)
-
-# define WAN_NETIF_STATS_INC_RX_PACKETS(common)		(common)->if_stats.rx_packets++
-# define WAN_NETIF_STATS_INC_TX_PACKETS(common)		(common)->if_stats.tx_packets++
-# define WAN_NETIF_STATS_RX_PACKETS(common)		((common)->if_stats.rx_packets)
-# define WAN_NETIF_STATS_TX_PACKETS(common)		((common)->if_stats.tx_packets)
-# define WAN_NETIF_STATS_INC_RX_BYTES(common,len)	(common)->if_stats.rx_bytes+=(len)
-# define WAN_NETIF_STATS_INC_TX_BYTES(common,len)	(common)->if_stats.tx_bytes+=(len)
-# define WAN_NETIF_STATS_INC_RX_ERRORS(common)		(common)->if_stats.rx_errors++
-# define WAN_NETIF_STATS_INC_TX_ERRORS(common)		(common)->if_stats.tx_errors++
-# define WAN_NETIF_STATS_INC_RX_DROPPED(common)		(common)->if_stats.rx_dropped++
-# define WAN_NETIF_STATS_RX_DROPPED(common)		(common)->if_stats.rx_dropped
-# define WAN_NETIF_STATS_INC_TX_DROPPED(common)		(common)->if_stats.tx_dropped++
-# define WAN_NETIF_STATS_INC_MULTICAST(common)		(common)->if_stats.multicast++
-# define WAN_NETIF_STATS_INC_COLLISIONS(common)		(common)->if_stats.collisions++
-# define WAN_NETIF_STATS_INC_RX_LENGTH_ERRORS(common)	(common)->if_stats.rx_length_errors++
-# define WAN_NETIF_STATS_INC_RX_OVER_ERRORS(common)	(common)->if_stats.rx_over_errors++
-# define WAN_NETIF_STATS_INC_RX_CRC_ERRORS(common)	(common)->if_stats.rx_crc_errors++
-# define WAN_NETIF_STATS_INC_RX_FRAME_ERRORS(common)	(common)->if_stats.rx_frame_errors++
-# define WAN_NETIF_STATS_INC_RX_FIFO_ERRORS(common)	(common)->if_stats.rx_fifo_errors++
-# define WAN_NETIF_STATS_INC_RX_MISSED_ERRORS(common)	(common)->if_stats.rx_missed_errors++
-# define WAN_NETIF_STATS_INC_TX_ABORTED_ERRORS(common)	(common)->if_stats.tx_aborted_errors++
-# define WAN_NETIF_STATS_INC_TX_CARRIER_ERRORS(common)	(common)->if_stats.tx_carrier_errors++
-# define WAN_NETIF_STATS_TX_CARRIER_ERRORS(common)	(common)->if_stats.tx_carrier_errors
-# define WAN_NETIF_STATS_INC_TX_FIFO_ERRORS(common)	(common)->if_stats.tx_fifo_errors++
-# define WAN_NETIF_STATS_INC_TX_HEARTBEAT_ERRORS(common) (common)->if_stats.tx_heartbeat_errors++
-# define WAN_NETIF_STATS_INC_TX_WINDOW_ERRORS(common)	(common)->if_stats.tx_window_errors++
-# define WAN_NETIF_STATS_INC_RX_COMPRESSED(common)	(common)->if_stats.rx_compressed++
-# define WAN_NETIF_STATS_INC_TX_COMPRESSED(common)	(common)->if_stats.tx_compressed++
-
 #else
 
 # error "Undefined WAN_NETIF_STATSx macro!"
@@ -490,11 +511,7 @@
 /* String library definitions */
 #if defined(__LINUX__)
 # define strncasecmp	strnicmp
-#elif defined(__WINDOWS__)
-# define strlcpy	strncpy
-# define strncasecmp	_strnicmp
-# define snprintf	_snprintf
-# define vsnprintf	_vsnprintf
+# define _snprintf		snprintf
 #endif
 
 /****************************************************************************
@@ -560,7 +577,7 @@
 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 void		wanpipe_debugging (void* data, int pending);
 #else
-void		wanpipe_debugging (unsigned long data);
+void		wanpipe_debugging (ulong_ptr_t data);
 #endif
 
 
@@ -606,7 +623,7 @@
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	ptr = malloc(size, M_DEVBUF, M_NOWAIT); 
 #elif defined(__WINDOWS__)
-	ptr = kmalloc(size);
+	ptr = kmalloc(size, '1lmk'/* memory pool tag */);
 #else
 # error "wan_malloc() function is not supported yet!"
 #endif
@@ -634,7 +651,7 @@
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	ptr = malloc(size, M_DEVBUF, M_NOWAIT); 
 #elif defined(__WINDOWS__)
-	ptr = kmalloc(size);
+	ptr = kmalloc(size, '2lmk'/* memory pool tag */);
 #else
 # error "wan_malloc() function is not supported yet!"
 #endif
@@ -663,7 +680,9 @@
 	}
 	
 #ifdef WAN_DEBUG_MEM
-	sdla_memdbg_pull(ptr, func_name, line);
+	if (sdla_memdbg_pull(ptr, func_name, line) != 0) {
+		DEBUG_EVENT("%s: %d: %s Invalid Free\n",func_name,line,__FUNCTION__);
+	}
 #endif
 
 #if defined(__LINUX__)
@@ -708,8 +727,9 @@
 		ptr = ptr1++;
 	}
 #elif defined(__SOLARIS__)
-#elif defined(__WINDOWS__)
 	ptr = kmalloc(size);
+#elif defined(__WINDOWS__)
+	ptr = kmalloc(size, '3lmk'/* memory pool tag */);
 #else
 # error "wan_vmalloc() function is not supported yet!"
 #endif
@@ -741,7 +761,9 @@
 	}
 
 #ifdef WAN_DEBUG_MEM
-	sdla_memdbg_pull(ptr, func_name, line);
+	if (sdla_memdbg_pull(ptr, func_name, line) != 0) {
+		DEBUG_EVENT("%s: %d: %s Invalid Free\n",func_name,line,__FUNCTION__);
+	}
 #endif
 
 #if defined(__LINUX__)
@@ -781,7 +803,7 @@
 #elif defined(__OpenBSD__) || defined(__NetBSD__)
 	return vtophys((vaddr_t)ptr);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 	return 0;
 #else
 # error "wan_virt2bus() function is not supported yet!"
@@ -798,7 +820,7 @@
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	return (unsigned long*)virt_addr;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 	return 0;
 #else
 # error "wan_bus2virt() function is not supported yet!"
@@ -887,8 +909,20 @@
 		err = -ENOMEM;
 	}
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
-	return -EINVAL;
+	{
+		PVOID	virtual_addr;
+		u32		physical_addr;
+
+		if(allocate_dma_buffer(	dma_descr->DmaAdapterObject, 
+								dma_descr->max_length,
+								&virtual_addr, 
+								&physical_addr)){
+			DEBUG_EVENT("%s(): Error: failed to allocate DMA memory!\n", __FUNCTION__);
+			return -ENOMEM;
+		}
+		dma_descr->vAddr = virtual_addr;
+		dma_descr->pAddr = physical_addr;
+	}
 #else
 # error "wan_dma_alloc() function is not supported yet!"
 #endif
@@ -918,8 +952,10 @@
 	dma_descr->vAddr = NULL;
 	dma_descr->pAddr = 0;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
-	return -EINVAL;
+	free_dma_buffer(dma_descr->DmaAdapterObject, dma_descr->max_length,
+					dma_descr->vAddr, dma_descr->pAddr);
+	dma_descr->vAddr = NULL;
+	dma_descr->pAddr = 0;
 #else
 # error "wan_dma_free() function is not supported yet!"
 #endif
@@ -933,7 +969,11 @@
 
 static __inline unsigned long wan_dma_get_paddr(void* card, wan_dma_descr_org_t* dma)
 {
+#if defined(__WINDOWS__)
+	return dma->pAddr;
+#else
 	return wan_virt2bus(dma->vAddr);
+#endif
 }
 
 
@@ -1069,6 +1109,7 @@
 			wan_timer->timer_func,
 			wan_timer->timer_arg); 
 #elif defined(__WINDOWS__)
+#if 0
 	LARGE_INTEGER	large_int_delay;
 
 	if(0)DEBUG_TIMER("%s(): delay: %u\n", __FUNCTION__, delay);
@@ -1081,6 +1122,24 @@
 
 	KeSetTimer(&wan_timer->timer_info.Timer, large_int_delay,
 		&wan_timer->timer_info.TimerDpcObject);
+#endif
+	LARGE_INTEGER	CurrentTime;
+
+	if(1)DBG_ADSL_SYNCH("%s(): delay: %u\n", __FUNCTION__, delay);
+
+	/* The 'delay' is in SYSTEM TICKS! */
+
+
+	/* 10 000 000
+	 * System time is a count of 100-nanosecond intervals
+	 * since January 1, 1601. System time is typically
+	 * updated approximately every ten milliseconds. (on Intel 32bit) */
+	KeQuerySystemTime(&CurrentTime);
+
+	CurrentTime.QuadPart = CurrentTime.QuadPart + delay * KeQueryTimeIncrement();
+
+	KeSetTimer(&wan_timer->timer_info.Timer, CurrentTime, &wan_timer->timer_info.TimerDpcObject);
+
 #else
 # error "wan_add_timer() function is not supported yet!"
 #endif /* linux */
@@ -1188,7 +1247,9 @@
 {
 
 #if defined(WAN_DEBUG_MEM)
-	sdla_memdbg_pull(skb, func_name, line);
+	if (sdla_memdbg_pull(skb, func_name, line) != 0) {
+		DEBUG_EVENT("%s: %d: %s Invalid Free\n",func_name,line,__FUNCTION__);
+	}
 #endif
 
 #if defined(__LINUX__)
@@ -1257,22 +1318,23 @@
 static __inline void* wan_skb_alloc(unsigned int len)
 #endif
 {
-#if defined(__LINUX__)
-#if defined(WAN_DEBUG_MEM)
-	struct sk_buff *skb=dev_alloc_skb(len);
+#if defined(__LINUX__) || defined(__WINDOWS__)
+
+	struct sk_buff *skb=dev_alloc_skb(len+64);
 	if (skb){
+		skb_reserve(skb,64);
+#if defined(WAN_DEBUG_MEM)
 		sdla_memdbg_push(skb, func_name,line,skb->truesize);
+#endif
 	}
 	return (void*)skb;
-#else
-	return (void*)dev_alloc_skb(len);
-#endif
+
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	struct mbuf	*nm = NULL;
 
 	nm = m_getcl(M_DONTWAIT,MT_DATA,M_PKTHDR);
 	if (nm != NULL){
-		nm->m_data += 16;
+		nm->m_data += 64;
 		wan_skb_set_mark(nm);
 # if defined(WAN_DEBUG_MEM)
 		sdla_memdbg_push(nm, func_name,line,sizeof(struct mbuf));
@@ -1280,14 +1342,12 @@
 	}
 	return nm;
 #elif defined (__SOLARIS__)
-	mblk_t *mp=allocb(ROUNDUP(len+16, IOC_LINESIZE), BPRI_MED);
+	mblk_t *mp=allocb(ROUNDUP(len+64, IOC_LINESIZE), BPRI_MED);
 	if (mp){
 		caddr_t ptr= (caddr_t) ROUNDUP((long)mp->b_rptr, 1);
-		mp->b_rptr=(uchar_t *)ptr+16;
+		mp->b_rptr=(uchar_t *)ptr+64;
 	}
 	return mp;
-#elif defined(__WINDOWS__)
-	return (void*)dev_alloc_skb(len);
 #else
 # error "wan_skb_alloc() function is not supported yet!"
 #endif
@@ -1301,22 +1361,22 @@
 static __inline void* wan_skb_kalloc(unsigned int len)
 #endif
 {
-#if defined(__LINUX__)
-#if defined(WAN_DEBUG_MEM)
-	struct sk_buff *skb=__dev_alloc_skb(len,GFP_KERNEL);
+#if defined(__LINUX__) || defined(__WINDOWS__)
+	struct sk_buff *skb=__dev_alloc_skb(len+64,GFP_KERNEL);
 	if (skb){
+		skb_reserve(skb,64);
+#if defined(WAN_DEBUG_MEM)
 		sdla_memdbg_push(skb, func_name,line,skb->truesize);
+#endif
 	}
 	return (void*)skb;
-#else
-	return (void*)__dev_alloc_skb(len,GFP_KERNEL);
-#endif
+
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	struct mbuf	*nm = NULL;
 
 	nm = m_getcl(M_DONTWAIT,MT_DATA,M_PKTHDR);
 	if (nm != NULL){
-		nm->m_data += 16;
+		nm->m_data += 64;
 		wan_skb_set_mark(nm);
 # if defined(WAN_DEBUG_MEM)
 		sdla_memdbg_push(nm, func_name,line,sizeof(struct mbuf));
@@ -1324,14 +1384,12 @@
 	}
 	return nm;
 #elif defined (__SOLARIS__)
-	mblk_t *mp=allocb(ROUNDUP(len+16, IOC_LINESIZE), BPRI_MED);
+	mblk_t *mp=allocb(ROUNDUP(len+64, IOC_LINESIZE), BPRI_MED);
 	if (mp){
 		caddr_t ptr= (caddr_t) ROUNDUP((long)mp->b_rptr, 1);
-		mp->b_rptr=(uchar_t *)ptr+16;
+		mp->b_rptr=(uchar_t *)ptr+64;
 	}
 	return mp;
-#elif defined(__WINDOWS__)
-	return (void*)dev_alloc_skb(len);
 #else
 # error "wan_skb_kalloc() function is not supported yet!"
 #endif
@@ -1397,7 +1455,7 @@
 #elif defined(__WINDOWS__)
 	struct sk_buff *skb = (struct sk_buff*)pskb;
 	/* skb->mac.raw = skb->data; */
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # warning "wan_skb_set_raw() function is not supported yet!"
 #endif
@@ -1412,7 +1470,7 @@
 	}
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # warning "wan_skb_reset_mac_hdr() function is not supported yet!"
 #endif
@@ -1427,7 +1485,7 @@
 	}
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # warning "wan_skb_reset_network_hdr() function is not supported yet!"
 #endif
@@ -1461,7 +1519,9 @@
 	}
 #elif defined(__WINDOWS__)
 	struct sk_buff *sk = (struct sk_buff*)skb;
-	sk->csum = csum;
+	if (sk){
+		sk->csum = csum;
+	}
 #else
 # error "wan_skb_set_csum() function is not supported yet!"
 #endif
@@ -1489,7 +1549,7 @@
 # endif
 #elif defined(__WINDOWS__)
 	struct sk_buff *sk = (struct sk_buff*)skb;
-	return sk->csum;
+	return (sk) ? sk->csum : 0;
 #else
 # error "wan_skb_csum() function is not supported yet!"
 #endif
@@ -1548,7 +1608,7 @@
 	struct sk_buff* sk = (struct sk_buff*)skb;
 	unsigned char* data = NULL;
 	if (off == wan_skb_len(skb)){
-		if (__wan_skb_tail_pointer(sk) + len > __wan_skb_end_pointer(sk)){	
+		if (sk->tail + len > sk->end){	
 			DEBUG_EVENT(
 			"%s:%d: Internal Error (off=%d,len=%d,skb_len=%d)!\n",
 				__FUNCTION__,__LINE__,
@@ -1670,7 +1730,7 @@
 	m->m_len 	= off + len;
 	m->m_pkthdr.len = off + len;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # error "wan_skb_copyback_user() function is not supported yet!"
 #endif
@@ -2011,7 +2071,6 @@
 	struct sk_buff* skb = (struct sk_buff*)pskb;
 	skb->data = skb->head + len;
 	skb->tail = skb->data;
-	skb->len  = 0;
 	skb->data_len = 0;   
 #else
 # error "wan_skb_init() function is not supported yet!"
@@ -2083,7 +2142,6 @@
 # endif
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
 #else
 # error "wan_skb_unlink() function is not supported yet!"
 #endif
@@ -2114,15 +2172,13 @@
 
 static __inline void wan_skb_queue_purge(void *list)
 {
-#if defined(__LINUX__)
+#if defined(__LINUX__) || defined(__WINDOWS__)
 	struct sk_buff *skb;
 	while ((skb=skb_dequeue(list))!=NULL){
 		wan_skb_free(skb);
 	}
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	WAN_IFQ_PURGE(((wan_skb_queue_t*)list));
-#elif defined(__WINDOWS__)
-	skb_queue_purge(list);
 #else
 # error "wan_skb_queue_purge() function is not supported yet!"
 #endif
@@ -2246,7 +2302,7 @@
 # endif
 	WAN_IFQ_SET_MAXLEN(&dev->if_snd, ifqmaxlen);
 #elif defined(__OpenBSD__) || defined(__NetBSD__)
-	if (strlen(ifname) >= IFNAMSIZ){
+	if (strlen(ifname) >= WAN_IFNAME_SZ){
 		return -ENOMEM;
 	}
     	bcopy(ifname, dev->if_xname, strlen(ifname));
@@ -2258,7 +2314,7 @@
 	strcpy(dev->name, ifname);
 # endif
 #elif defined(__WINDOWS__)
-	strncpy(dev->name, ifname, IFNAMSIZ);
+	strncpy(dev->name, ifname, WAN_IFNAME_SZ);
 #else
 # error "wan_netif_init() function is not supported yet!"
 #endif
@@ -2402,7 +2458,7 @@
 	}
 	memset(dev, 0, sizeof(netdevice_t));
 	
-	strncpy(dev->name,devname,IFNAMSIZ);
+	strncpy(dev->name,devname,WAN_IFNAME_SZ);
 	return dev;	
 #else
 # error "wan_netif_alloc() unsupported"
@@ -2439,7 +2495,7 @@
 	
 static __inline char* wan_netif_name(netdevice_t* dev)
 {
-	static char ifname[IFNAMSIZ+1];
+	static char ifname[WAN_IFNAME_SZ+1];
 	WAN_ASSERT2(dev == NULL, NULL);
 #if defined(__LINUX__)
 	strcpy(ifname, dev->name);
@@ -2463,11 +2519,7 @@
 {
 	WAN_ASSERT2(dev == NULL, NULL);
 #if defined(__LINUX__)
-#  if  (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
 	return dev->priv;
-#  else
-	return dev->ml_priv;
-#  endif
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	return dev->if_softc;
 #elif defined(__WINDOWS__)
@@ -2485,7 +2537,7 @@
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	return WAN_NETIF_UP(dev);
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # error "wan_netif_up() function is not supported yet!"
 #endif
@@ -2496,11 +2548,7 @@
 {
 	WAN_ASSERT1(dev == NULL);
 #if defined(__LINUX__)
-#  if  (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
 	dev->priv = priv;
-#  else
-	dev->ml_priv = priv;
-#  endif
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	dev->if_softc = priv;
 #elif defined(__WINDOWS__)
@@ -2519,7 +2567,7 @@
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	return dev->if_flags;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # error "wan_netif_flags() function is not supported yet!"
 #endif
@@ -2534,7 +2582,7 @@
 #elif defined(__OpenBSD__) || defined(__NetBSD__)
 	return 0;
 #elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # error "wan_netif_mcount() function is not supported yet!"
 #endif
@@ -2542,11 +2590,9 @@
 
 static __inline int wan_netif_set_ticks(netdevice_t* dev, unsigned long ticks)
 {
-#if defined(__LINUX__)
+#if defined(__LINUX__) || defined(__WINDOWS__)
 	dev->trans_start = ticks;
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-#elif defined(__WINDOWS__)
-	dev->trans_start = ticks;
 #else
 # error "wan_netif_set_ticks() function is not supported yet!"
 #endif
@@ -2555,18 +2601,15 @@
 
 static __inline int wan_netif_set_mtu(netdevice_t* dev, unsigned long mtu)
 {
-#if defined(__LINUX__)
+#if defined(__LINUX__) || defined(__WINDOWS__)
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	dev->if_mtu = mtu;
-#elif defined(__WINDOWS__)
-	FUNC_NOT_IMPL
 #else
 # error "wan_netif_set_mtu() function is not supported yet!"
 #endif
 	return 0;
 }
 
-
 static __inline void
 wan_bpf_report(netdevice_t* dev, void* pkt, int flag, int dir)
 {
@@ -2592,7 +2635,7 @@
 	}
 #elif defined(__WINDOWS__)
 	/* Do nothing */
-	FUNC_NOT_IMPL
+	FUNC_NOT_IMPL();
 #else
 # error "wan_bpf_report() function is not supported yet!"
 #endif
@@ -2685,11 +2728,12 @@
 	*flag = splimp();
 # endif
 #elif defined(__WINDOWS__)
-	spin_lock_irqsave((wan_spinlock_t*)lock);
+	spin_lock_irqsave((wan_spinlock_t*)lock, flag/* irql before lock */);
 #else
 # warning "wan_spin_lock_irq() function is not supported yet!"
 #endif	
 }
+
 static __inline void wan_spin_unlock_irq(void *lock, wan_smp_flag_t *flag)
 {
 #if defined(__LINUX__)
@@ -2708,13 +2752,13 @@
 #elif defined(__OpenBSD__) || defined(__NetBSD__)
 	splx(*flag);
 #elif defined(__WINDOWS__)
-	spin_unlock_irqrestore((wan_spinlock_t*)lock);
+	spin_unlock_irqrestore((wan_spinlock_t*)lock, flag/* irql to be restored */);
 #else
 # warning "wan_spin_unlock_irq() function is not supported yet!"
 #endif	
 }
 
-static __inline int wan_spin_trylock(void *lock)
+static __inline int wan_spin_trylock(void *lock, wan_smp_flag_t *flag)
 {
 #if defined(__LINUX__)
 	return spin_trylock(((spinlock_t*)lock));	
@@ -2725,14 +2769,14 @@
 #elif defined(__NetBSD__)
 	#warning "FIXME: Complete this code.!!!!!!!!!!!"
 #elif defined(__WINDOWS__)
-	return spin_trylock((wan_spinlock_t*)lock);
+	return spin_trylock((wan_spinlock_t*)lock, flag);
 #else
 # warning "wan_spin_trylock() function is not supported yet!"
 #endif	
 	return 0;
 }
 
-static __inline void wan_spin_lock(void *lock)
+static __inline void wan_spin_lock(void *lock, wan_smp_flag_t *flag)
 {
 #if defined(__LINUX__)
 	spin_lock(((spinlock_t*)lock));	
@@ -2758,12 +2802,12 @@
 	*((wan_spinlock_t*)lock) = splimp();
 # endif
 #elif defined(__WINDOWS__)
-	spin_lock((wan_spinlock_t*)lock);	
+	spin_lock((wan_spinlock_t*)lock, flag);	
 #else
 # warning "wan_spin_lock() function is not supported yet!"
 #endif	
 }
-static __inline void wan_spin_unlock(void *lock)
+static __inline void wan_spin_unlock(void *lock,  wan_smp_flag_t *flag)
 {
 #if defined(__LINUX__)
 	spin_unlock(((spinlock_t*)lock));	
@@ -2781,7 +2825,7 @@
 #elif defined(__OpenBSD__) || defined(__NetBSD__)
 	splx(*(wan_spinlock_t*)lock);
 #elif defined(__WINDOWS__)
-	spin_unlock((wan_spinlock_t*)lock);	
+	spin_unlock((wan_spinlock_t*)lock, flag);	
 #else
 # warning "wan_spin_unlock() function is not supported yet!"
 #endif	
@@ -2849,44 +2893,12 @@
 
 #if defined(__WINDOWS__)
 
-# define WAN_SPIN_LOCK_INIT(pSpinLock)		\
-{											\
-	int rc=1;								\
-	VERIFY_PASSIVE_IRQL(rc);				\
-	if(rc == 0){							\
-		KeInitializeSpinLock(pSpinLock);	\
-	}										\
-}
-
-///////////////////////////////////////////////////////
-//for use at IRQL <= DISPATCH_LEVEL
-# define WAN_SPIN_LOCK(pSpinLock)		\
-{												\
-	int rc=SILENT;								\
-	VERIFY_DISPATCH_IRQL(rc);					\
-	if(rc == 0){								\
-		KeAcquireSpinLock(pSpinLock, &old_IRQL);\
-	}											\
-}
-
-# define WAN_SPIN_UNLOCK(pSpinLock)	\
-	KeReleaseSpinLock(pSpinLock, old_IRQL);
-
-//for use at IRQL == DISPATCH_LEVEL - more efficient
-//when known to run in DPC
-# define WAN_SPIN_LOCK_DPC(pSpinLock)			\
-{												\
-	int rc=1;									\
-	if(0)DBG_IRQLOCK("WAN_SPIN_LOCK_DPC: caller: %s\n",__FUNCTION__);	\
-												\
-	VERIFY_IRQL_EQUAL_DISPATCH(rc);				\
-	if(rc == 0){								\
-		KeAcquireSpinLockAtDpcLevel(pSpinLock);	\
-	}											\
-}
+#define WAN_IFQ_INIT(ifq, max_pkt)			wan_skb_queue_init((ifq))
+#define WAN_IFQ_DESTROY(ifq)
+#define WAN_IFQ_PURGE(ifq)					wan_skb_queue_purge((ifq))
+#define WAN_IFQ_DMA_PURGE(ifq)				wan_skb_queue_purge(ifq)
+#define WAN_IFQ_ENQUEUE(ifq, skb, arg, err)	wan_skb_queue_tail((ifq), (skb))
 
-# define WAN_SPIN_UNLOCK_DPC(pSpinLock)	\
-	KeReleaseSpinLockFromDpcLevel(pSpinLock);
 #endif
 
 #endif  /* WAN_KERNEL */
diff -dur include/wanpipe_debug.h /usr/include/wanpipe/wanpipe_debug.h
--- include/wanpipe_debug.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_debug.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,12 +1,12 @@
 /*
  ************************************************************************
- * wanpipe_debug.h	WANPIPE(tm) 	Global definition for Sangoma 	*
- *					Debugging messages		*
- *									*
- * Author:		Alex Feldman <al.feldman@sangoma.com>		*
+ * wanpipe_debug.h	WANPIPE(tm) 	Global definition for Sangoma 		*
+ *					Debugging messages									*
+ *																		*
+ * Author:		Alex Feldman <al.feldman@sangoma.com>					*
  *======================================================================*
- *	May 10 2002		Alex Feldman	Initial version		*
- *									*
+ *	May 10 2002		Alex Feldman	Initial version						*
+ *																		*
  ************************************************************************
  */
 
@@ -48,6 +48,7 @@
 #undef WAN_DEBUG_MEM
 #undef WAN_DEBUG_BRI
 #undef WAN_DEBUG_BRI_INIT
+#undef WAN_DEBUG_USB
 #undef WAN_DEBUG_FUNC
 
 #if defined (__WINDOWS__)
@@ -61,9 +62,12 @@
 # define PRINT	if(1)DbgPrint
 #endif
 
+
 # define DEBUG_PRINT	DbgPrint
 # define _DEBUG_PRINT	DbgPrint
 
+#define _DEBUG_EVENT 	DbgPrint
+
 # define DEBUG_KERNEL	DEBUG_NONE
 # define DEBUG_EVENT	DEBUG_NONE
 # define DEBUG_MOD	DEBUG_NONE
@@ -175,11 +179,11 @@
 # ifdef WAN_DEBUG_56K
 #  undef  DEBUG_56K
 #  define DEBUG_56K	DEBUG_PRINT
-# endif
+# endif 
 # ifdef WAN_DEBUG_A600
 #  undef  DEBUG_A600
 #  define DEBUG_A600	DEBUG_PRINT
-# endif  
+# endif 
 # ifdef WAN_DEBUG_BRI
 #  undef  DEBUG_BRI
 #  define DEBUG_BRI	DEBUG_PRINT
@@ -236,6 +240,25 @@
 #  undef  DEBUG_BRI_INIT
 #  define DEBUG_BRI_INIT DEBUG_PRINT
 # endif 
+# ifdef WAN_DEBUG_USB
+#  undef  DEBUG_USB
+#  define DEBUG_USB	DEBUG_PRINT
+# endif 
+
+//uncomment -DSANG_DBG in C_DEFINES in Sources to get debug output
+#if defined(SANG_DBG)
+ //print driver name and a line
+ #define DbgOut(_f_, _x_) if(_f_) { DbgPrint("%s: ", DRIVER_NAME); DbgPrint _x_;}
+ //print a line. used when driver name is not needed
+ #define DbgOutL(_f_, _x_) if(_f_) { DbgPrint _x_;}
+ #define BUS_DEFAULT_DEBUG_OUTPUT_LEVEL 0x000FFFFF
+#else //#if SANG_DBG
+ #define BUS_DEFAULT_DEBUG_OUTPUT_LEVEL 0x0
+ #define DbgOut(_f_, _x_)
+ #define DbgOutL(_f_, _x_)
+#endif//#if SANG_DBG
+
+extern ULONG BusEnumDebugLevel;
 
 # define DEBUG_ADD_MEM
 # define DEBUG_SUB_MEM
@@ -243,65 +266,72 @@
 # define splimp() 0
 # define splx(l)
 
-#define	ERR_DBG_OUT	if(0)DbgPrint
-#define DBG_NOT_IMPL	if(0)DbgPrint
-#define FUNC_NOT_IMPL	if(0)DbgPrint("%s()-Not Implemented(Line:%i)\n", __FUNCTION__, __LINE__);
-#define DBG_DSL_NOT_IMPLD if(0)DbgPrint("%s()-Not Implemented(Line:%i)\n", __FUNCTION__, __LINE__);
+#define	ERR_DBG_OUT			if(0)DbgPrint
+#define DBG_NOT_IMPL		if(0)DbgPrint
+#define FUNC_NOT_IMPL()		if(0)DbgPrint("%s()-Not Implemented(File:%s, Line:%i)\n", __FUNCTION__, __FILE__, __LINE__)
+#define DBG_DSL_NOT_IMPLD	FUNC_NOT_IMPL()
 
 /* debugging of SngBus.sys */
 #define DEBUG_SNGBUS	if(0)DbgPrint
 
+#define DBG_SINGLE_IRQLOCK if(0)DbgPrint
+
 /* debugging of wanpipe_kernel.h */
-#define DBG_KRN		if(0)DbgPrint
-#define DBG_8TE1	if(0)DbgPrint
-#define DG_TDMCODEC	if(0)DbgPrint
-#define DBG_G3		if(0)DbgPrint
+#define DBG_KRN			if(0)DbgPrint
+#define DBG_COPY_FROM_TO_USER if(0)DbgPrint
+#define DBG_SHUTDOWN	if(0)DbgPrint
+
+#define DBG_FAST_TX		if(0)DbgPrint
 
-#define DBG_FAST_TX	if(0)DbgPrint
-#define DBG_ACUAPI	if(0)DbgPrint
-#define DEBUG_IDLE_TX	if(0)DbgPrint
 #define DEBUG_SHARED_EVENT if(0)DbgPrint
-#define DBG_ADSL_TX	if(0)DbgPrint
-#define DEBUG_NEW_TX	if(0)DbgPrint
-#define DBG_IRQLOCK	if(0)DbgPrint
+#define DBG_ADSL_TX		if(0)DbgPrint
+#define DBG_IRQLOCK		if(0)DbgPrint
 #define DBG_ADSL_FAST_TX if(0)DbgPrint
-#define DBG_S514_INIT	if(0)DbgPrint
-#define DBG_SET_CFG	if(0)DbgPrint
+
+#define DBG_SET_CFG		if(0)DbgPrint
 #define DBG_ADSL_INIT	if(0)DbgPrint
-#define DBG_HIGH_IMPED	if(0)DbgPrint
-#define DBG_LIP_OOB	if(0)DbgPrint
+
+#define DBG_A200_INIT	if(0)DbgPrint
+
+#define DBG_LIP_OOB		if(0)DbgPrint
 #define DEBUG_XLNX_AFT	if(0)DbgPrint
-#define DEBUG_AFT	if(0)DbgPrint
-#define DBG_TE1_INTERRUPT if(0)DbgPrint
-#define DBG_BSTRM	if(0)DbgPrint
-#define DEBUG_FIRMWARE_UPDATE if(0)DbgPrint
-#define DBG_ADSL_RX	if(0)DbgPrint
-#define DBG_8TE1_START	if(0)DbgPrint
-#define DBG_BITSTRM	if(0)DbgPrint
+#define DEBUG_AFT		if(0)DbgPrint
 
-#define DBG_BRI_START	if(0)DbgPrint
-#define DBG_BRI_CLOCK	if(0)DbgPrint
-#define DBG_BRI_ISR	if(0)DbgPrint
-#define DBG_BRI_RESTART	if(0)DbgPrint
+#define DBG_BSTRM		if(0)DbgPrint
+#define DEBUG_FIRMWARE_UPDATE if(0)DbgPrint
+#define DBG_ADSL_RX		if(0)DbgPrint
 
-#define	DBG_FE_LOCK	if(0)DbgPrint
-#define DBG_DRVSTOP	if(0)DbgPrint
+#define	DBG_FE_LOCK		if(0)DbgPrint
+#define DBG_DRVSTOP		if(0)DbgPrint
 #define DBG_GET_REGISTRY if(0)DbgPrint
-#define	DBG_FE_LOCK	if(0)DbgPrint
+#define	DBG_FE_LOCK		if(0)DbgPrint
 
 #define DEBUG_RX_FIFO	if(0)DbgPrint
 
 /* sprotocol.sys */
-#define DEBUG_LIP	if(0)DbgPrint
-#define DBG_LIP_SKB	if(0)DbgPrint
+#define DEBUG_LIP		if(0)DbgPrint
+#define DBG_LIP_SKB		if(0)DbgPrint
 /* wanpipe.sys */
 #define DEBUG_REQUEST	if(0)DbgPrint
-#define DEBUG_IF_TX	if(0)DbgPrint
+#define DEBUG_IF_TX		if(0)DbgPrint
 #define DEBUG_COMMON	if(0)DbgPrint
-#define DEBUG_IF_RX	if(0)DbgPrint
+#define DEBUG_IF_RX		if(0)DbgPrint
 #define DEBUG_NET_IF	if(0)DbgPrint
 
-#define DBG_TX_TIMEOUT	if(0)DbgPrint
+#define DBG_RBS_EVENT	if(0)DbgPrint
+
+#define DBG_ADSL_MACADDR	if(0)DbgPrint
+#define DBG_ADSL_SYNCH		if(0)DbgPrint
+
+#define DBG_MEM		if(0)DbgPrint
+
+#define DBG_PNP		if(0)DbgPrint(DRIVER_NAME);if(0)DbgPrint
+
+#define DBG_SYMB_LINK if(0)DbgPrint
+
+#define DBG_BUFLEN	 if(0)DbgPrint
+
+#define ADSL_TEST 0
 
 /* These are defined in "sources" file of each driver */
 #if defined( VIRTUAL_IF_DRV )
@@ -321,16 +351,16 @@
 	DbgPrint("%s:%s(): File: %s, Line: %d.\n", drv_name, func, file, line);
 }
 
-#define AFT_FUNC_DEBUG() if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define TDM_FUNC_DBG()	 if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define EC_FUNC_DEBUG()	 if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define DBG_SET_CFG_FUNC() if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define DBG_ACUAPI_FUNC() if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define FUNC_DEBUG()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define TDM_FUNC_DBG()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-#define SKB_FUNC()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+//#define AFT_FUNC_DEBUG()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define TDM_FUNC_DBG()		if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define EC_FUNC_DEBUG()		if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define DBG_SET_CFG_FUNC()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define DBG_ACUAPI_FUNC()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define FUNC_DEBUG()		if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define TDM_FUNC_DBG()		if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
+#define SKB_FUNC()		if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
 #define PROT_FUNC_DEBUG()	if(0)my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
-
+#define TDMAPI_FUNC_DEBUG()	if()my_func_dbg(DRIVER_NAME, __FUNCTION__, __FILE__, __LINE__)
 
 #else	/* !__WINDOWS__*/
 
@@ -375,6 +405,7 @@
 # define WAN_DEBUG_FUNC_LINE
 # define DEBUG_BRI(format,msg...)
 # define DEBUG_BRI_INIT(format,msg...)
+# define DEBUG_USB(format,msg...)
 
 #define AFT_FUNC_DEBUG() 
 
@@ -537,9 +568,19 @@
 #  undef  DEBUG_NG
 #  define DEBUG_NG(format,msg...)		DEBUG_PRINT(format,##msg)
 # endif 
+# ifdef WAN_DEBUG_USB
+#  undef  DEBUG_USB
+#  define DEBUG_USB(format,msg...)		DEBUG_PRINT(format,##msg)
+# endif 
 
 #endif	/* __WINDOWS__ */
 
+#if defined (__WINDOWS__)
+#define	WAN_KRN_BREAK_POINT()	if(0)DbgBreakPoint()
+#else
+#define	WAN_KRN_BREAK_POINT()
+#endif
+
 #define WAN_DEBUG_FLINE	DEBUG_EVENT("[%s]: %s:%d\n",			\
 				__FILE__,__FUNCTION__,__LINE__);
 
@@ -562,6 +603,7 @@
 #define WAN_ASSERT(val) if (val){					\
 	DEBUG_EVENT("************** ASSERT FAILED **************\n");	\
 	DEBUG_EVENT("%s:%d - Critical error\n",__FILE__,__LINE__);	\
+	WAN_KRN_BREAK_POINT();	\
 	return -EINVAL;							\
 			}
 #define WAN_ASSERT_EINVAL(val) WAN_ASSERT(val)
@@ -695,7 +737,7 @@
 	DEBUG_TEST("%s:%d: WULock %u\n",__FILE__,__LINE__,(u32)lock); 	\
 	splx(flag); }
 
-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__WINDOWS__)
+#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 # define WP_READ_LOCK(lock,flag)   {					\
 	DEBUG_TEST("%s:%d: RLock %u\n",__FILE__,__LINE__,(u32)lock);	\
 	flag = splimp(); }
@@ -712,6 +754,24 @@
 	DEBUG_TEST("%s:%d: WULock %u\n",__FILE__,__LINE__,(u32)lock); 	\
 	splx(flag); }
 
+#elif defined(__WINDOWS__)
+
+# define WP_READ_LOCK(lock,flag)   {							\
+	DEBUG_TEST("%s:%d: RLock 0x%p\n",__FILE__,__LINE__,lock);	\
+	flag = splimp(); }
+				     
+# define WP_READ_UNLOCK(lock,flag) {							\
+	DEBUG_TEST("%s:%d: RULock 0x%p\n",__FILE__,__LINE__,lock);	\
+	splx(flag);}
+
+# define WP_WRITE_LOCK(lock,flag) {								\
+	DEBUG_TEST("%s:%d: WLock 0x%p\n",__FILE__,__LINE__,lock); 	\
+	flag = splimp(); }
+
+# define WP_WRITE_UNLOCK(lock,flag) {							\
+	DEBUG_TEST("%s:%d: WULock 0x%p\n",__FILE__,__LINE__,lock); \
+	splx(flag); }
+
 #elif defined(__LINUX__)
 
 # define WAN_TIMEOUT(sec)  { unsigned long timeout; \
@@ -764,6 +824,14 @@
 #endif
 
 
+#if defined(__WINDOWS__)
+#define DBG_NEWDRV		if(0)DbgPrint
+#define FUNC_NEWDRV()	if(0)DbgPrint("%s():Line:%i\n", __FUNCTION__, __LINE__)
+#else
+#define DBG_NEWDRV		if(1)DEBUG_TEST
+#define FUNC_NEWDRV()	if(1)DEBUG_TEST("%s():Line:%i\n", __FUNCTION__, __LINE__)
+#endif
+
 static __inline void debug_print_skb_pkt(unsigned char *name, unsigned char *data, int len, int direction)
 {
 #if defined(__LINUX__) && defined(__KERNEL__)
@@ -778,6 +846,8 @@
 }
 
 
+#if 0
+
 static __inline void debug_print_udp_pkt(unsigned char *data,int len,char trc_enabled, char direction)
 {
 #if defined(__LINUX__) && defined(__KERNEL__)
@@ -850,6 +920,7 @@
 #endif
 }
 
+#endif
 
 
 
diff -dur include/wanpipe_defines.h /usr/include/wanpipe/wanpipe_defines.h
--- include/wanpipe_defines.h	2009-07-13 17:38:20.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_defines.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,16 +1,16 @@
-/*************************************************************************
-* wanpipe_defines.h							 *
-*		WANPIPE(tm) 	Global definition for Sangoma 		 *
-*				Mailbox/API/UDP	structures.		 *
-*									 *
-* Author:	Alex Feldman <al.feldman@sangoma.com>			 *
-*========================================================================*
-* May 10, 2002	Alex Feldman	Initial version				 *
-*									 * 
-* Nov 27,  2007 David Rokhvarg	Implemented functions/definitions for    *
-*                              Sangoma MS Windows Driver and API.        *
-*									 *
-*									 *
+/************************************************************************
+* wanpipe_defines.h														*
+*		WANPIPE(tm) 	Global definition for Sangoma 					*
+*				Mailbox/API/UDP	structures.								*
+*																		*
+* Author:	Alex Feldman <al.feldman@sangoma.com>						*
+*=======================================================================*
+* May 10, 2002	Alex Feldman	Initial version							*
+*																		* 
+* Nov 27,  2007 David Rokhvarg	Implemented functions/definitions for   *
+*                              Sangoma MS Windows Driver and API.       *
+*																		*
+*																		*
 *************************************************************************/
 
 #ifndef __WANPIPE_DEFINES_H
@@ -25,27 +25,20 @@
 # endif
 #endif
 
-#if defined(__LINUX__)
-# include <linux/wanpipe_includes.h>
-# include <linux/wanpipe_version.h>
-# include <linux/wanpipe_kernel.h>
-# include <linux/wanpipe_abstr_types.h>
-#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <wanpipe_version.h>
-# if defined(WAN_KERNEL)
-#  include <wanpipe_kernel.h>
-# endif
-# include <wanpipe_abstr_types.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_version.h>
-# include <wanpipe_ctypes.h> /* Basic data types */
-# include <wanpipe_debug.h>
+#include "wanpipe_version.h"
+#if defined(WAN_KERNEL)
+ #include "wanpipe_kernel.h"
+#endif
+#include "wanpipe_abstr_types.h"
+
+#if defined(__WINDOWS__)
+# include "wanpipe_ctypes.h" /* Basic data types */
 # if defined(WAN_KERNEL)
-# include <wanpipe_kernel.h>
+#  include "wanpipe_skb.h"
 # endif
-# include <wanpipe_abstr_types.h>
 #endif
 
+
 /************************************************
  *	GLOBAL SANGOMA PLATFORM DEFINITIONS	*
  ************************************************/
@@ -71,27 +64,6 @@
 # define WAN_PLATFORM_ID	WAN_WIN2K_PLATFORM
 #endif
 
-/************************************************
- *	GLOBAL SANGOMA COMMAND RANGES		*
- ************************************************/
-#define WAN_PROTOCOL_CMD_START	0x01
-#define WAN_PROTOCOL_CMD_END	0x4F
-
-#define WAN_UDP_CMD_START	0x60
-#define WAN_GET_PROTOCOL	(WAN_UDP_CMD_START+0)
-#define WAN_GET_PLATFORM	(WAN_UDP_CMD_START+1)
-#define WAN_GET_MEDIA_TYPE	(WAN_UDP_CMD_START+2)
-#define WAN_GET_MASTER_DEV_NAME	(WAN_UDP_CMD_START+3)
-#define WAN_UDP_CMD_END		0x6F	
-
-#define WAN_FE_CMD_START	0x90
-#define WAN_FE_CMD_END		0x9F
-
-#define WAN_INTERFACE_CMD_START	0xA0
-#define WAN_INTERFACE_CMD_END	0xAF
-
-#define WAN_FE_UDP_CMD_START	0xB0
-#define WAN_FE_UDP_CMD_END	0xBF	
 
 /*
 ************************************************
@@ -169,13 +141,8 @@
 # define w_tcp_seq	seq
 # define w_tcp_ack_seq	ack_seq
 
-#if 0
-typedef time_t	wan_time_t;
-typedef suseconds_t	wan_suseconds_t;
-#else
-#define wan_time_t unsigned long
-#define wan_suseconds_t unsigned long
-#endif
+# define wan_time_t	 unsigned long
+# define wan_suseconds_t unsigned long
 
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 typedef	struct ip		iphdr_t;
@@ -200,12 +167,15 @@
 # define w_tcp_dport	th_dport
 # define w_tcp_seq	th_seq
 # define w_tcp_ack_seq	th_ack
+
 # if (__FreeBSD_version > 700000)
-typedef time_t	wan_time_t;
+# define wan_time_t time_t
 # else /* includes FreeBSD-5/6/OpenBSD/NetBSD */
-typedef long wan_time_t;
+# define wan_time_t long
 # endif
-typedef suseconds_t	wan_suseconds_t;
+#define wan_suseconds_t suseconds_t
+
+
 
 #elif defined(__WINDOWS__)
 /* Intel X86 */
@@ -243,8 +213,37 @@
 typedef	struct	iphdr	iphdr_t;
 typedef	struct	udphdr	udphdr_t;
 
-typedef unsigned long	wan_time_t;
-typedef unsigned long	wan_suseconds_t;
+
+# define w_eth_dest	h_dest
+# define w_eth_src	h_source
+# define w_eth_proto	h_proto
+# define w_ip_v		version
+# define w_ip_hl	ihl
+# define w_ip_tos	tos
+# define w_ip_len	tot_len
+# define w_ip_id	id
+# define w_ip_off	frag_off
+# define w_ip_ttl	ttl
+# define w_ip_p		protocol
+# define w_ip_sum	check
+# define w_ip_src	saddr
+# define w_ip_dst	daddr
+# define w_udp_sport	source
+# define w_udp_dport	dest
+# define w_udp_len	len
+# define w_udp_sum	check
+# define w_tcp_sport	source
+# define w_tcp_dport	dest
+# define w_tcp_seq	seq
+# define w_tcp_ack_seq	ack_seq
+
+# define wan_time_t	 unsigned long
+# define wan_suseconds_t unsigned long
+
+#if !defined snprintf
+# define snprintf	_snprintf
+#endif
+
 #else
 # error "Unknown OS system!"
 #endif
@@ -265,6 +264,7 @@
 typedef u_int64_t		u64;
 #endif
 
+
 /************************************************
 **	GLOBAL SANGOMA MACROS
 ************************************************/
@@ -278,442 +278,8 @@
 # endif
 #endif
 
-/************************************************
- *	GLOBAL DEFINITION FOR SANGOMA MAILBOX	*
- ************************************************/
-#define WAN_MAILBOX_SIZE	16
-#define WAN_MAX_DATA_SIZE	2032
-#define WAN_MAX_CMD_DATA_SIZE	1000
-#define WAN_MAX_POS_DATA_SIZE	1030
-
-#pragma pack(1)
-typedef struct {
-	union {
-		struct {
-			unsigned char  opp_flag;
-			unsigned char  command;
-			unsigned short data_len;	
-			unsigned char  return_code;
-			union {
-				struct {
-					unsigned char	PF_bit;		/* the HDLC P/F bit */
-				} hdlc;
-				struct {
-					unsigned short	dlci;		/* DLCI number */
-					unsigned char	attr;		/* FECN, BECN, DE and C/R bits */
-					unsigned short	rxlost1;	/* frames discarded at int. level */
-					u_int32_t	rxlost2;	/* frames discarded at app. level */
-				} fr;
-				struct {
-					unsigned char	pf;			/* P/F bit */
-					unsigned short	lcn;		/* logical channel */
-					unsigned char	qdm;		/* Q/D/M bits */
-					unsigned char	cause;		/* cause field */
-					unsigned char	diagn;		/* diagnostics */
-					unsigned char	pktType;	/* packet type */
-				} x25;
-				struct {
-					unsigned char	misc_Tx_Rx_bits; /* miscellaneous transmit and receive bits */
-					unsigned char	Rx_error_bits; /* an indication of a block received with an error */
-					unsigned short	Rx_time_stamp; /* a millisecond receive time stamp */
-					unsigned char	port;		/* comm port */
-				} bscstrm;
-				struct {
-					unsigned char 	misc_tx_rx_bits;
-					unsigned short 	heading_length;
-					unsigned short 	notify;
-					unsigned char 	station;
-					unsigned char 	poll_address;
-					unsigned char 	select_address;
-					unsigned char 	device_address;
-					unsigned char 	notify_extended;
-				} bsc;
-				struct {
-					unsigned char	sdlc_address;
-					unsigned char	PF_bit;
-					unsigned short	poll_interval;
-					unsigned char	general_mailbox_byte;
-				} sdlc;
-				struct {
-					unsigned char	force;
-				} fe;
-			} wan_protocol;
-		} wan_p_cmd;
-		struct {
-			unsigned char opp_flag;
-			unsigned char pos_state;
-			unsigned char async_state;
-		} wan_pos_cmd;
-		unsigned char mbox[WAN_MAILBOX_SIZE];
-	} wan_cmd_u;
-#define wan_cmd_opp_flag		wan_cmd_u.wan_p_cmd.opp_flag
-#define wan_cmd_command			wan_cmd_u.wan_p_cmd.command
-#define wan_cmd_data_len		wan_cmd_u.wan_p_cmd.data_len
-#define wan_cmd_return_code		wan_cmd_u.wan_p_cmd.return_code
-#define wan_cmd_hdlc_PF_bit		wan_cmd_u.wan_p_cmd.wan_protocol.hdlc.PF_bit
-#define wan_cmd_fe_force		wan_cmd_u.wan_p_cmd.wan_protocol.fe.force
-#define wan_cmd_fr_dlci			wan_cmd_u.wan_p_cmd.wan_protocol.fr.dlci
-#define wan_cmd_fr_attr			wan_cmd_u.wan_p_cmd.wan_protocol.fr.attr
-#define wan_cmd_fr_rxlost1		wan_cmd_u.wan_p_cmd.wan_protocol.fr.rxlost1
-#define wan_cmd_fr_rxlost2		wan_cmd_u.wan_p_cmd.wan_protocol.fr.rxlost2
-#define wan_cmd_x25_pf			wan_cmd_u.wan_p_cmd.wan_protocol.x25.pf
-#define wan_cmd_x25_lcn			wan_cmd_u.wan_p_cmd.wan_protocol.x25.lcn
-#define wan_cmd_x25_qdm			wan_cmd_u.wan_p_cmd.wan_protocol.x25.qdm
-#define wan_cmd_x25_cause		wan_cmd_u.wan_p_cmd.wan_protocol.x25.cause
-#define wan_cmd_x25_diagn		wan_cmd_u.wan_p_cmd.wan_protocol.x25.diagn
-#define wan_cmd_x25_pktType		wan_cmd_u.wan_p_cmd.wan_protocol.x25.pktType
-#define wan_cmd_bscstrm_misc_bits	wan_cmd_u.wan_p_cmd.wan_protocol.bscstrm.misc_Tx_Rx_bits
-#define wan_cmd_bscstrm_Rx_err_bits	wan_cmd_u.wan_p_cmd.wan_protocol.bscstrm.Rx_error_bits
-#define wan_cmd_bscstrm_Rx_time_stamp	wan_cmd_u.wan_p_cmd.wan_protocol.bscstrm.Rx_time_stamp
-#define wan_cmd_bscstrm_port		wan_cmd_u.wan_p_cmd.wan_protocol.bscstrm.port
-#define wan_cmd_bsc_misc_bits		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.misc_tx_rx_bits
-#define wan_cmd_bsc_heading_len		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.heading_length
-#define wan_cmd_bsc_notify		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.notify
-#define wan_cmd_bsc_station		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.station
-#define wan_cmd_bsc_poll_addr		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.poll_address
-#define wan_cmd_bsc_select_addr		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.select_address
-#define wan_cmd_bsc_device_addr		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.device_address
-#define wan_cmd_bsc_notify_ext		wan_cmd_u.wan_p_cmd.wan_protocol.bsc.notify_extended
-#define wan_cmd_sdlc_address		wan_cmd_u.wan_p_cmd.wan_protocol.sdlc.sdlc_address
-#define wan_cmd_sdlc_pf			wan_cmd_u.wan_p_cmd.wan_protocol.sdlc.PF_bit
-#define wan_cmd_sdlc_poll_interval	wan_cmd_u.wan_p_cmd.wan_protocol.sdlc.poll_interval
-#define wan_cmd_sdlc_general_mb_byte	wan_cmd_u.wan_p_cmd.wan_protocol.sdlc.general_mailbox_byte
-
-#define wan_cmd_pos_opp_flag		wan_cmd_u.wan_pos_cmd.opp_flag
-#define wan_cmd_pos_pos_state		wan_cmd_u.wan_pos_cmd.pos_state
-#define wan_cmd_pos_async_state		wan_cmd_u.wan_pos_cmd.async_state
-} wan_cmd_t;
-
-
-typedef struct {
-	wan_cmd_t	wan_cmd;
-	union {
-		struct {
-			unsigned char  command;
-			unsigned short data_len;	
-			unsigned char  return_code;
-			unsigned char  port_num;
-			unsigned char  attr;
-			unsigned char  reserved[10];
-			unsigned char  data[WAN_MAX_POS_DATA_SIZE];
-		} pos_data;
-		unsigned char data[WAN_MAX_DATA_SIZE];
-	} wan_u_data;
-#define wan_opp_flag			wan_cmd.wan_cmd_opp_flag
-#define wan_command			wan_cmd.wan_cmd_command
-#define wan_data_len			wan_cmd.wan_cmd_data_len
-#define wan_return_code			wan_cmd.wan_cmd_return_code
-#define wan_hdlc_PF_bit			wan_cmd.wan_cmd_hdlc_PF_bit
-#define wan_fr_dlci			wan_cmd.wan_cmd_fr_dlci
-#define wan_fr_attr			wan_cmd.wan_cmd_fr_attr
-#define wan_fr_rxlost1			wan_cmd.wan_cmd_fr_rxlost1
-#define wan_fr_rxlost2			wan_cmd.wan_cmd_fr_rxlost2
-#define wan_x25_pf			wan_cmd.wan_cmd_x25_pf
-#define wan_x25_lcn			wan_cmd.wan_cmd_x25_lcn
-#define wan_x25_qdm			wan_cmd.wan_cmd_x25_qdm
-#define wan_x25_cause			wan_cmd.wan_cmd_x25_cause
-#define wan_x25_diagn			wan_cmd.wan_cmd_x25_diagn
-#define wan_x25_pktType			wan_cmd.wan_cmd_x25_pktType
-#define wan_bscstrm_misc_bits		wan_cmd.wan_cmd_bscstrm_misc_bits
-#define wan_bscstrm_Rx_err_bits		wan_cmd.wan_cmd_bscstrm_Rx_error_bits
-#define wan_bscstrm_Rx_time_stamp	wan_cmd.wan_cmd_bscstrm_Rx_time_stamp
-#define wan_bscstrm_port		wan_cmd.wan_cmd_bscstrm_port
-#define wan_bsc_misc_bits		wan_cmd.wan_cmd_bsc_misc_bits
-#define wan_bsc_heading_len		wan_cmd.wan_cmd_bsc_heading_length
-#define wan_bsc_notify			wan_cmd.wan_cmd_bsc_notify
-#define wan_bsc_station			wan_cmd.wan_cmd_bsc_station
-#define wan_bsc_poll_addr		wan_cmd.wan_cmd_bsc_poll_address
-#define wan_bsc_select_addr		wan_cmd.wan_cmd_bsc_select_address
-#define wan_bsc_device_addr		wan_cmd.wan_cmd_bsc_device_address
-#define wan_bsc_notify_ext		wan_cmd.wan_cmd_bsc_notify_extended
-#define wan_sdlc_address		wan_cmd.wan_cmd_sdlc_address		
-#define wan_sdlc_pf			wan_cmd.wan_cmd_sdlc_pf			
-#define wan_sdlc_poll_interval		wan_cmd.wan_cmd_sdlc_poll_interval	
-#define wan_sdlc_general_mb_byte	wan_cmd.wan_cmd_sdlc_general_mb_byte	
-#define wan_data			wan_u_data.data	
-
-#define wan_pos_opp_flag		wan_cmd.wan_cmd_pos_opp_flag
-#define wan_pos_pos_state		wan_cmd.wan_cmd_pos_pos_state
-#define wan_pos_async_state		wan_cmd.wan_cmd_pos_async_state
-#define wan_pos_command			wan_u_data.pos_data.command
-#define wan_pos_data_len		wan_u_data.pos_data.data_len
-#define wan_pos_return_code		wan_u_data.pos_data.return_code
-#define wan_pos_port_num		wan_u_data.pos_data.port_num
-#define wan_pos_attr			wan_u_data.pos_data.attr
-#define wan_pos_data			wan_u_data.pos_data.data
-} wan_mbox_t;
-
-#define WAN_MBOX_INIT(mbox)	memset(mbox, 0, sizeof(wan_cmd_t));
-
-/********************************************************
- *	GLOBAL DEFINITION FOR SANGOMA API STRUCTURE	*
- *******************************************************/
-#define WAN_API_MAX_DATA	2048
-typedef struct{
-	unsigned char	pktType;
-	unsigned short	length;
-	unsigned char	result;
-	union {
-		struct {
-			unsigned char	arg1;
-			unsigned short	time_stamp;
-		} chdlc;
-		struct {
-	        	unsigned char   attr;
-	        	unsigned short  time_stamp;
-		} fr;
-		struct {
-			unsigned char	qdm;
-			unsigned char	cause;
-			unsigned char	diagn;
-			unsigned short	lcn;
-		} x25;
-		struct {
-			unsigned char  station;
-			unsigned char  PF_bit;
-			unsigned short poll_interval;
-			unsigned char  general_mailbox_byte;
-		}sdlc;
-		struct {
-			unsigned char  exception;
-		}xdlc;
-	} wan_protocol;
-#define wan_apihdr_chdlc_error_flag	wan_protocol.chdlc.arg1
-#define wan_apihdr_chdlc_attr		wan_protocol.chdlc.arg1
-#define wan_apihdr_chdlc_time_stamp	wan_protocol.chdlc.time_stamp
-#define wan_apihdr_fr_attr		wan_protocol.fr.attr
-#define wan_apihdr_fr_time_stamp	wan_protocol.fr.time_stamp
-#define wan_apihdr_x25_qdm		wan_protocol.x25.qdm
-#define wan_apihdr_x25_cause		wan_protocol.x25.cause
-#define wan_apihdr_x25_diagn		wan_protocol.x25.diagn
-#define wan_apihdr_x25_lcn		wan_protocol.x25.lcn
-
-#define wan_apihdr_sdlc_station		wan_protocol.sdlc.station
-#define wan_apihdr_sdlc_pf		wan_protocol.sdlc.PF_bit
-#define wan_apihdr_sdlc_poll_interval	wan_protocol.sdlc.poll_interval
-#define wan_apihdr_sdlc_general_mb_byte	wan_protocol.sdlc.general_mailbox_byte
-
-#define wan_apihdr_xdlc_exception	wan_protocol.xdlc.exception
-} wan_api_hdr_t;
-
-
-typedef struct{
-	wan_api_hdr_t	api_hdr;
-	unsigned char	data[WAN_API_MAX_DATA];
-#define wan_api_pktType			api_hdr.pktType
-#define wan_api_length			api_hdr.length
-#define wan_api_result			api_hdr.result
-#define wan_api_chdlc_error_flag	api_hdr.wan_apihdr_chdlc_error_flag
-#define wan_api_chdlc_time_stamp	api_hdr.wan_apihdr_chdlc_time_stamp
-#define wan_api_chdlc_attr		api_hdr.wan_apihdr_chdlc_attr
-#define wan_api_chdlc_misc_Tx_bits	api_hdr.wan_apihdr_chdlc_misc_Tx_bits
-#define wan_api_fr_attr			api_hdr.wan_apihdr_fr_attr
-#define wan_api_fr_time_stamp		api_hdr.wan_apihdr_fr_time_stamp
-#define wan_api_x25_qdm			api_hdr.wan_apihdr_x25_qdm
-#define wan_api_x25_cause		api_hdr.wan_apihdr_x25_cause
-#define wan_api_x25_diagn		api_hdr.wan_apihdr_x25_diagn
-#define wan_api_x25_lcn			api_hdr.wan_apihdr_x25_lcn
-#define	wan_api_sdlc_station		api_hdr.wan_apihdr_sdlc_station
-#define wan_api_sdlc_pf			api_hdr.wan_apihdr_sdlc_pf
-#define wan_api_sdlc_poll_interval	api_hdr.wan_apihdr_sdlc_poll_interval
-#define wan_api_sdlc_general_mb_byte	api_hdr.wan_apihdr_sdlc_general_mb_byte
-#define wan_api_xdlc_exception		api_hdr.wan_apihdr_xdlc_exception
-} wan_api_t;
-
-
-typedef struct {
-	union {
-		struct {
-			unsigned char	error_flag;
-			unsigned short	time_stamp;
-		}chdlc,hdlc;
-		struct {
-			unsigned char   exception;
-			unsigned char 	pf;
-		}lapb;
-		struct {
-			unsigned char	state;
-			unsigned char	address;
-			unsigned short  exception;
-		}xdlc;
-		unsigned char	reserved[16];
-	}u;
-
-#define wan_hdr_xdlc_state	u.xdlc.state
-#define wan_hdr_xdlc_address	u.xdlc.address
-#define wan_hdr_xdlc_exception	u.xdlc.exception
-} wan_api_rx_hdr_t;
-
-typedef struct {
-        wan_api_rx_hdr_t	api_rx_hdr;
-#if defined(__WINDOWS__)/* zero-sized array does not comply to ANSI 'C' standard! */
-        unsigned char  		data[1];
-#else
-        unsigned char  		data[0];
-#endif
-#define wan_rxapi_xdlc_state		api_rx_hdr.wan_hdr_xdlc_state
-#define wan_rxapi_xdlc_address		api_rx_hdr.wan_hdr_xdlc_address
-#define wan_rxapi_xdlc_exception	api_rx_hdr.wan_hdr_xdlc_exception
-} wan_api_rx_element_t;
-
-typedef struct {
-	union{
-		struct {
-			unsigned char 	attr;
-			unsigned char   misc_Tx_bits;
-		}chdlc,hdlc;
-		struct {
-			unsigned char 	pf;
-		}lapb;
-		struct {
-			unsigned char  pf;
-		}xdlc;
-		unsigned char  	reserved[16];
-	}u;
-} wan_api_tx_hdr_t;
-
-typedef struct {
-	wan_api_tx_hdr_t 	api_tx_hdr;
-#if defined(__WINDOWS__)/* zero-sized array does not comply to ANSI 'C' standard! */
-	unsigned char		data[1];
-#else
-	unsigned char		data[0];
-#endif
-}wan_api_tx_element_t;
-
-#pragma pack()
-
-#if !defined(__WINDOWS__)
-enum {
-	SIOC_WAN_READ_REG = 0x01,
-	SIOC_WAN_WRITE_REG,
-	SIOC_WAN_HWPROBE,
-	SIOC_WAN_ALL_HWPROBE,
-	SIOC_WAN_ALL_READ_REG,
-	SIOC_WAN_ALL_WRITE_REG,
-	SIOC_WAN_ALL_SET_PCI_BIOS,
-	SIOC_WAN_SET_PCI_BIOS,
-	SIOC_WAN_COREREV,
-	SIOC_WAN_GET_CFG,
-	SIOC_WAN_FE_READ_REG,
-	SIOC_WAN_FE_WRITE_REG,
-	SIOC_WAN_EC_REG,
-	SIOC_WAN_READ_PCIBRIDGE_REG,
-	SIOC_WAN_ALL_READ_PCIBRIDGE_REG,
-	SIOC_WAN_WRITE_PCIBRIDGE_REG,
-	SIOC_WAN_ALL_WRITE_PCIBRIDGE_REG
-};
-#endif
-
-typedef struct wan_cmd_api_
-{
-	unsigned int	cmd;
-	unsigned short	len;
-	unsigned char	bar;
-	u_int32_t	offset;
-	unsigned char	data[WAN_MAX_CMD_DATA_SIZE];
-} wan_cmd_api_t;
-
-
-/********************************************************
- *	GLOBAL DEFINITION FOR SANGOMA UDP STRUCTURE	*
- *******************************************************/
-#define GLOBAL_UDP_SIGNATURE		"WANPIPE"
-#define GLOBAL_UDP_SIGNATURE_LEN	7
-#define UDPMGMT_UDP_PROTOCOL 		0x11
-
-typedef struct {
-	unsigned char	signature[8];
-	unsigned char	request_reply;
-	unsigned char	id;
-	unsigned char	reserved[6];
-} wan_mgmt_t;
-
-
-/****** DEFINITION OF UDP HEADER AND STRUCTURE PER PROTOCOL ******/
-typedef struct {
-	unsigned char	num_frames;
-	unsigned char	ismoredata;
-} wan_trace_info_t;
-
-typedef struct wan_udp_hdr{
-	wan_mgmt_t	wan_mgmt;
-	wan_cmd_t	wan_cmd;
-	union {
-		struct {
-			wan_trace_info_t	trace_info;
-			unsigned char		data[WAN_MAX_DATA_SIZE];
-		} chdlc, adsl, atm, ss7,bitstrm,aft;
-#define xilinx aft
-		unsigned char data[WAN_MAX_DATA_SIZE];
-	} wan_udphdr_u;
-#define wan_udphdr_signature			wan_mgmt.signature
-#define wan_udphdr_request_reply		wan_mgmt.request_reply
-#define wan_udphdr_id				wan_mgmt.id
-#define wan_udphdr_opp_flag			wan_cmd.wan_cmd_opp_flag
-#define wan_udphdr_command			wan_cmd.wan_cmd_command
-#define wan_udphdr_data_len			wan_cmd.wan_cmd_data_len
-#define wan_udphdr_return_code			wan_cmd.wan_cmd_return_code
-#define wan_udphdr_fe_force			wan_cmd.wan_cmd_fe_force
-#define wan_udphdr_hdlc_PF_bit			wan_cmd.wan_cmd_hdlc_PF_bit
-#define wan_udphdr_fr_dlci			wan_cmd.wan_cmd_fr_dlci
-#define wan_udphdr_fr_attr			wan_cmd.wan_cmd_fr_attr	
-#define wan_udphdr_fr_rxlost1			wan_cmd.wan_cmd_fr_rxlost1
-#define wan_udphdr_fr_rxlost2			wan_cmd.wan_cmd_fr_rxlost2
-#define wan_udphdr_x25_pf			wan_cmd.wan_cmd_x25_pf
-#define wan_udphdr_x25_lcn			wan_cmd.wan_cmd_x25_lcn			
-#define wan_udphdr_x25_qdm			wan_cmd.wan_cmd_x25_qdm	
-#define wan_udphdr_x25_cause			wan_cmd.wan_cmd_x25_cause
-#define wan_udphdr_x25_diagn			wan_cmd.wan_cmd_x25_diagn
-#define wan_udphdr_x25_pktType			wan_cmd.wan_cmd_x25_pktType
-#define wan_udphdr_bscstrm_misc_bits		wan_cmd.wan_cmd_bscstrm_misc_bits
-#define wan_udphdr_bscstrm_Rx_err_bits		wan_cmd.wan_cmd_bscstrm_Rx_err_bits
-#define wan_udphdr_bscstrm_Rx_time_stamp	wan_cmd.wan_cmd_bscstrm_Rx_time_stamp
-#define wan_udphdr_bscstrm_port			wan_cmd.wan_cmd_bscstrm_port
-#define wan_udphdr_bsc_misc_bits		wan_cmd.wan_cmd_bsc_misc_bit
-#define wan_udphdr_bsc_misc_heading_len		wan_cmd.wan_cmd_bsc_misc_heading_len
-#define wan_udphdr_bsc_misc_notify		wan_cmd.wan_cmd_bsc_misc_notify
-#define wan_udphdr_bsc_misc_station		wan_cmd.wan_cmd_bsc_misc_station
-#define wan_udphdr_bsc_misc_poll_add		wan_cmd.wan_cmd_bsc_misc_poll_addr
-#define wan_udphdr_bsc_misc_select_addr		wan_cmd.wan_cmd_bsc_misc_select_addr
-#define wan_udphdr_bsc_misc_device_addr		wan_cmd.wan_cmd_bsc_misc_device_addr
-#define wan_udphdr_chdlc_num_frames		wan_udphdr_u.chdlc.trace_info.num_frames
-#define wan_udphdr_chdlc_ismoredata		wan_udphdr_u.chdlc.trace_info.ismoredata
-#define wan_udphdr_chdlc_data			wan_udphdr_u.chdlc.data
-
-#define wan_udphdr_bitstrm_num_frames		wan_udphdr_u.bitstrm.trace_info.num_frames
-#define wan_udphdr_bitstrm_ismoredata		wan_udphdr_u.bitstrm.trace_info.ismoredata
-#define wan_udphdr_bitstrm_data			wan_udphdr_u.bitstrm.data
-
-#define wan_udphdr_adsl_num_frames		wan_udphdr_u.adsl.trace_info.num_frames
-#define wan_udphdr_adsl_ismoredata		wan_udphdr_u.adsl.trace_info.ismoredata
-#define wan_udphdr_adsl_data			wan_udphdr_u.adsl.data
-#define wan_udphdr_atm_num_frames		wan_udphdr_u.atm.trace_info.num_frames
-#define wan_udphdr_atm_ismoredata		wan_udphdr_u.atm.trace_info.ismoredata
-#define wan_udphdr_atm_data			wan_udphdr_u.atm.data
-#define wan_udphdr_ss7_num_frames		wan_udphdr_u.ss7.trace_info.num_frames
-#define wan_udphdr_ss7_ismoredata		wan_udphdr_u.ss7.trace_info.ismoredata
-#define wan_udphdr_ss7_data			wan_udphdr_u.ss7.data
-#define wan_udphdr_aft_num_frames		wan_udphdr_u.aft.trace_info.num_frames
-#define wan_udphdr_aft_ismoredata		wan_udphdr_u.aft.trace_info.ismoredata
-#define wan_udphdr_aft_data			wan_udphdr_u.aft.data	
-#if defined(__WINDOWS__)
-# define wan_udphdr_data			wan_udphdr_aft_data
-#else
-# define wan_udphdr_data			wan_udphdr_u.data
-#endif
-} wan_udp_hdr_t;
-
-
 #ifdef WAN_KERNEL
 
-#if 0
-#if defined(__LINUX__)
-# include <linux/wanpipe_events.h>
-#elif defined(__FreeBSD__) || defned(__OpenBSD__)
-# include <wanpipe_events.h>
-#endif
-#endif
 
 /*
 ******************************************************************
@@ -795,9 +361,18 @@
 #elif defined(__WINDOWS__)
 /******************* W I N D O W S ******************************/
 # define ETHER_ADDR_LEN		6
-# define WP_DELAY(usecs)	KeStallExecutionProcessor(usecs);/* usecs is in MicroSeconds */
-# define SYSTEM_TICKS		get_systemticks()
+# define WP_DELAY(usecs)						\
+{												\
+	unsigned long i, j = usecs / 50;			\
+	for(i = 0; i < j; i++){						\
+		KeStallExecutionProcessor(50);			\
+	}											\
+	KeStallExecutionProcessor((usecs % 50));	\
+}
+
+# define SYSTEM_TICKS	get_systemticks()
 # define jiffies		SYSTEM_TICKS
+
 # define wan_atomic_read	atomic_read
 # define wan_atomic_set		atomic_set
 # define wan_atomic_inc		atomic_inc
@@ -805,18 +380,21 @@
 # define RW_LOCK_UNLOCKED	0
 typedef int			wan_ioctl_cmd_t;
 
-/* this macro allowed only at IRQL = PASSIVE_LEVEL */
-/* Convert timeout in Milliseconds to relative timeout in 100ns units
-suitable as parameter 5 to KeWaitForSingleObject(..., TimeOut). */
-#define WP_MILLISECONDS_DELAY(ms_delay){			\
-	KEVENT		WaitEvent;				\
-	LARGE_INTEGER	TimeOut;				\
-								\
+/* This macro allowed only at IRQL <= PASSIVE_LEVEL.
+ * Convert timeout in Milliseconds to relative timeout in 100ns units
+ * suitable as parameter 5 to KeWaitForSingleObject(..., TimeOut). */
+#define WP_MILLISECONDS_DELAY(ms_delay){		\
+	KEVENT		WaitEvent;						\
+	LARGE_INTEGER	TimeOut;					\
+												\
 	KeInitializeEvent(&WaitEvent, NotificationEvent, FALSE);\
 	TimeOut.QuadPart = -( (LONGLONG) (ms_delay)*10*1000 );	\
 	KeWaitForSingleObject(&WaitEvent, Executive, KernelMode, FALSE, &TimeOut);\
 }
-#endif
+
+# define WP_SCHEDULE(arg,name)	WP_MILLISECONDS_DELAY(arg)
+
+#endif /* __WINDOWS__ */
 
 #if defined(__FreeBSD__)
 # define WAN_MODULE_VERSION(module, version)			\
@@ -1057,10 +635,6 @@
 #elif defined(__WINDOWS__)
 /**************************** W I N D O W S **********************************/
 
-/*********************************************************************/
-
-/*********************************************************************/
-
 typedef struct sk_buff		netskb_t;
 typedef struct sk_buff_head	wan_skb_queue_t;
 
@@ -1071,25 +645,17 @@
     u16 EtherType;
 } ethhdr_t;
 
-typedef void*			wan_timer_arg_t;
-typedef PKDEFERRED_ROUTINE	wan_tasklet_func_t;
-typedef PKDEFERRED_ROUTINE	wan_taskq_func_t;
-
-typedef struct _wan_timer_info_t{
-	KTIMER			Timer;
-	KDPC			TimerDpcObject;
-	LARGE_INTEGER		TimerDueTime;
-}wan_timer_info_t;
-
-typedef void (*wan_timer_func_t)(IN PKDPC Dpc, void* context, void * arg2, void * arg3);
 
 typedef struct { ULONG counter; } atomic_t;
 
-typedef int 			wan_rwlock_t;
-typedef int			wan_rwlock_flag_t;
-typedef int			pid_t;
+typedef int		wan_rwlock_t;
+typedef int		wan_rwlock_flag_t;
+typedef int		pid_t;
+typedef void	(wan_pci_ifunc_t)(void*);
+
 #endif
 
+
 /*
  * Spin Locks
  */
@@ -1132,9 +698,9 @@
 typedef struct _wan_dma_descr_org
 {
 	unsigned long*		vAddr;
-        unsigned long		pAddr;
-        unsigned long		length;
-        unsigned long		max_length;
+    unsigned long		pAddr;
+    unsigned long		length;
+    unsigned long		max_length;
 #if defined(__FreeBSD__)
 	bus_dma_tag_t		dmat;
 	bus_dmamap_t		dmamap;
@@ -1146,6 +712,8 @@
 	bus_dma_tag_t		dmat;
 	bus_dma_segment_t	dmaseg;
 	int			rsegs;
+#elif defined(__WINDOWS__)
+	PDMA_ADAPTER	DmaAdapterObject;
 #else	/* other OS */
 #endif
 } wan_dma_descr_org_t;/*, *PDMA_DESCRIPTION;*/
@@ -1170,7 +738,7 @@
 #endif
 } wan_tasklet_t;
 
-#ifndef __LINUX__
+#if !defined(__LINUX__) && !defined(__WINDOWS__)
 typedef struct _wan_taskq
 {
 	unsigned char		running;
@@ -1188,8 +756,6 @@
 # else
         struct work_struct 	tqueue;
 # endif
-#elif  defined(__WINDOWS__)
-	KDPC 	tqueue;
 #elif  defined(__SOLARIS__)
 #error "_wan_taskq: not defined in solaris"
 #endif
@@ -1205,6 +771,7 @@
 	unsigned int   		max_trace_queue;
 	unsigned char		last_trace_direction;
 	u_int32_t		missed_idle_rx_counter;
+	u_int32_t		time_stamp;
 }wan_trace_t;
 
 
@@ -1212,6 +779,7 @@
 /*
 ** TIMER structure
 */
+#if !defined(__WINDOWS__)
 typedef struct _wan_timer
 {
 #define NDIS_TIMER_TAG 0xBEEF0005
@@ -1222,11 +790,11 @@
 	wan_timer_info_t	timer_info;
 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	wan_timer_func_t	timer_func;
-#elif defined(__WINDOWS__)
-	wan_timer_func_t	timer_func;
 #endif
 	void*			timer_arg;
 } wan_timer_t;
+#endif
+
 
 #if !defined(LINUX_2_6) && !defined(__WINDOWS__)
 /* Define this structure for BSDs and not Linux-2.6 */
@@ -1245,84 +813,6 @@
 #endif
 
 
-
-/****** DEFINITION OF UDP HEADER AND STRUCTURE PER PROTOCOL *******/
-typedef struct wan_udp_pkt {
-	iphdr_t		ip_hdr;
-	udphdr_t	udp_hdr;
-	wan_udp_hdr_t	wan_udp_hdr;
-
-
-#define wan_ip				ip_hdr
-#define wan_ip_v			ip_hdr.w_ip_v
-#define wan_ip_hl			ip_hdr.w_ip_hl
-#define wan_ip_tos			ip_hdr.w_ip_tos
-#define wan_ip_len			ip_hdr.w_ip_len
-#define wan_ip_id			ip_hdr.w_ip_id
-#define wan_ip_off			ip_hdr.w_ip_off
-#define wan_ip_ttl			ip_hdr.w_ip_ttl
-#define wan_ip_p			ip_hdr.w_ip_p
-#define wan_ip_sum			ip_hdr.w_ip_sum
-#define wan_ip_src			ip_hdr.w_ip_src
-#define wan_ip_dst			ip_hdr.w_ip_dst
-#define wan_udp_sport			udp_hdr.w_udp_sport
-#define wan_udp_dport			udp_hdr.w_udp_dport
-#define wan_udp_len			udp_hdr.w_udp_len
-#define wan_udp_sum			udp_hdr.w_udp_sum
-#define wan_udp_cmd			wan_udp_hdr.wan_cmd
-#define wan_udp_signature		wan_udp_hdr.wan_udphdr_signature
-#define wan_udp_request_reply		wan_udp_hdr.wan_udphdr_request_reply
-#define wan_udp_id			wan_udp_hdr.wan_udphdr_id
-#define wan_udp_opp_flag		wan_udp_hdr.wan_udphdr_opp_flag
-#define wan_udp_command			wan_udp_hdr.wan_udphdr_command
-#define wan_udp_data_len		wan_udp_hdr.wan_udphdr_data_len
-#define wan_udp_return_code		wan_udp_hdr.wan_udphdr_return_code
-#define wan_udp_hdlc_PF_bit 		wan_udp_hdr.wan_udphdr_hdlc_PF_bit
-#define wan_udp_fr_dlci 		wan_udp_hdr.wan_udphdr_fr_dlci
-#define wan_udp_fr_attr 		wan_udp_hdr.wan_udphdr_fr_attr
-#define wan_udp_fr_rxlost1 		wan_udp_hdr.wan_udphdr_fr_rxlost1
-#define wan_udp_fr_rxlost2 		wan_udp_hdr.wan_udphdr_fr_rxlost2
-#define wan_udp_x25_pf 			wan_udp_hdr.wan_udphdr_x25_pf	
-#define wan_udp_x25_lcn 		wan_udp_hdr.wan_udphdr_x25_lcn	
-#define wan_udp_x25_qdm 		wan_udp_hdr.wan_udphdr_x25_qdm
-#define wan_udp_x25_cause 		wan_udp_hdr.wan_udphdr_x25_cause
-#define wan_udp_x25_diagn 		wan_udp_hdr.wan_udphdr_x25_diagn
-#define wan_udp_x25_pktType 		wan_udp_hdr.wan_udphdr_x25_pktType
-#define wan_udp_bscstrm_misc_bits 	wan_udp_hdr.wan_udphdr_bscstrm_misc_bits
-#define wan_udp_bscstrm_Rx_err_bits 	wan_udp_hdr.wan_udphdr_bscstrm_Rx_err_bits
-#define wan_udp_bscstrm_Rx_time_stam 	wan_udp_hdr.wan_udphdr_bscstrm_Rx_time_stamp
-#define wan_udp_bscstrm_port 		wan_udp_hdr.wan_udphdr_bscstrm_port
-#define wan_udp_bsc_misc_bits 		wan_udp_hdr.wan_udphdr_bsc_misc_bits
-#define wan_udp_bsc_misc_heading_len  	wan_udp_hdr.wan_udphdr_bsc_misc_heading_len
-#define wan_udp_bsc_misc_notify 	wan_udp_hdr.wan_udphdr_bsc_misc_notify
-#define wan_udp_bsc_misc_station 	wan_udp_hdr.wan_udphdr_bsc_misc_station
-#define wan_udp_bsc_misc_poll_add 	wan_udp_hdr.wan_udphdr_bsc_misc_poll_add
-#define wan_udp_bsc_misc_select_addr 	wan_udp_hdr.wan_udphdr_bsc_misc_select_addr
-#define wan_udp_bsc_misc_device_addr 	wan_udp_hdr.wan_udphdr_bsc_misc_device_addr
-#define wan_udp_bsc_misc_notify_ext 	wan_udp_hdr.wan_udphdr_bsc_misc_notify_ext
-#define wan_udp_chdlc_num_frames	wan_udp_hdr.wan_udphdr_chdlc_num_frames
-#define wan_udp_chdlc_ismoredata	wan_udp_hdr.wan_udphdr_chdlc_ismoredata
-#define wan_udp_chdlc_data		wan_udp_hdr.wan_udphdr_chdlc_data
-
-#define wan_udp_bitstrm_num_frames	wan_udp_hdr.wan_udphdr_bitstrm_num_frames
-#define wan_udp_bitstrm_ismoredata	wan_udp_hdr.wan_udphdr_bitstrm_ismoredata
-#define wan_udp_bitstrm_data		wan_udp_hdr.wan_udphdr_bitstrm_data
-
-#define wan_udp_adsl_num_frames		wan_udp_hdr.wan_udphdr_adsl_num_frames
-#define wan_udp_adsl_ismoredata		wan_udp_hdr.wan_udphdr_adsl_ismoredata
-#define wan_udp_adsl_data		wan_udp_hdr.wan_udphdr_adsl_data
-#define wan_udp_atm_num_frames		wan_udp_hdr.wan_udphdr_atm_num_frames
-#define wan_udp_atm_ismoredata		wan_udp_hdr.wan_udphdr_atm_ismoredata	
-#define wan_udp_atm_data		wan_udp_hdr.wan_udphdr_atm_data
-#define wan_udp_ss7_num_frames		wan_udp_hdr.wan_udphdr_ss7_num_frames
-#define wan_udp_ss7_ismoredata		wan_udp_hdr.wan_udphdr_ss7_ismoredata	
-#define wan_udp_ss7_data		wan_udp_hdr.wan_udphdr_ss7_data
-#define wan_udp_aft_num_frames		wan_udp_hdr.wan_udphdr_aft_num_frames
-#define wan_udp_aft_ismoredata		wan_udp_hdr.wan_udphdr_aft_ismoredata	
-#define wan_udp_data			wan_udp_hdr.wan_udphdr_data
-} wan_udp_pkt_t;
-
-
 #pragma pack(1)
 #if defined(WAN_BIG_ENDIAN) || (1)
 
Only in /usr/include/wanpipe/: wanpipe_dsp.h
diff -dur include/wanpipe_ec_kernel.h /usr/include/wanpipe/wanpipe_ec_kernel.h
--- include/wanpipe_ec_kernel.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_ec_kernel.h	2009-07-14 13:02:00.000000000 -0400
@@ -16,9 +16,8 @@
 #ifndef __WANPIPE_EC_KERNEL_H
 # define __WANPIPE_EC_KERNEL_H
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-#elif defined(__LINUX__)
-# include <linux/wanpipe_tdm_api.h>
+#if defined(__LINUX__)
+# include "wanpipe_tdm_api.h"
 #endif
 
 #if defined(WAN_KERNEL)
diff -dur include/wanpipe_events.h /usr/include/wanpipe/wanpipe_events.h
--- include/wanpipe_events.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_events.h	2009-07-14 13:02:00.000000000 -0400
@@ -42,11 +42,13 @@
 		((port) == WAN_EC_CHANNEL_PORT_ROUT)	? "ROUT" :	\
 		((port) == WAN_EC_CHANNEL_PORT_RIN)	? "RIN"  : "Unknown"
 
-#define WAN_EVENT_RXHOOK_OFF		0x01
-#define WAN_EVENT_RXHOOK_ON		0x02
+#define WAN_EVENT_RXHOOK_OFF			0x01
+#define WAN_EVENT_RXHOOK_ON				0x02
+#define WAN_EVENT_RXHOOK_FLASH		0x03
 #define WAN_EVENT_RXHOOK_DECODE(hook)					\
 		((hook) == WAN_EVENT_RXHOOK_OFF) ? "Off-hook" :		\
 		((hook) == WAN_EVENT_RXHOOK_ON)  ? "On-hook" :		\
+		((hook) == WAN_EVENT_RXHOOK_FLASH)  ? "Flash-hook" :		\
 							"Unknown"
 
 #define WAN_EVENT_RING_PRESENT		0x01
@@ -69,8 +71,20 @@
 		((status) == WAN_EVENT_LINK_STATUS_DISCONNECTED)  ? "Disconnected" :		\
 							"Unknown"
 
+/*FXO polarity Reversal */
+#define WAN_EVENT_POLARITY_REV_POSITIVE_NEGATIVE	0x01
+#define WAN_EVENT_POLARITY_REV_NEGATIVE_POSITIVE	0x02
+#define WAN_EVENT_POLARITY_REV_DECODE(status)					\
+		((status) == WAN_EVENT_POLARITY_REV_POSITIVE_NEGATIVE) ? "Positive to Negative" :		\
+		((status) == WAN_EVENT_POLARITY_REV_NEGATIVE_POSITIVE)  ? "Negative to Positive" :		\
+							"Unknown"
+	
 #if defined(WAN_KERNEL)
 
+#include "wanpipe_debug.h"
+#include "wanpipe_defines.h"
+#include "wanpipe_common.h"
+
 /* Global Event defines 			*/
 #define WAN_EVENT_ENABLE	0x01
 #define WAN_EVENT_DISABLE	0x02
@@ -80,7 +94,7 @@
 						"(Unknown mode)"
 
 /* Event type list */
-#define WAN_EVENT_EC_DTMF		0x0001
+#define WAN_EVENT_EC_DTMF		0x0001	/* WAN_EVENT_EC_TONE_DTMF */
 #define WAN_EVENT_RM_POWER		0x0002
 #define WAN_EVENT_RM_LC			0x0003
 #define WAN_EVENT_RM_RING_TRIP		0x0004
@@ -100,6 +114,7 @@
 #define WAN_EVENT_EC_H100_REPORT	0x0012
 #define WAN_EVENT_BRI_CHAN_LOOPBACK	0x0013
 #define WAN_EVENT_LINK_STATUS		0x0014
+#define WAN_EVENT_RM_POLARITY_REVERSE 	0x0016
 	
 
 #define WAN_EVENT_TYPE_DECODE(type)					\
@@ -122,18 +137,19 @@
 		((type) == WAN_EVENT_EC_CHAN_MODIFY)	? "EC Chan Modify" :	\
 		((type) == WAN_EVENT_BRI_CHAN_LOOPBACK)	? "BRI B-Chan Loopback" :	\
 		((type) == WAN_EVENT_LINK_STATUS)	? "Link Status" :	\
+		((type) == WAN_EVENT_RM_POLARITY_REVERSE)	? "RM Polarity Reverse" :	\
 							"(Unknown type)"
 
 /* tone type list */						
-#define	WAN_EVENT_TONE_DIAL		0x01
-#define	WAN_EVENT_TONE_BUSY		0x02
-#define	WAN_EVENT_TONE_RING		0x03
-#define	WAN_EVENT_TONE_CONGESTION	0x04
+#define	WAN_EVENT_RM_TONE_TYPE_DIAL		0x01
+#define	WAN_EVENT_RM_TONE_TYPE_BUSY		0x02
+#define	WAN_EVENT_RM_TONE_TYPE_RING		0x03
+#define	WAN_EVENT_RM_TONE_TYPE_CONGESTION	0x04
 #define WAN_EVENT_TONE_DECODE(tone)					\
-		((tone) == WAN_EVENT_TONE_DIAL)		? "Dial tone" :	\
-		((tone) == WAN_EVENT_TONE_BUSY)		? "Busy tone" :	\
-		((tone) == WAN_EVENT_TONE_RING)		? "Ring tone" :	\
-		((tone) == WAN_EVENT_TONE_CONGESTION)	? "Congestion tone" :	\
+		((tone) == WAN_EVENT_RM_TONE_TYPE_DIAL)		? "Dial tone" :	\
+		((tone) == WAN_EVENT_RM_TONE_TYPE_BUSY)		? "Busy tone" :	\
+		((tone) == WAN_EVENT_RM_TONE_TYPE_RING)		? "Ring tone" :	\
+		((tone) == WAN_EVENT_RM_TONE_TYPE_CONGESTION)	? "Congestion tone" :	\
 						"(Unknown tone)"
 
 /* Event information			*/
@@ -141,15 +157,17 @@
 {
 	u_int16_t	type;
 	u_int8_t	mode;		/* Enable/Disable */
-	int		channel;	/* A200-mod_no, T1/E1-fe chan  */
-	unsigned char	digit;		/* DTMF: digit  */
-	unsigned char	dtmf_type;	/* DTMF: PRESETN/STOP */
-	unsigned char	dtmf_port;	/* DTMF: ROUT/SOUT */
+	u_int8_t	channel;	/* A200-mod_no, T1/E1-fe chan  */
+	unsigned char	digit;		/* TONE: digit, 'f' -  for fax  */
+	unsigned char	tone_type;	/* TONE: PRESETN/STOP */
+	unsigned char	tone_port;	/* TONE: ROUT/SOUT */
 
 	unsigned char	rxhook;		/* LC: OFF-HOOK or ON-HOOK */
 
 	unsigned char	ring_mode;	/* RingDetect: Present/Stop */
 	unsigned char	link_status;    /* Link Status */
+	unsigned char   polarity_reverse; /*Polarity Reverse detection */
+	unsigned int	alarms;
 		
 } wan_event_t;
 
@@ -160,7 +178,7 @@
 	u_int8_t	mode;
 	int		mod_no;		/* A200-Remora */
 	int		channel;
-	unsigned char	ec_dtmf_port;	/* EC DTMF: SOUT or ROUT */
+	unsigned char	ec_tone_port;	/* EC DTMF: SOUT or ROUT */
 	unsigned long	ts_map;
 	u_int8_t	tone;
 	int		ohttimer;	/* On-hook transfer */
diff -dur include/wanpipe.h /usr/include/wanpipe/wanpipe.h
--- include/wanpipe.h	2009-07-07 12:45:21.000000000 -0400
+++ /usr/include/wanpipe/wanpipe.h	2009-07-14 13:02:00.000000000 -0400
@@ -43,32 +43,17 @@
 #ifndef	_WANPIPE_H
 #define	_WANPIPE_H
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-#include <wanpipe_defines.h>
-#include <wanpipe_debug.h>
-#include <wanpipe_common.h>
-#include <wanpipe_events.h>
-#include <wanpipe_cfg.h>
-# include <wanrouter.h>
-#elif defined(__WINDOWS__)
-#if defined (__KERNEL__)
-# include <wanpipe_defines.h>
-# include <wanpipe_debug.h>
-# include <wanpipe_common.h>
-# include <wanpipe_events.h>
-# include <wanpipe_cfg.h>
-# include <wanrouter.h>
-# include <wanpipe_structs.h>
-#endif
-#elif defined(__LINUX__) || defined (__KERNEL__)
-#include <linux/wanpipe_defines.h>
-#include <linux/wanpipe_debug.h>
-#include <linux/wanpipe_common.h>
-#include <linux/wanpipe_events.h>
-#include <linux/wanpipe_cfg.h>
-#include <linux/wanrouter.h>
-#else
-# error "No OS Specified"
+#include "wanpipe_api.h"
+#include "wanpipe_defines.h"
+#include "wanpipe_debug.h"
+#include "wanpipe_common.h"
+#include "wanpipe_events.h"
+#include "wanpipe_cfg.h"
+#include "wanrouter.h"
+
+
+#if defined(__WINDOWS__) && defined (__KERNEL__)
+# include "wanpipe_structs.h"
 #endif
 
 /* Due to changes between 2.4.9 and 2.4.13,
@@ -121,14 +106,7 @@
 		}
 #endif
 
-#define TRACE_ALL                       0x00
-#define TRACE_PROT			0x01
-#define TRACE_DATA			0x02
 
-/* values for request/reply byte */
-#define UDPMGMT_REQUEST	0x01
-#define UDPMGMT_REPLY	0x02
-#define UDP_OFFSET	12
 
 #define MAX_CMD_BUFF 	10
 #define MAX_X25_LCN 	255	/* Maximum number of x25 channels */
@@ -200,80 +178,9 @@
  Data Structure for global statistics
 *************************************************************************/
 
-typedef struct global_stats
-{
-	unsigned long isr_entry;
-	unsigned long isr_already_critical;		
-	unsigned long isr_rx;
-	unsigned long isr_tx;
-	unsigned long isr_intr_test;
-	unsigned long isr_spurious;
-	unsigned long isr_enable_tx_int;
-	unsigned long rx_intr_corrupt_rx_bfr;
-	unsigned long rx_intr_on_orphaned_DLCI;
-	unsigned long rx_intr_dev_not_started;
-	unsigned long tx_intr_dev_not_started;
-	unsigned long poll_entry;
-	unsigned long poll_already_critical;
-	unsigned long poll_processed;
-	unsigned long poll_tbusy_bad_status;
-	unsigned long poll_host_disable_irq;
-	unsigned long poll_host_enable_irq;
-
-} global_stats_t;
-
-/*************************************************************************
- Data Structure for if_send  statistics
-*************************************************************************/  
-typedef struct if_send_stat{
-	unsigned long if_send_entry;
-	unsigned long if_send_skb_null;
-	unsigned long if_send_broadcast;
-	unsigned long if_send_multicast;
-	unsigned long if_send_critical_ISR;
-	unsigned long if_send_critical_non_ISR;
-	unsigned long if_send_tbusy;
-	unsigned long if_send_tbusy_timeout;
-	unsigned long if_send_PIPE_request;
-	unsigned long if_send_wan_disconnected;
-	unsigned long if_send_dlci_disconnected;
-	unsigned long if_send_no_bfrs;
-	unsigned long if_send_adptr_bfrs_full;
-	unsigned long if_send_bfr_passed_to_adptr;
-	unsigned long if_send_protocol_error;
-       	unsigned long if_send_bfr_not_passed_to_adptr;
-       	unsigned long if_send_tx_int_enabled;
-        unsigned long if_send_consec_send_fail; 
-} if_send_stat_t;
-
-typedef struct rx_intr_stat{
-	unsigned long rx_intr_no_socket;
-	unsigned long rx_intr_dev_not_started;
-	unsigned long rx_intr_PIPE_request;
-	unsigned long rx_intr_bfr_not_passed_to_stack;
-	unsigned long rx_intr_bfr_passed_to_stack;
-} rx_intr_stat_t;	
-
-typedef struct pipe_mgmt_stat{
-	unsigned long UDP_PIPE_mgmt_kmalloc_err;
-	unsigned long UDP_PIPE_mgmt_direction_err;
-	unsigned long UDP_PIPE_mgmt_adptr_type_err;
-	unsigned long UDP_PIPE_mgmt_adptr_cmnd_OK;
-	unsigned long UDP_PIPE_mgmt_adptr_cmnd_timeout;
-	unsigned long UDP_PIPE_mgmt_adptr_send_passed;
-	unsigned long UDP_PIPE_mgmt_adptr_send_failed;
-	unsigned long UDP_PIPE_mgmt_not_passed_to_stack;
-	unsigned long UDP_PIPE_mgmt_passed_to_stack;
-	unsigned long UDP_PIPE_mgmt_no_socket;
-        unsigned long UDP_PIPE_mgmt_passed_to_adptr;
-} pipe_mgmt_stat_t;
-
-
 typedef struct {
 	struct sk_buff *skb;
 } bh_data_t, cmd_data_t;
-
-#define MAX_LGTH_UDP_MGNT_PKT WAN_MAX_DATA_SIZE
  
 
 /* This is used for interrupt testing */
@@ -290,20 +197,19 @@
 #if defined(WAN_KERNEL)
 /****** Kernel Interface ****************************************************/
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <wanpipe_debug.h>	/* WANPIPE Debugging messages */
-# include <wanpipe_kernel.h>
-# include <sdlasfm.h>
-# include <sdladrv.h>
-# include <wanpipe_common.h>
-#elif defined(__LINUX__)
-# include <linux/wanpipe_kernel.h>
+#include "wanpipe_includes.h"
+#include "wanpipe_defines.h"
+#include "wanpipe_debug.h"
+#include "wanpipe_common.h"
+#include "wanpipe_cfg.h"
+#include "wanpipe_kernel.h"
+#include "sdlasfm.h"
+#include "sdladrv.h"
+
+#if defined(__LINUX__)
 # ifndef KERNEL_VERSION
 #  define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 # endif
-# include <linux/wanpipe_debug.h>
-# include <linux/sdlasfm.h>	/* SDLA firmware module definitions */
-# include <linux/sdladrv.h>	/* SDLA support module API definitions */
 
 # if defined(LINUX_2_6)
 #  include <linux/workqueue.h>
@@ -311,28 +217,22 @@
 #  include <linux/tqueue.h>
 # endif
 
-# include <linux/wanpipe_common.h>
 # if defined(LINUX_2_4) || defined(LINUX_2_6)
 #  include <linux/serial.h>
 #  include <linux/serialP.h>
 #  include <linux/serial_reg.h>
 #  include <asm/serial.h>
 # endif
+
 # include <linux/tty.h>
 # include <linux/tty_driver.h>
 # include <linux/tty_flip.h>
-#elif defined(__WINDOWS__)
-# include <wanpipe_debug.h>
-# include <wanpipe_kernel.h>
-# include <sdlasfm.h>	/* SDLA firmware module definitions */
-# include <sdladrv.h>	/* SDLA support module API definitions */
-# include <wanpipe_common.h>
 #endif
 
 #define MAX_E1_CHANNELS 32
 
 #if defined(__WINDOWS__)
-#define MAX_FR_CHANNELS	MAX_NUMBER_OF_PROTOCOL_INTERFACES /*1023*/
+#define MAX_FR_CHANNELS	MAX_NUMBER_OF_PROTOCOL_INTERFACES /*100*/
 #else
 #define MAX_FR_CHANNELS (1007+1)
 #endif
@@ -708,7 +608,7 @@
 	unsigned long logic_ch_map;
 	unsigned char num_of_time_slots;
 	unsigned char top_logic_ch;
-	unsigned long bar;
+	sdla_base_addr_t bar;
 	void *trace_info;
 	void *dev_to_ch_map[MAX_E1_CHANNELS];
 	void *rx_dma_ptr;
@@ -746,15 +646,15 @@
 	unsigned int	tdmv_chan;	
 	unsigned int	tdmv_dchan;	
 	unsigned int	tdmv_dchan_active_ch;
-	void 		*tdmv_chan_ptr;
+	void 			*tdmv_chan_ptr;
 
-	unsigned char	tdmv_hw_dtmf;
+	unsigned char	tdmv_hw_tone;
 	
 	unsigned char	led_ctrl;
 	unsigned int	tdm_intr_status;
-	void 		*bar_virt;
-	unsigned short	tdm_rx_dma_toggle;
-	unsigned short	tdm_tx_dma_toggle;
+	sdla_mem_handle_t	bar_virt;
+	unsigned char	tdm_rx_dma_toggle[32];
+	unsigned char	tdm_tx_dma_toggle[32];
 	unsigned int	tdm_logic_ch_map;
 
 	wan_ticks_t	sec_chk_cnt;
@@ -764,7 +664,18 @@
 
 } sdla_xilinx_t;
 
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+typedef struct
+{
+	unsigned char	num_of_time_slots;
+	wan_taskq_t 	port_task;
+	unsigned int 	port_task_cmd;
+	void		*dev_to_ch_map[10];		// temporary
+	unsigned int	tdm_logic_ch_map;
 
+} wp_usb_t;
+#endif
+ 
 enum {
 	AFT_CHIP_CONFIGURED,
 	AFT_FRONT_END_UP,
@@ -873,6 +784,9 @@
 		sdla_adsl_t	adsl;
 		sdla_xilinx_t	aft;
 		sdla_debug_t	debug;
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+		wp_usb_t	usb;
+#endif
 	} u;
 	unsigned char irq_equalize;
 
@@ -897,6 +811,7 @@
 	
 	sdla_fe_t	fe;		/* front end structures */
 	u8		fe_no_intr;	/* set to 0x01 if not FE interrupt should enabled */		
+	u8		fe_ignore_intr;	/* Set to 0x01 if all FE interrupts should be ignored */
 	
 	unsigned int	rCount;
 
@@ -973,18 +888,29 @@
  	/* This value is used for detecting TDM Voice
 	* rsync timeout, it should be long */
 	wan_ticks_t   rsync_timeout;
-
+	
 	/* This value is used for detecting Fronte end interrupt
-	* timeout, it should be long */
+	 * timeout, it should be long */
 	wan_ticks_t   front_end_irq_timeout;
 
 	/* SDLA TDMV Dummy interface */
 #if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE)
-        void* sdla_tdmv_dummy;
+	void* sdla_tdmv_dummy;
 #endif
+	void* wp_tdmapi_hash[MAX_E1_CHANNELS];
 
-	unsigned char wp_debug_chan_seq;
+	unsigned char  card_no;	
+#if defined(__WINDOWS__)
+	PDMA_ADAPTER	DmaAdapterObject;  /* Object for allocating memory for DMA.
+										* Can NOT be called from spin-locked code!!
+										* (not from regular lock too)	*/
+	wan_debug_t		wan_debug_rx_interrupt_timing;
+	wan_debug_t		wan_debug_tx_interrupt_timing;
+#endif
 
+	void *tdm_api_dev;
+	unsigned char wp_debug_gen_fifo_err;
+	unsigned char wp_debug_chan_seq;
 } sdla_t;
 
 /****** Public Functions ****************************************************/
@@ -1012,7 +938,7 @@
 int wp_pos_init(sdla_t* card, wandev_conf_t* conf);	/* POS Driver */	
 int wp_xilinx_init(sdla_t* card, wandev_conf_t* conf);	/* Xilinx Hardware Support */
 int wp_aft_te1_init(sdla_t* card, wandev_conf_t* conf);	/* Xilinx Hardware Support */
-int wp_aft_a600_init(sdla_t* card, wandev_conf_t* conf);	/* A600 Hardware Support */
+int wp_aft_a600_init(sdla_t* card, wandev_conf_t* conf); /* Xilinx A600 Hardware Support */
 int wp_aft_56k_init(sdla_t* card, wandev_conf_t* conf);	/* Xilinx Hardware Support */
 int wp_aft_analog_init(sdla_t* card, wandev_conf_t* conf);	/* Xilinx Hardware Support */
 int wp_aft_bri_init(sdla_t* card, wandev_conf_t* conf);	/* BRI Hardware Support */
@@ -1023,6 +949,10 @@
 int wp_aft_te1_ss7_init(sdla_t* card, wandev_conf_t* conf); /* AFT TE1 SS7 Hardware Support */
 int aft_global_hw_device_init(void);
 
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+int wp_usb_init(sdla_t* card, wandev_conf_t* conf);
+#endif
+
 int wanpipe_globals_util_init(void); /* Initialize All Global Tables */
 
 #if defined(__LINUX__)
@@ -1032,6 +962,7 @@
 extern unsigned long get_ip_address (netdevice_t *dev, int option);
 extern void add_gateway(sdla_t *, netdevice_t *);
 
+
 #if 0
 extern void fastcall wp_tasklet_hi_schedule_per_cpu(struct tasklet_struct *t, int cpu_no);
 extern void wp_tasklet_per_cpu_init (void);
@@ -1060,14 +991,16 @@
 int wan_snmp_data(sdla_t* card, netdevice_t* dev, int cmd, struct ifreq* ifr);
 
 int wan_capture_trace_packet(sdla_t *card, wan_trace_t* trace_info, netskb_t *skb, char direction);
-int wan_capture_trace_packet_buffer(sdla_t *card, wan_trace_t* trace_info, char *data, int len, char direction);
 int wan_capture_trace_packet_offset(sdla_t *card, wan_trace_t* trace_info, netskb_t *skb, int off,char direction);
+void debug_print_udp_pkt(unsigned char *data,int len,char trc_enabled, char direction);
 
 #if defined(__LINUX__)
+#if 0
 int wan_verify_iovec(struct msghdr *m, struct iovec *iov, char *address, int mode);
 int wan_memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len);
 int wan_memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len);
 #endif
+#endif
 
 /* LIP ATM prototypes */
 int init_atm_idle_buffer(unsigned char *buff, int buff_len, char *if_name, char hardware_flip);
diff -dur include/wanpipe_includes.h /usr/include/wanpipe/wanpipe_includes.h
--- include/wanpipe_includes.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_includes.h	2009-07-14 13:02:00.000000000 -0400
@@ -224,80 +224,81 @@
 # include <netipx/ipx_if.h>
 # include <uvm/uvm_extern.h>
 #elif defined(__LINUX__)
-#ifdef __KERNEL__
+# ifdef __KERNEL__
 /*
 **		***	L I N U X	***
 */
-# include <linux/init.h>
-# include <linux/version.h>	/**/
+#  include <linux/init.h>
+#  include <linux/version.h>	/**/
 
-# if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
-# include <linux/config.h>	/* OS configuration options */
-# endif
+#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
+#   include <linux/config.h>	/* OS configuration options */
+#  endif
 
-# if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
-#  if !(defined __NO_VERSION__) && !defined(_K22X_MODULE_FIX_)
-#   define __NO_VERSION__	
+#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
+#   if !(defined __NO_VERSION__) && !defined(_K22X_MODULE_FIX_)
+#    define __NO_VERSION__	
+#   endif
 #  endif
-# endif
-# if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
   /* Remove experimental SEQ support */
-# define _LINUX_SEQ_FILE_H
-#endif
-# include <linux/module.h>
-# include <linux/types.h>
-# include <linux/sched.h>
-# include <linux/mm.h>
-# include <linux/slab.h>
-# include <linux/stddef.h>	/* offsetof, etc. */
-# include <linux/errno.h>	/* returns codes */
-# include <linux/string.h>	/* inline memset, etc */
-# include <linux/ctype.h>
-# include <linux/kernel.h>	/* printk()m and other usefull stuff */
-# include <linux/timer.h>
-# include <linux/kmod.h>
-# include <net/ip.h>
-# include <net/protocol.h>
-# include <net/sock.h>
-# include <net/route.h>
-# include <linux/fcntl.h>
-# include <linux/skbuff.h>
-# include <linux/socket.h>
-# include <linux/poll.h>
-# include <linux/wireless.h>
-# include <linux/in.h>
-# include <linux/inet.h>
-# include <linux/netdevice.h>
-# include <linux/list.h>
-# include <asm/io.h>		/* phys_to_virt() */
-# include <asm/system.h>
-# include <asm/byteorder.h>
-# include <asm/delay.h>
-# include <linux/pci.h>
-# include <linux/if.h>
-# include <linux/if_arp.h>
-# include <linux/tcp.h>
-# include <linux/ip.h>
-# include <linux/udp.h>
-# include <linux/ioport.h>
-# include <linux/init.h>
-# include <linux/pkt_sched.h>
-# include <linux/etherdevice.h>
-# include <linux/random.h>
-# include <asm/uaccess.h>
-# include <linux/inetdevice.h>
-# include <linux/vmalloc.h>     /* vmalloc, vfree */
-# include <asm/uaccess.h>        /* copy_to/from_user */
-# include <linux/init.h>         /* __initfunc et al. */
-# include <linux/time.h>
-
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
-#  include <linux/seq_file.h>
+#   define _LINUX_SEQ_FILE_H
 # endif
-# ifdef CONFIG_INET
-#  include <net/inet_common.h>
+#  include <linux/module.h>
+#  include <linux/types.h>
+#  include <linux/sched.h>
+#  include <linux/mm.h>
+#  include <linux/slab.h>
+#  include <linux/stddef.h>	/* offsetof, etc. */
+#  include <linux/errno.h>	/* returns codes */
+#  include <linux/string.h>	/* inline memset, etc */
+#  include <linux/ctype.h>
+#  include <linux/kernel.h>	/* printk()m and other usefull stuff */
+#  include <linux/timer.h>
+#  include <linux/kmod.h>
+#  include <net/ip.h>
+#  include <net/protocol.h>
+#  include <net/sock.h>
+#  include <net/route.h>
+#  include <linux/fcntl.h>
+#  include <linux/skbuff.h>
+#  include <linux/socket.h>
+#  include <linux/poll.h>
+#  include <linux/wireless.h>
+#  include <linux/in.h>
+#  include <linux/inet.h>
+#  include <linux/netdevice.h>
+#  include <linux/list.h>
+#  include <asm/io.h>		/* phys_to_virt() */
+#  include <asm/system.h>
+#  include <asm/byteorder.h>
+#  include <asm/delay.h>
+#  include <linux/pci.h>
+# if defined(CONFIG_PRODUCT_WANPIPE_USB)
+#  include <linux/usb.h>
+# endif
+#  include <linux/if.h>
+#  include <linux/if_arp.h>
+#  include <linux/tcp.h>
+#  include <linux/ip.h>
+#  include <linux/udp.h>
+#  include <linux/ioport.h>
+#  include <linux/init.h>
+#  include <linux/pkt_sched.h>
+#  include <linux/etherdevice.h>
+#  include <linux/random.h>
+#  include <asm/uaccess.h>
+#  include <linux/inetdevice.h>
+#  include <linux/vmalloc.h>     /* vmalloc, vfree */
+#  include <asm/uaccess.h>        /* copy_to/from_user */
+#  include <linux/init.h>         /* __initfunc et al. */
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+#   include <linux/seq_file.h>
+#  endif
+#  ifdef CONFIG_INET
+#   include <net/inet_common.h>
+#  endif
 # endif
-#endif
 #elif defined(__SOLARIS__)
 /*
 **		***	S O L A R I S	***
@@ -337,15 +338,17 @@
 
 # if defined(VIRTUAL_IF_DRV) || defined(SPROTOCOL) || defined(BUSENUM_DRV)
 # include <ntddk.h>
-# include <wanpipe_ctypes.h>
-# include <wanpipe_debug.h>
-# include <wanpipe_kernel.h>
-# include <wanpipe_skb.h>
-# include <wanpipe_defines.h>
-# include <wanpipe_common.h>
-# include <wanpipe_cfg.h>
-# include <sdladrv.h>	/* API definitions */
-# include <wanpipe_abstr.h>
+# include "wanpipe_ctypes.h"
+# include "wanpipe_kernel_types.h"
+# include "aft_core_options.h"
+# include "wanpipe_debug.h"
+# include "wanpipe_kernel.h"
+# include "wanpipe_skb.h"
+# include "wanpipe_defines.h"
+# include "wanpipe_common.h"
+# include "wanpipe_cfg.h"
+# include "sdladrv.h"	/* API definitions */
+# include "wanpipe_abstr.h"
 # endif
 
 #if defined( NDIS_MINIPORT_DRIVER )
@@ -354,10 +357,11 @@
 # define NDIS50_MINIPORT   1 
 # include <ntddk.h>
 # include <ndis.h>
-# include <wanpipe_debug.h>
+# include "wanpipe_ctypes.h"
+# include "wanpipe_kernel_types.h"
+# include "wanpipe_debug.h"
 #endif
 
-/*# include <windef.h> - UINT*/
 #else
 # include <windows.h>
 #endif
diff -dur include/wanpipe_kernel.h /usr/include/wanpipe/wanpipe_kernel.h
--- include/wanpipe_kernel.h	2009-07-07 16:35:13.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_kernel.h	2009-07-14 13:02:00.000000000 -0400
@@ -51,7 +51,7 @@
 #endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-#define	cancel_work_sync(work) ({ cancel_work_sync(work); 0; })
+#define cancel_work_sync(work) ({ cancel_work_sync(work); 0; })
 #endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) || defined(LINUX_FEAT_2624)
@@ -111,13 +111,13 @@
 
  #define pci_present() 	1
 
- static inline void wan_schedule_task(struct tq_struct *tq)
+ static inline int wan_schedule_task(struct tq_struct *tq)
  {
-	schedule_work(tq);
+	return schedule_work(tq);
  }
 
 
- static inline int wan_task_dequeue(struct tq_struct *tq)
+ static inline int wan_task_cancel(struct tq_struct *tq)
  {
 #if  LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
 	return cancel_work_sync (tq);
@@ -133,7 +133,15 @@
 	flush_scheduled_work();
 	return err;
 #endif
- }           
+ }
+
+#if 1
+#define MOD_INC_USE_COUNT try_module_get(THIS_MODULE)
+#define MOD_DEC_USE_COUNT module_put(THIS_MODULE)
+#else
+#define MOD_INC_USE_COUNT 
+#define MOD_DEC_USE_COUNT
+#endif
 
 #define ADMIN_CHECK()  {if (!capable(CAP_SYS_ADMIN)) {\
                              if (WAN_NET_RATELIMIT()) { \
@@ -230,11 +238,12 @@
 
  #define __dev_get(a)		dev_get(a)
 
- static inline void wan_schedule_task(struct tq_struct *tq)
+ static inline int wan_schedule_task(struct tq_struct *tq)
  {
-	schedule_task(tq);
+	return schedule_task(tq);
  }
- static inline int wan_task_dequeue(struct tq_struct *tq)
+
+ static inline int wan_task_cancel(struct tq_struct *tq)
  {
 	return 0;
  }
@@ -403,16 +412,17 @@
 	tasklet->data = (void *)data;
  }
 
- static inline void wan_schedule_task(struct tq_struct *tq)
+ static inline int wan_schedule_task(struct tq_struct *tq)
  {
 	queue_task(tq, &tq_scheduler);
+	return 0;
  }
-
- static inline int wan_task_dequeue(struct tq_struct *tq)
+ static inline int wan_task_cancel(struct tq_struct *tq)
  {
 	return 0;
  }
 
+
  /* Setup Dma Memory size copied directly from 3c505.c */
  static inline int __get_order(unsigned long size)
  {
@@ -609,15 +619,12 @@
 #  define WAN_TASKQ_INIT(task, priority, func, arg)	\
 		INIT_WORK((task),func)	
 # endif
-
 # define WAN_IS_TASKQ_SCHEDULE
-
 # define WAN_TASKQ_SCHEDULE(task)			\
 	wan_schedule_task(task)
 
 # define WAN_TASKQ_STOP(task) \
-	wan_task_dequeue(task)
-
+	wan_task_cancel(task)
 
 #else /* __KERNEL__ */
 
@@ -636,8 +643,119 @@
 #endif
 
 
+
+#endif
+
+
+/* For All operating Systems */
+
+#pragma pack(1)         
+
+typedef struct wan_iovec
+{
+	uint32_t iov_len; /* Must be size_t (1003.1g) */
+	void *iov_base;	/* BSD uses caddr_t (1003.1g requires void *) */
+#ifndef __x86_64__
+    uint32_t reserved;
+#endif
+}wan_iovec_t;
+
+typedef struct wan_msghdr {
+	uint32_t	msg_iovlen;	/* Number of blocks		*/
+	wan_iovec_t *	msg_iov;	/* Data blocks			*/
+#ifndef __x86_64__
+    uint32_t reserved;
+#endif
+}wan_msghdr_t;          
+
+#pragma pack()
+
+#if defined(__KERNEL__)
+
+static __inline int wan_verify_iovec(wan_msghdr_t *m, wan_iovec_t *iov, char *address, int mode)
+{
+	int size, err, ct;
+	
+	if (m->msg_iovlen == 0) {
+		return -EMSGSIZE;
+	}
+	
+	size = m->msg_iovlen * sizeof(wan_iovec_t);
+
+	
+	if (copy_from_user(iov, m->msg_iov, size))
+		return -EFAULT;
+
+	m->msg_iov = iov;
+	err = 0;
+
+	for (ct = 0; ct < m->msg_iovlen; ct++) {
+		err += iov[ct].iov_len;
+		/*
+		 * Goal is not to verify user data, but to prevent returning
+		 * negative value, which is interpreted as errno.
+		 * Overflow is still possible, but it is harmless.
+		 */
+		if (err < 0)
+			return -EMSGSIZE;
+	}
+
+	return err;
+}
+      
+ /*
+ *	Copy iovec to kernel. Returns -EFAULT on error.
+ *
+ *	Note: this modifies the original iovec.
+ */
+ 
+static __inline int wan_memcpy_fromiovec(unsigned char *kdata, wan_iovec_t *iov, int len)
+{
+	while (len > 0) {
+		if (iov->iov_len) {
+			int copy = min_t(unsigned int, len, iov->iov_len);
+			if (copy_from_user(kdata, iov->iov_base, copy))
+				return -EFAULT;
+			len -= copy;
+			kdata += copy;
+			iov->iov_base += copy;
+			iov->iov_len -= copy;
+		}
+		iov++;
+	}
+
+	return 0;
+}                
+
+/*
+ *	Copy kernel to iovec. Returns -EFAULT on error.
+ *
+ *	Note: this modifies the original iovec.
+ */
+ 
+static __inline int wan_memcpy_toiovec(wan_iovec_t *iov, unsigned char *kdata, int len)
+{
+	while (len > 0) {
+		if (iov->iov_len) {
+			int copy = min_t(unsigned int, iov->iov_len, len);
+			if (copy_to_user(iov->iov_base, kdata, copy))
+				return -EFAULT;
+			kdata += copy;
+			len -= copy;
+			iov->iov_len -= copy;
+			iov->iov_base += copy;
+		}
+		iov++;
+	}
+
+	return 0;
+}             
+
+
 #endif
 
+
+
 #endif
 
 
Only in include/: .wanpipe_kernel.h.swp
Only in /usr/include/wanpipe/: wanpipe_lapb.h
diff -dur include/wanpipe_lip_atm_iface.h /usr/include/wanpipe/wanpipe_lip_atm_iface.h
--- include/wanpipe_lip_atm_iface.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_lip_atm_iface.h	2009-07-14 13:02:00.000000000 -0400
@@ -13,11 +13,10 @@
 * September 15, 2005	David Rokhvarg	Initial Version
 *****************************************************************************/
 
+
 #ifndef _WANPIPE_LIP_ATM_IFACE_H
 #define _WANPIPE_LIP_ATM_IFACE_H
 
-//#include <linux/wanpipe_cfg.h>
-
 #define wplist_insert_dev(dev, list)	do{\
 	                                   dev->next = list;\
 					   list = dev;\
diff -dur include/wanpipe_lip.h /usr/include/wanpipe/wanpipe_lip.h
--- include/wanpipe_lip.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_lip.h	2009-07-14 13:02:00.000000000 -0400
@@ -3,94 +3,56 @@
 #ifndef _WANPIPE_LIP_HEADER_
 #define _WANPIPE_LIP_HEADER_
 
+#include "wanpipe_includes.h"
+#include "wanpipe_defines.h"
+#include "wanpipe_debug.h"
+#include "wanpipe_common.h"
+#include "wanpipe_abstr.h"
+#include "wanpipe_snmp.h"
+#include "wanproc.h"
+#include "wanpipe.h"
+#include "wanpipe_cfg.h"
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <wanpipe_includes.h>
-# include <wanpipe_defines.h>
-# include <wanpipe_debug.h>
-# include <wanpipe_common.h>
-# include <wanpipe_abstr.h>
-# include <wanpipe_snmp.h>
-# include <wanproc.h>
-# include <wanpipe.h>
-# include <wanpipe_cfg.h>
-# include <if_wanpipe_common.h>
-# include <wanpipe_iface.h>
-# include <wanpipe_lip_kernel.h>
-# include <wanpipe_fr_iface.h>
-# include <wanpipe_sppp_iface.h>
-# if defined(CONFIG_PRODUCT_WANPIPE_LAPB) || defined(CONFIG_PRODUCT_WANPIPE_LIP_LAPD)
-#  include <wanpipe_lapb_iface.h>
-# endif
-# if defined(CONFIG_PRODUCT_WANPIPE_XDLC)
-#  include <wanpipe_xdlc_iface.h>
-# endif
-#elif defined(__WINDOWS__)
-# include <wanpipe_includes.h>
-# include <wanpipe_defines.h>
-# include <wanpipe_debug.h>
-# include <wanpipe_common.h>
-# include <wanpipe_abstr.h>
-# include <wanpipe_snmp.h>
-# include <wanpipe.h>
-# include <wanpipe_cfg.h>
-# include <if_wanpipe_common.h>
-# include <wanpipe_iface.h>
-# include <wanpipe_lip_kernel.h>
-# include <wanpipe_fr_iface.h>
-# include <wanpipe_sppp_iface.h>
-# if defined(CONFIG_PRODUCT_WANPIPE_LAPB) || defined(CONFIG_PRODUCT_WANPIPE_LIP_LAPD)
-#  include <wanpipe_lapb_iface.h>
-# endif
-# if defined(CONFIG_PRODUCT_WANPIPE_XDLC)
-#  include <wanpipe_xdlc_iface.h>
-# endif
-/* Prototypes for interface between LIP and 'sprotocol' code in virt_adap_enum.c: */
-int sdla_tx_down(void* dev, void *tx_skb);
-int sdla_data_rx_up(void* sdla_net_dev, void *rx_skb);
+#if defined (__LINUX__)
+# include "if_wanpipe.h"
+#endif
 
-#else
-# include <linux/wanpipe_includes.h>
-# include <linux/wanpipe_defines.h>
-# include <linux/wanpipe_debug.h>
-# include <linux/wanpipe_common.h>
-# include <linux/wanpipe_abstr.h>
-# include <linux/wanpipe_snmp.h>
-# include <linux/wanproc.h>
-# include <linux/wanpipe.h>
-# include <linux/wanpipe_cfg.h>
-# include <linux/if_wanpipe.h>
-# include <linux/if_wanpipe_common.h>
-# include <linux/wanpipe_fr_iface.h>
-# include <linux/wanpipe_lip_atm_iface.h>
-# include <linux/wanpipe_sppp_iface.h>
-# if defined(CONFIG_PRODUCT_WANPIPE_LAPB) || defined(CONFIG_PRODUCT_WANPIPE_LIP_LAPD)
-#  include <linux/wanpipe_lapb_iface.h>
-# endif 
-# if defined(CONFIG_PRODUCT_WANPIPE_LIP_KATM)
-#  include <linux/wanpipe_katm_iface.h>
-# endif 
-# if defined(CONFIG_PRODUCT_WANPIPE_XDLC)
-#  include <linux/wanpipe_xdlc_iface.h>
-# endif 
-# if defined(CONFIG_PRODUCT_WANPIPE_XMTP2)
-#  include <linux/wanpipe_xmtp2_iface.h>
-# endif 
-# if defined(CONFIG_PRODUCT_WANPIPE_LIP_HDLC)
-#  include <linux/wanpipe_lip_hdlc_iface.h>
-# endif
-# include <linux/wanpipe_lip_kernel.h>
-# include <linux/wanpipe_iface.h>
+#include "if_wanpipe_common.h"
+#include "wanpipe_fr_iface.h"
+#include "wanpipe_lip_atm_iface.h"
+#include "wanpipe_sppp_iface.h"
 
-# ifdef WPLIP_TTY_SUPPORT
+#if defined(CONFIG_PRODUCT_WANPIPE_LAPB) || defined(CONFIG_PRODUCT_WANPIPE_LIP_LAPD)
+# include "wanpipe_lapb_iface.h"
+#endif
+#if defined(CONFIG_PRODUCT_WANPIPE_LIP_KATM)
+# include "wanpipe_katm_iface.h"
+#endif
+#if defined(CONFIG_PRODUCT_WANPIPE_XDLC)
+# include "/wanpipe_xdlc_iface.h"
+#endif
+#if defined(CONFIG_PRODUCT_WANPIPE_XMTP2)
+# include "wanpipe_xmtp2_iface.h"
+#endif
+#if defined(CONFIG_PRODUCT_WANPIPE_LIP_HDLC)
+# include "wanpipe_lip_hdlc_iface.h"
+#endif
+#include "wanpipe_lip_kernel.h"
+#include "wanpipe_iface.h"
+
+#if defined (__LINUX__) && defined (WPLIP_TTY_SUPPORT)
 # include <linux/tty.h>
 # include <linux/tty_driver.h>
 # include <linux/tty_flip.h>
-# endif
-
 #endif
 
 
+#if defined(__WINDOWS__)
+/* Prototypes for interface between LIP and 'sprotocol' code in virt_adap_enum.c: */
+int sdla_tx_down(void* dev, void *tx_skb);
+int sdla_data_rx_up(void* sdla_net_dev, void *rx_skb);
+#endif
+
 
 
 #ifdef WAN_KERNEL
diff -dur include/wanpipe_snmp.h /usr/include/wanpipe/wanpipe_snmp.h
--- include/wanpipe_snmp.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_snmp.h	2009-07-14 13:02:00.000000000 -0400
@@ -20,8 +20,6 @@
 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined (__OpenBSD__)
 # define SIOC_WANPIPE_SNMP		_IOWR('i', 100, struct ifreq)
 # define SIOC_WANPIPE_SNMP_IFSPEED	_IOWR('i', 101, struct ifreq)
-#else
-//# include <linux/if_wanpipe.h>
 #endif
 
 #define SNMP_READ	1
diff -dur include/wanpipe_syncppp.h /usr/include/wanpipe/wanpipe_syncppp.h
--- include/wanpipe_syncppp.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_syncppp.h	2009-07-14 13:02:00.000000000 -0400
@@ -195,7 +195,7 @@
 	unsigned long task_working;
 	int	dynamic_failures;
 
-	unsigned char hwdevname[IFNAMSIZ+1];
+	unsigned char hwdevname[WAN_IFNAME_SZ+1];
 };
 
 struct ppp_device
@@ -208,8 +208,8 @@
 
 static inline struct sppp *sppp_of(netdevice_t *dev)
 {
-	wanpipe_common_t *chan = wan_netif_priv(dev);
-	struct ppp_device *pppdev = (struct ppp_device *) chan->prot_ptr;
+	wanpipe_common_t *chan=dev->priv;
+	struct ppp_device *pppdev=(struct ppp_device *)chan->prot_ptr;
 	return &pppdev->sppp;
 }
 
Only in include/: wanpipe_tdm_api_ec.h
diff -dur include/wanpipe_tdm_api.h /usr/include/wanpipe/wanpipe_tdm_api.h
--- include/wanpipe_tdm_api.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_tdm_api.h	2009-07-14 13:02:00.000000000 -0400
@@ -20,135 +20,144 @@
 #ifndef __WANPIPE_TDM_API_H_
 #define __WANPIPE_TDM_API_H_ 
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
-# include <net/wanpipe_includes.h>
-# include <net/wanpipe_defines.h>
-# include <net/wanpipe.h>
-# include <net/wanpipe_codec_iface.h>
-# include <net/wanpipe_tdm_api_iface.h>
-#elif defined(__WINDOWS__)
-# if defined(__KERNEL__)
-#  include <wanpipe_includes.h>
-#  include <wanpipe_defines.h>
-#  include <wanpipe_tdm_api_iface.h>
-#  include <wanpipe.h>
-
-enum{
-	TDMAPI_BUFFER_NO_CODEC=1,
-	TDMAPI_BUFFER_HDLC_DATA,
-	TDMAPI_BUFFER_ERROR,
-	TDMAPI_BUFFER_READY,
-	TDMAPI_BUFFER_ACCEPTED
-};
 
-#define inline __inline
-# endif
-# include <wanpipe_codec_iface.h>
+#include "wanpipe_includes.h"
+#include "wanpipe_defines.h"
+#include "wanpipe.h"
+#include "wanpipe_codec_iface.h"
+#include "wanpipe_api_iface.h"
+#include "wanpipe_cdev_iface.h"
 
-#else
-# include <linux/wanpipe_includes.h>
-# include <linux/wanpipe_defines.h>
-# include <linux/wanpipe.h>
-# include <linux/if_wanpipe.h>
-# include <linux/wanpipe_codec_iface.h>
-# include <linux/wanpipe_tdm_api_iface.h>
+#if defined(__WINDOWS__) && defined(__KERNEL__)
+# define inline __inline
 #endif
 
 
-
 #ifdef WAN_KERNEL
 
-#if !defined(__WINDOWS__)
-#define WP_TDM_API_MAX_LEN 	8*200
-#endif
+#define WP_TDM_API_MAX_LEN 	4096+sizeof(wp_api_hdr_t)
+#define WP_TDM_API_EVENT_MAX_LEN sizeof(wanpipe_tdm_api_dev_t)+sizeof(wp_api_hdr_t)
 
 #define WP_TDM_API_CHUNK_SZ 	8
-
+#define WP_RM_RXFLASHTIME		0 /* Default disable flash */
 enum {
 	WP_TDM_HDLC_TX,
 	WP_TDM_DOWN
 };
 
-#if defined(__WINDOWS__)
 
-#define	ssize_t unsigned int
-#define loff_t	unsigned int
+#if 1
+#undef WAN_TDMAPI_DTMF_TEST
+#else
+#define WAN_TDMAPI_DTMF_TEST 1
+typedef struct wp_dtmf_seq
+{
+	u8 dtmf_tone;
+}wp_dtmf_seq_t;
 
-struct file{
-	void *private_data;
-	unsigned int span;
-	unsigned int chan;
-};
+static _inline unsigned char wp_get_next_expected_digit(unsigned char current_digit)
+{
+	switch(current_digit)
+	{
+	case '0':
+		return '1';
+	case '1':
+		return '2';
+	case '2':
+		return '3';
+	case '3':
+		return '4';
+	case '4':
+		return '5';
+	case '5':
+		return '6';
+	case '6':
+		return '7';
+	case '7':
+		return '8';
+	case '8':
+		return '9';
+	case '9':
+		return 'A';
+	case 'A':
+		return 'B';
+	case 'B':
+		return 'C';
+	case 'C':
+		return 'D';
+	case 'D':
+		return '#';
+	case '#':
+		return '*';
+	case '*':
+		return '0';
+	default:
+		return '?';
+	}
+}
 
-struct inode{
-	char dummy;
-};
+#endif
 
-struct poll_table_struct{
-	char dummy;
-};
+#define WPTDM_CHAN_OP_MODE(tdm_api) (tdm_api->operation_mode==WP_TDM_OPMODE_CHAN)
+#define WPTDM_SPAN_OP_MODE(tdm_api) (tdm_api->operation_mode)
+#define WPTDM_WIN_LEGACY_OP_MODE(tdm_api) (tdm_api->operation_mode==WP_TDM_OPMODE_LEGACY_WIN_API)
 
-struct file_operations {
-    int		(*open)			(struct inode *, struct file *);
-	int		(*release)		(struct inode *, struct file *);
-    int		(*ioctl)		(struct inode *, struct file *, unsigned int, unsigned long);
-    ssize_t (*read)			(struct file *, char *, size_t, loff_t *);
-    ssize_t (*write)		(struct file *, const char *, size_t, loff_t *);
-    unsigned int (*poll)	(struct file *, struct poll_table_struct *);
-};
+#define WPTDM_WIN_LEGACY_API_MODE(tdm_api) (tdm_api->api_mode==WP_TDM_API_MODE_LEGACY_WIN_API)
 
-struct msghdr{
-	void *msg_iov;
-	int msg_namelen;
-	int msg_iovlen;
-};
 
-struct iovec{
-	char dummy;
-};
+typedef struct wanpipe_tdm_api_card_dev {
 
-#endif/* #if defined(__WINDOWS__) */
+	int ref_cnt;
+	unsigned int 	rbs_poll_timeout;
+	unsigned long 	rbs_poll_cnt;
+	unsigned long 	rbs_long_poll_cnt;
+	unsigned int	max_timeslots;
+	unsigned int	sig_timeslot_map;
+	unsigned int	rbscount;
+	int				rbs_enable_cnt;
+} wanpipe_tdm_api_card_dev_t;
 
 typedef struct wanpipe_tdm_api_dev {
 
 	u32 	init;
-	void 	*chan;
-	void 	*card;
+	void 	*chan;/* pointer to private_area_t */
+	void 	*card;/* pointer to sdla_t */
 	char 	name[WAN_IFNAME_SZ];
 	wan_spinlock_t lock;
 	
-	u32	used;
-	u32	tdm_span;
-	u32	tdm_chan;
+	u32	used, open_cnt;
+	u8	tdm_span;
+	u8	tdm_chan;
 	u8	state;
 	u8	hdlc_framing;
 	u32	active_ch;		/* ALEX */
 	
-	wanpipe_tdm_api_cmd_t	cfg;
+	wanpipe_api_dev_cfg_t cfg;
 
 	wan_skb_queue_t 	wp_rx_list;
 	wan_skb_queue_t 	wp_rx_free_list;
-	netskb_t 		*rx_skb;
-	
+	netskb_t 			*rx_skb;
+
 	wan_skb_queue_t 	wp_tx_list;
 	wan_skb_queue_t 	wp_tx_free_list;
-	netskb_t 		*tx_skb; 
-	
+	netskb_t 			*tx_skb;
+	u8					tx_channelized;
+
 	wan_skb_queue_t 	wp_event_list;
+	wan_skb_queue_t 	wp_event_bh_list;
+	wan_skb_queue_t 	wp_event_free_list;
+	wan_taskq_t 		wp_api_task;
+
+	wan_skb_queue_t 	wp_dealloc_list;
+
+	wp_api_hdr_t	*rx_hdr;
+	wp_api_hdr_t	tx_hdr;
 	
-	wp_tdm_api_rx_hdr_t	*rx_hdr;
-	wp_tdm_api_tx_hdr_t	tx_hdr;
-	
-	u32			poll_event;
-#if !defined(__WINDOWS__)
-	wait_queue_head_t 	poll_wait;
-#endif
+	u32				busy;
+	u32				kick;
 	
-	wan_ticks_t	 	rbs_poll_cnt;
-	u32			busy;
-	u32			tx_q_len;
 	u32 			critical;
-	u32			master;
+	u32				master;
 	
 	/* Used For non channelized drivers */
 	u8			rx_data[WP_TDM_API_CHUNK_SZ];
@@ -167,26 +176,62 @@
 	int (*event_ctrl)(void *chan, wan_event_ctrl_t*);
 	int (*read_rbs_bits)(void *chan, u32 ch, u8 *rbs_bits);
 	int (*write_rbs_bits)(void *chan, u32 ch, u8 rbs_bits);
-	int (*write_hdlc_frame)(void *chan, netskb_t *skb);
+	int (*write_hdlc_frame)(void *chan, netskb_t *skb,  wp_api_hdr_t *hdr);
+	int (*pipemon)(void* card, void* chan, void *udata);
+	int (*driver_ctrl)(void *chan_ptr, int cmd, wanpipe_api_cmd_t *api_cmd);
 
+	unsigned int 	rbs_rx_bits[NUM_OF_E1_CHANNELS];	/* Rx RBS Bits */
+#ifdef WAN_TDMAPI_DTMF_TEST
+	wp_dtmf_seq_t 	dtmf_check[NUM_OF_E1_CHANNELS+1];	/* Rx RBS Bits */
+ 	wp_dtmf_seq_t 	dtmf_check_event[NUM_OF_E1_CHANNELS+1];	/* Rx RBS Bits */
+#endif
+	uint8_t	 		dtmfsupport;
+	void 			*cdev;
+	uint8_t			operation_mode;/* WP_TDM_OPMODE */
+	uint8_t			api_mode;
+}wanpipe_tdm_api_dev_t;
 
-	 /* Hash pointers used to implement
-	 * SPAN/CHAN to Device mapping */
-	u32 hash_init;
-	struct wanpipe_tdm_api_dev **hash_pprev;
-	struct wanpipe_tdm_api_dev *hash_next; 
+ 
+static __inline int __wp_tdm_get_open_cnt( wanpipe_tdm_api_dev_t *tdm_api)
+{
+	return tdm_api->open_cnt;
+}
+ 
 
-#if defined(__WINDOWS__)
-	u32 original_active_ch;
-#endif
+static __inline int wp_tdm_get_open_cnt( wanpipe_tdm_api_dev_t *tdm_api)
+{
+	wan_smp_flag_t flags;
+	int cnt;
+	wan_spin_lock(&tdm_api->lock,&flags);
+	cnt=__wp_tdm_get_open_cnt(tdm_api);
+	wan_spin_unlock(&tdm_api->lock,&flags);
+	return cnt;
+}
 
-	uint8_t		dtmfsupport;
-	
-}wanpipe_tdm_api_dev_t;
+static __inline int wp_tdm_inc_open_cnt( wanpipe_tdm_api_dev_t *tdm_api)
+{
+	wan_smp_flag_t flags;
+	int cnt;
+	wan_spin_lock(&tdm_api->lock,&flags);
+	tdm_api->open_cnt++;
+	cnt = tdm_api->cfg.open_cnt = tdm_api->open_cnt;
+	wan_spin_unlock(&tdm_api->lock,&flags);
+	return cnt;
+}
 
-static __inline int is_tdm_api(void *chan, wanpipe_tdm_api_dev_t *tdm_api)
+static __inline int wp_tdm_dec_open_cnt( wanpipe_tdm_api_dev_t *tdm_api)
 {
+	wan_smp_flag_t flags;
+	int cnt;
+	wan_spin_lock(&tdm_api->lock,&flags);
+	tdm_api->open_cnt--;
+	cnt = tdm_api->cfg.open_cnt = tdm_api->open_cnt;
+	wan_spin_unlock(&tdm_api->lock,&flags);
+	return cnt;
+}
 
+static __inline int is_tdm_api(void *chan, wanpipe_tdm_api_dev_t *tdm_api)
+{
 	if (wan_test_bit(0,&tdm_api->init)) {
 		return 1;
 	}
@@ -196,6 +241,8 @@
 	}
 	return 0;
 }
+
+
 static __inline int is_tdm_api_stopped(wanpipe_tdm_api_dev_t *tdm_api)
 {
 	return wan_test_bit(0,&tdm_api->busy);
@@ -211,100 +258,120 @@
 	wan_clear_bit(0,&tdm_api->busy);
 }
 
-extern int wanpipe_tdm_api_rx_tx (wanpipe_tdm_api_dev_t *tdm_api, 
-				 u8 *rx_data, u8 *tx_data, int len);	  
-extern int wanpipe_tdm_api_reg(wanpipe_tdm_api_dev_t *tdm_api);
-extern int wanpipe_tdm_api_unreg(wanpipe_tdm_api_dev_t *tdm_api);
-extern int wanpipe_tdm_api_update_state(wanpipe_tdm_api_dev_t *tdm_api, int state);
-extern int wanpipe_tdm_api_rx_hdlc (wanpipe_tdm_api_dev_t *tdm_api, netskb_t *skb);
-extern int wanpipe_tdm_api_kick(wanpipe_tdm_api_dev_t *tdm_api);
 
-		
-/*===============================================================
- * wphash_sar_dev
- * wpunhash_sar_dev
- * wp_find_sar_dev_by_vpivci
- *
- *  Hashing functions used to map SPAN/CHAN to TDM API devices
- */
-#define WP_TDMAPI_HASH_SZ 	(4096 >> 2)
-#define vpivci_hashfn(x)	((((x) >> 8) ^ (x)) & (WP_TDMAPI_HASH_SZ - 1))    
 
-static inline wanpipe_tdm_api_dev_t *wp_find_tdm_api_dev(void **hash, 
-		                               unsigned int key,
-					       unsigned int span,
-					       unsigned int chan)
+static inline int wp_tdmapi_check_mtu(void* pcard, unsigned long timeslot_map, int chunksz, int *mtu)
 {
-	wanpipe_tdm_api_dev_t *p, **htable;
+	sdla_t	*card = (sdla_t*)pcard;
+	int	x, num_of_channels = 0, max_channels;
 
-	htable = (wanpipe_tdm_api_dev_t **)&hash[vpivci_hashfn(key)];
-	
-	for(p = *htable; p ;p = p->hash_next){
-		if (p->tdm_span == span && p->tdm_chan == chan){
-			break;
+	max_channels = GET_TE_CHANNEL_RANGE(&card->fe);
+	for (x = 0; x < max_channels; x++) {
+		if (wan_test_bit(x,&timeslot_map)){
+			num_of_channels++;
 		}
 	}
+	*mtu = chunksz * num_of_channels;
+	return 0;
+}
 
-	return p;
+static inline u8 wp_tdmapi_get_span(sdla_t *card)
+{
+	return card->tdmv_conf.span_no;
 }
- 
-static inline int wphash_tdm_api_dev(void **hash, wanpipe_tdm_api_dev_t *p, int hashid)
+
+static inline int wp_tdmapi_alloc_q(wanpipe_tdm_api_dev_t *tdm_api, wan_skb_queue_t *queue, int size, int cnt)
 {
-	wanpipe_tdm_api_dev_t **htable = (wanpipe_tdm_api_dev_t **)&hash[vpivci_hashfn(hashid)];
+	netskb_t *skb;
+	int i;
+#if defined(__WINDOWS__) && defined(DBG_QUEUE_IRQ_LOCKING)
+	KIRQL  OldIrql;
+#endif
 
-	
-	if (wan_test_bit(0,&p->hash_init)){
-		DEBUG_EVENT("%s: Critical Error: Init Sar in wphash_sar_dev!\n",
-				p->name);
+	if (!size || size > WP_TDM_API_MAX_LEN) {
 		return -1;
 	}	
 
-	if (wp_find_tdm_api_dev(hash, hashid, p->tdm_span, p->tdm_chan)){
-		DEBUG_EVENT("%s:%s: Error: device SPAN=%i CHAN=%i already in use!\n",
-				__FUNCTION__,p->name,p->tdm_span,p->tdm_chan);
-		return -1;
+	for (i=0;i<cnt;i++) {
+		skb=wan_skb_kalloc(size);
+		if (!skb) {
+			if (WAN_NET_RATELIMIT()) {
+			DEBUG_EVENT("%s: Error: Failed to Allocatet Memory %s:%d\n",
+					tdm_api->name, __FUNCTION__,__LINE__);
+			}
+			return -1;
+		}
+		wan_skb_init(skb,sizeof(wp_api_hdr_t));
+		wan_skb_trim(skb,0);
+
+#if defined(__WINDOWS__) && defined(DBG_QUEUE_IRQ_LOCKING)
+		/* this is an emulation of irq lock priority */
+		KeRaiseIrql(DISPATCH_LEVEL + 1, &OldIrql);//fixme: remove it!!
+#endif
+		
+		wan_skb_queue_tail(queue,skb);
+
+#if defined(__WINDOWS__) && defined(DBG_QUEUE_IRQ_LOCKING)
+		KeLowerIrql(OldIrql);//fixme: remove it!!
+#endif
 	}
-	
-	if((p->hash_next = *htable) != NULL)
-		(*htable)->hash_pprev = &p->hash_next;
-	
-	*htable = p;
-	p->hash_pprev = htable;
 
-	wan_set_bit(0,&p->hash_init);
 	return 0;
 }
 
-static inline void wpunhash_tdm_api_dev(wanpipe_tdm_api_dev_t *p)
-{
-	if (p->hash_next)
-		p->hash_next->hash_pprev = p->hash_pprev;
-	
-	*p->hash_pprev = p->hash_next;
-
-	wan_clear_bit(0,&p->init);
-}
 
-static inline int wp_tdmapi_check_mtu(void* pcard, unsigned long timeslot_map, int chunksz, int *mtu)
-{
-	sdla_t	*card = (sdla_t*)pcard;
-	int	x, num_of_channels = 0, max_channels;
+extern int wanpipe_tdm_api_rx_tx (wanpipe_tdm_api_dev_t *tdm_api, 
+				 u8 *rx_data, u8 *tx_data, int len);	  
+extern int wanpipe_tdm_api_reg(wanpipe_tdm_api_dev_t *tdm_api);
+extern int wanpipe_tdm_api_unreg(wanpipe_tdm_api_dev_t *tdm_api);
+extern int wanpipe_tdm_api_update_state(wanpipe_tdm_api_dev_t *tdm_api, int state);
+extern int wanpipe_tdm_api_kick(wanpipe_tdm_api_dev_t *tdm_api);
+extern int wanpipe_tdm_api_span_rx(wanpipe_tdm_api_dev_t *tdm_api, netskb_t *skb);
+extern int wanpipe_tdm_api_is_rbsbits(sdla_t *card);
+extern int wanpipe_tdm_api_rbsbits_poll(sdla_t * card);
 
-	max_channels = GET_TE_CHANNEL_RANGE(&card->fe);
-	for (x = 0; x < max_channels; x++) {
-		if (wan_test_bit(x,&timeslot_map)){
-			num_of_channels++;
-		}
+/* FIXME: Create proper TDM API Interface */
+#if 0
+#define WAN_TDMAPI_CALL(func, args, err)					\
+	if (card->tdmv_iface.func){					\
+		err = card->tdmv_iface.func args;			\
+	}else{								\
+		DEBUG_EVENT("%s: Internal Error (%s:%d)!\n",\
+				card->devname,				\
+				__FUNCTION__,__LINE__);			\
+		err = -EINVAL;						\
 	}
-	*mtu = chunksz * num_of_channels;
-	return 0;
-}
 
-static inline int wp_tdmapi_get_span(sdla_t *card)
+typedef struct wan_tdm_api_iface_
 {
-	return card->tdmv_conf.span_no;
-}
-		
+	int	(*check_mtu)(void*, unsigned long, int *);
+	int	(*create)(void* pcard, wanif_conf_t*);
+	int	(*remove)(void* pcard);
+	int	(*reg)(void*, wan_tdmv_if_conf_t*, unsigned int, unsigned char, void*);
+	int	(*unreg)(void* pcard, unsigned long ts_map);
+	int	(*software_init)(wan_tdmv_t*);
+	int 	(*state)(void*, int);
+	int	(*running)(void*);
+	int	(*rx_tx)(void*, netskb_t*);
+	int	(*rx_chan)(wan_tdmv_t*, int, unsigned char*, unsigned char*);
+#if defined(CONFIG_PRODUCT_WANPIPE_TDM_VOICE_DCHAN)
+	int	(*rx_dchan)(wan_tdmv_t*, int, unsigned char*, unsigned int); 
+#endif
+	int	(*rx_tx_span)(void *pcard);
+	int	(*is_rbsbits)(wan_tdmv_t *);
+	int	(*rbsbits_poll)(wanpipe_tdm_api_dev_t *, void*);
+	int	(*init)(void*, wanif_conf_t*);
+	int	(*free)(wanpipe_tdm_api_dev_t*);
+	int	(*polling)(void*);
+	int	(*buf_rotate)(void *pcard,u32,unsigned long);
+	int	(*ec_span)(void *pcard);
+
+#if defined(CONFIG_PRODUCT_WANPIPE_USB)
+	int	(*update_regs)(void*, int, u8*);	/* USB-FXO */
+#endif
+} wan_tdm_api_iface_t;
+
+#endif
 #endif
 
 #endif
diff -dur include/wanpipe_tdm_api_iface.h /usr/include/wanpipe/wanpipe_tdm_api_iface.h
--- include/wanpipe_tdm_api_iface.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_tdm_api_iface.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,351 +1,39 @@
-/*****************************************************************************
-* wanpipe_tdm_api_iface.h 
-* 		
-* 		WANPIPE(tm) AFT TE1 Hardware Support
-*
-* Authors: 	Nenad Corbic <ncorbic@sangoma.com>
-*
-* Copyright (c) 2007 - 08, Sangoma Technologies
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the <organization> nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-* ============================================================================
-* Oct 04, 2005	Nenad Corbic	Initial version.
-*
-* Jul 25, 2006	David Rokhvarg	<davidr@sangoma.com>	Ported to Windows.
-*****************************************************************************/
+/******************************************************************************//**
+ * \file wanpipe_tdm_api_iface.h
+ * \brief WANPIPE(tm) AFT TE1 Hardware Support
+ *
+ * Authors: Nenad Corbic <ncorbic@sangoma.com>
+ *			David Rokhvarg <davidr@sangoma.com>
+ *
+ * Copyright (c) 2007 - 08, Sangoma Technologies
+ * All rights reserved.
+ *
+ * * Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the Sangoma Technologies nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Sangoma Technologies ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Sangoma Technologies BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * ===============================================================================
+ */
 
 #ifndef __WANPIPE_TDM_API_IFACE_H_
-#define __WANPIPE_TDM_API_IFACE_H_ 
-
-
-#if defined(__WINDOWS__)
-typedef HANDLE sng_fd_t;
-#else
-typedef int sng_fd_t;
-#endif
-
-/* Indicate to library that new features exist */
-#define WP_TDM_FEATURE_DTMF_EVENTS	1
-#define WP_TDM_FEATURE_FE_ALARM		1
-#define WP_TDM_FEATURE_EVENTS		1
-#define WP_TDM_FEATURE_LINK_STATUS	1
-
-enum wanpipe_tdm_api_cmds {
-
-	SIOC_WP_TDM_GET_USR_MTU_MRU,	/* 0x00 */
-
-	SIOC_WP_TDM_SET_USR_PERIOD,	/* 0x01 */
-	SIOC_WP_TDM_GET_USR_PERIOD,	/* 0x02 */
-	
-	SIOC_WP_TDM_SET_HW_MTU_MRU,	/* 0x03 */
-	SIOC_WP_TDM_GET_HW_MTU_MRU,	/* 0x04 */
-
-	SIOC_WP_TDM_SET_CODEC,		/* 0x05 */
-	SIOC_WP_TDM_GET_CODEC,		/* 0x06 */
-
-	SIOC_WP_TDM_SET_POWER_LEVEL,	/* 0x07 */
-	SIOC_WP_TDM_GET_POWER_LEVEL,	/* 0x08 */
-
-	SIOC_WP_TDM_TOGGLE_RX,		/* 0x09 */
-	SIOC_WP_TDM_TOGGLE_TX,		/* 0x0A */
-
-	SIOC_WP_TDM_GET_HW_CODING,	/* 0x0B */
-	SIOC_WP_TDM_SET_HW_CODING,	/* 0x0C */
-
-	SIOC_WP_TDM_GET_FULL_CFG,	/* 0x0D */
-
-	SIOC_WP_TDM_SET_EC_TAP,		/* 0x0E */
-	SIOC_WP_TDM_GET_EC_TAP,		/* 0x0F */
-	
-	SIOC_WP_TDM_ENABLE_RBS_EVENTS,	/* 0x10 */
-	SIOC_WP_TDM_DISABLE_RBS_EVENTS,	/* 0x11 */
-	SIOC_WP_TDM_WRITE_RBS_BITS,	/* 0x12 */
-	
-	SIOC_WP_TDM_GET_STATS,		/* 0x13 */
-	SIOC_WP_TDM_FLUSH_BUFFERS,	/* 0x14 */
-	
-	SIOC_WP_TDM_READ_EVENT,		/* 0x15 */
-	
-	SIOC_WP_TDM_SET_EVENT,		/* 0x16 */
-
-	SIOC_WP_TDM_SET_RX_GAINS,	/* 0x17 */
-	SIOC_WP_TDM_SET_TX_GAINS,	/* 0x18 */
-	SIOC_WP_TDM_CLEAR_RX_GAINS,	/* 0x19 */
-	SIOC_WP_TDM_CLEAR_TX_GAINS,	/* 0x1A */
-
-	SIOC_WP_TDM_GET_FE_ALARMS,	/* 0x1B */
-
-	SIOC_WP_TDM_ENABLE_HWEC,	/* 0x1C */
-	SIOC_WP_TDM_DISABLE_HWEC,	/* 0x1D */
-	
-	SIOC_WP_TDM_SET_FE_STATUS,	/* 0x1E */
-	SIOC_WP_TDM_GET_FE_STATUS,	/* 0x1F */
-
-	SIOC_WP_TDM_GET_HW_DTMF,	/* 0x20 */
-
-	SIOC_WP_TDM_NOTSUPP		/*  */
-
-};
-
-#define SIOC_WP_TDM_GET_LINK_STATUS SIOC_WP_TDM_GET_FE_STATUS
-
-enum wanpipe_tdm_api_events {
-	WP_TDMAPI_EVENT_NONE,
-	WP_TDMAPI_EVENT_RBS,
-	WP_TDMAPI_EVENT_ALARM,
-	WP_TDMAPI_EVENT_DTMF,
-	WP_TDMAPI_EVENT_RM_DTMF,
-	WP_TDMAPI_EVENT_RXHOOK,
-	WP_TDMAPI_EVENT_RING,
-	WP_TDMAPI_EVENT_RING_DETECT,
-	WP_TDMAPI_EVENT_RING_TRIP_DETECT,
-	WP_TDMAPI_EVENT_TONE,
-	WP_TDMAPI_EVENT_TXSIG_KEWL,
-	WP_TDMAPI_EVENT_TXSIG_START,
-	WP_TDMAPI_EVENT_TXSIG_OFFHOOK,
-	WP_TDMAPI_EVENT_TXSIG_ONHOOK,
-	WP_TDMAPI_EVENT_ONHOOKTRANSFER,
-	WP_TDMAPI_EVENT_SETPOLARITY,
-	WP_TDMAPI_EVENT_BRI_CHAN_LOOPBACK,
-	WP_TDMAPI_EVENT_LINK_STATUS
-};
-
-#define WP_TDMAPI_EVENT_FE_ALARM WP_TDMAPI_EVENT_ALARM
-
-
-#define WP_TDMAPI_EVENT_ENABLE		0x01
-#define WP_TDMAPI_EVENT_DISABLE		0x02
-#define WP_TDMAPI_EVENT_MODE_DECODE(mode)				\
-		((mode) == WP_TDMAPI_EVENT_ENABLE) ? "Enable" :	\
-		((mode) == WP_TDMAPI_EVENT_DISABLE) ? "Disable" :	\
-						"(Unknown mode)"
-
-#define WPTDM_A_BIT 			WAN_RBS_SIG_A
-#define WPTDM_B_BIT 			WAN_RBS_SIG_B
-#define WPTDM_C_BIT 			WAN_RBS_SIG_C
-#define WPTDM_D_BIT 			WAN_RBS_SIG_D
- 
-#define WP_TDMAPI_EVENT_RXHOOK_OFF	0x01
-#define WP_TDMAPI_EVENT_RXHOOK_ON	0x02
-#define WP_TDMAPI_EVENT_RXHOOK_DECODE(state)				\
-		((state) == WP_TDMAPI_EVENT_RXHOOK_OFF) ? "Off-hook" :	\
-		((state) == WP_TDMAPI_EVENT_RXHOOK_ON) ? "On-hook" :	\
-						"(Unknown state)"
-
-#define WP_TDMAPI_EVENT_RING_PRESENT	0x01
-#define WP_TDMAPI_EVENT_RING_STOP	0x02
-#define WP_TDMAPI_EVENT_RING_DECODE(state)				\
-		((state) == WP_TDMAPI_EVENT_RING_PRESENT) ? "Ring Present" :	\
-		((state) == WP_TDMAPI_EVENT_RING_STOP) ? "Ring Stop" :	\
-						"(Unknown state)"
-
-#define WP_TDMAPI_EVENT_RING_TRIP_PRESENT	0x01
-#define WP_TDMAPI_EVENT_RING_TRIP_STOP	0x02
-#define WP_TDMAPI_EVENT_RING_TRIP_DECODE(state)				\
-		((state) == WP_TDMAPI_EVENT_RING_TRIP_PRESENT) ? "Ring Present" :	\
-		((state) == WP_TDMAPI_EVENT_RING_TRIP_STOP) ? "Ring Stop" :	\
-						"(Unknown state)"
-/*Link Status */
-#define WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED		0x01
-#define WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED	0x02
-#define WP_TDMAPI_EVENT_LINK_STATUS_DECODE(status)					\
-		((status) == WP_TDMAPI_EVENT_LINK_STATUS_CONNECTED) ? "Connected" :		\
-		((status) == WP_TDMAPI_EVENT_LINK_STATUS_DISCONNECTED)  ? "Disconnected" :		\
-							"Unknown"
-#define	WP_TDMAPI_EVENT_TONE_DIAL	0x01
-#define	WP_TDMAPI_EVENT_TONE_BUSY	0x02
-#define	WP_TDMAPI_EVENT_TONE_RING	0x03
-#define	WP_TDMAPI_EVENT_TONE_CONGESTION	0x04
-
-/* BRI channels list */						
-#define	WAN_BRI_BCHAN1		0x01
-#define	WAN_BRI_BCHAN2		0x02
-#define	WAN_BRI_DCHAN		0x03
-
-
-typedef struct {
-
-	u_int8_t	type;
-	u_int8_t	mode;
-	u_int32_t	time_stamp;
-	u_int8_t	channel;
-	u_int32_t	chan_map;
-	u_int8_t	span;
-	union {
-		struct {
-			u_int8_t	alarm;
-		} te1_alarm;
-		struct {
-			u_int8_t	rbs_bits;
-		} te1_rbs;
-		struct {
-			u_int8_t	state;
-			u_int8_t	sig;
-		} rm_hook;
-		struct {
-			u_int8_t	state;
-		} rm_ring;
-		struct {
-			u_int8_t	type;
-		} rm_tone;
-		struct {
-			u_int8_t	digit;	/* DTMF: digit  */
-			u_int8_t	port;	/* DTMF: SOUT/ROUT */
-			u_int8_t	type;	/* DTMF: PRESET/STOP */
-		} dtmf;
-		struct {
-			u_int16_t	polarity;
-			u_int16_t	ohttimer;
-		} rm_common;
-		struct{
-			u_int16_t status;
-		} linkstatus;
-	} wp_tdm_api_event_u;
-#define wp_tdm_api_event_type 		type
-#define wp_tdm_api_event_mode 		mode
-#define wp_tdm_api_event_alarm 		wp_tdm_api_event_u.te1_alarm.alarm
-#define wp_tdm_api_event_alarm 		wp_tdm_api_event_u.te1_alarm.alarm
-#define wp_tdm_api_event_rbs_bits 	wp_tdm_api_event_u.te1_rbs.rbs_bits
-#define wp_tdm_api_event_hook_state 	wp_tdm_api_event_u.rm_hook.state
-#define wp_tdm_api_event_hook_sig 	wp_tdm_api_event_u.rm_hook.sig
-#define wp_tdm_api_event_ring_state 	wp_tdm_api_event_u.rm_ring.state
-#define wp_tdm_api_event_tone_type 	wp_tdm_api_event_u.rm_tone.type
-#define wp_tdm_api_event_dtmf_digit 	wp_tdm_api_event_u.dtmf.digit
-#define wp_tdm_api_event_dtmf_type 	wp_tdm_api_event_u.dtmf.type
-#define wp_tdm_api_event_dtmf_port 	wp_tdm_api_event_u.dtmf.port
-#define wp_tdm_api_event_ohttimer 	wp_tdm_api_event_u.rm_common.ohttimer
-#define wp_tdm_api_event_polarity 	wp_tdm_api_event_u.rm_common.polarity
-#define wp_tdm_api_event_link_status	wp_tdm_api_event_u.linkstatus.status
-} wp_tdm_api_event_t;
-
-typedef struct {
-	union {
-		unsigned char	reserved[16];
-	}wp_rx_hdr_u;
-} wp_tdm_api_rx_hdr_t;
-
-typedef struct {
-        wp_tdm_api_rx_hdr_t	hdr;
-        unsigned char  		data[1];
-} wp_tdm_api_rx_element_t;
-
-typedef struct {
-	union {
-		struct {
-			unsigned char	_rbs_rx_bits;
-			unsigned int	_time_stamp;
-		}wp_tx;
-		unsigned char	reserved[16];
-	}wp_tx_hdr_u;
-#define wp_api_time_stamp 	wp_tx_hdr_u.wp_tx._time_stamp
-} wp_tdm_api_tx_hdr_t;
-
-typedef struct {
-        wp_tdm_api_tx_hdr_t	hdr;
-        unsigned char  		data[1];
-} wp_tdm_api_tx_element_t;
-
-
-
-typedef struct wp_tdm_chan_stats
-{
-	unsigned int	rx_packets;		/* total packets received	*/
-	unsigned int	tx_packets;		/* total packets transmitted	*/
-	unsigned int	rx_bytes;		/* total bytes received 	*/
-	unsigned int	tx_bytes;		/* total bytes transmitted	*/
-	unsigned int	rx_errors;		/* bad packets received		*/
-	unsigned int	tx_errors;		/* packet transmit problems	*/
-	unsigned int	rx_dropped;		/* no space in linux buffers	*/
-	unsigned int	tx_dropped;		/* no space available in linux	*/
-	unsigned int	multicast;		/* multicast packets received	*/
-#if !defined(__WINDOWS__)
-	unsigned int	collisions;
-#endif
-	/* detailed rx_errors: */
-	unsigned int	rx_length_errors;
-	unsigned int	rx_over_errors;		/* receiver ring buff overflow	*/
-	unsigned int	rx_crc_errors;		/* recved pkt with crc error	*/
-	unsigned int	rx_frame_errors;	/* recv'd frame alignment error */
-#if !defined(__WINDOWS__)
-	unsigned int	rx_fifo_errors;		/* recv'r fifo overrun		*/
-#endif
-	unsigned int	rx_missed_errors;	/* receiver missed packet	*/
-
-	/* detailed tx_errors */
-#if !defined(__WINDOWS__)
-	unsigned int	tx_aborted_errors;
-	unsigned int	tx_carrier_errors;
-#endif
-	unsigned int	tx_fifo_errors;
-	unsigned int	tx_heartbeat_errors;
-	unsigned int	tx_window_errors;
-	
-}wp_tdm_chan_stats_t;          
-
-
- 
-typedef struct wanpipe_tdm_api_cmd{
-	unsigned int cmd;
-	unsigned int hw_tdm_coding;	/* Set/Get HW TDM coding: uLaw muLaw */
-	unsigned int hw_mtu_mru;	/* Set/Get HW TDM MTU/MRU */
-	unsigned int usr_period;	/* Set/Get User Period in ms */
-	unsigned int tdm_codec;		/* Set/Get TDM Codec: SLinear */
-	unsigned int power_level;	/* Set/Get Power level treshold */
-	unsigned int rx_disable;	/* Enable/Disable Rx */
-	unsigned int tx_disable;	/* Enable/Disable Tx */		
-	unsigned int usr_mtu_mru;	/* Set/Get User TDM MTU/MRU */
-	unsigned int ec_tap;		/* Echo Cancellation Tap */
-	unsigned int rbs_poll;		/* Enable/Disable RBS Polling */
-	unsigned int rbs_rx_bits;	/* Rx RBS Bits */
-	unsigned int rbs_tx_bits;	/* Tx RBS Bits */
-	unsigned int hdlc;			/* HDLC based device */
-	unsigned int idle_flag;		/* IDLE flag to Tx */
-	unsigned int fe_alarms;		/* FE Alarms detected */
-	wp_tdm_chan_stats_t stats;	/* TDM Statistics */
-	/* Do NOT add anything above this! Important for binary backward compatibility. */
-	wp_tdm_api_event_t event;	/* TDM Event */
-	unsigned int data_len;
-        void *data;	
-	unsigned char fe_status;	/* FE status - Connected or Disconnected */
-	unsigned int hw_dtmf;		/* HW DTMF enabled */
-}wanpipe_tdm_api_cmd_t;
-
-typedef struct wanpipe_tdm_api_event{
-	int (*wp_rbs_event)(sng_fd_t fd, unsigned char rbs_bits);
-	int (*wp_dtmf_event)(sng_fd_t fd, unsigned char dtmf, unsigned char type, unsigned char port);
-	int (*wp_rxhook_event)(sng_fd_t fd, unsigned char hook_state);
-	int (*wp_ring_detect_event)(sng_fd_t fd, unsigned char ring_state);
-	int (*wp_ring_trip_detect_event)(sng_fd_t fd, unsigned char ring_state);
-	int (*wp_fe_alarm_event)(sng_fd_t fd, unsigned char fe_alarm_event);
-	int (*wp_link_status_event)(sng_fd_t fd, unsigned char link_status_event);
-}wanpipe_tdm_api_event_t; 
-
-typedef struct wanpipe_tdm_api{
-	wanpipe_tdm_api_cmd_t	wp_tdm_cmd;
-	wanpipe_tdm_api_event_t wp_tdm_event;
-}wanpipe_tdm_api_t;
+#define __WANPIPE_TDM_API_IFACE_H_
 
+#include "wanpipe_api_iface.h"
 
 #endif
Only in /usr/include/wanpipe/: wanpipe_timer_iface.h
Only in /usr/include/wanpipe/: wanpipe_usb.h
diff -dur include/wanpipe_version.h /usr/include/wanpipe/wanpipe_version.h
--- include/wanpipe_version.h	2009-07-14 11:29:25.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_version.h	2009-07-14 13:02:00.000000000 -0400
@@ -1,3 +1,7 @@
+/*****************************************************************************
+* wanpipe_version.h	WANPIPE(tm) Sangoma Device Driver.
+******************************************************************************/
+
 #ifndef __WANPIPE_VERSION__
 #define __WANPIPE_VERSION__
 
@@ -6,71 +10,64 @@
 #define WANPIPE_COMPANY         "Sangoma Technologies Inc"
 
 /********** LINUX **********/
-#define WANPIPE_VERSION			"3.4.2.17"
-#define WANPIPE_SUB_VERSION		"0"
-#define WANPIPE_VERSION_BETA		0
-#define WANPIPE_LITE_VERSION		"1.1.1"
+#define WANPIPE_VERSION					"3.5.0"
+#define WANPIPE_SUB_VERSION				"0"
+#define WANPIPE_LITE_VERSION			"1.1.1"
+
+#if defined(__LINUX__)
+#define	WANPIPE_VERSION_MAJOR			3
+#define	WANPIPE_VERSION_MINOR			5
+#define	WANPIPE_VERSION_MINOR1			0
+#define	WANPIPE_VERSION_MINOR2			1
+#endif
 
 /********** FreeBSD **********/
-#define WANPIPE_VERSION_FreeBSD		"3.2"
-#define WANPIPE_SUB_VERSION_FreeBSD	"2"
+#define WANPIPE_VERSION_FreeBSD			"3.2"
+#define WANPIPE_SUB_VERSION_FreeBSD		"2"
 #define WANPIPE_VERSION_BETA_FreeBSD	1
 #define WANPIPE_LITE_VERSION_FreeBSD	"1.1.1"
 
 /********** OpenBSD **********/
-#define WANPIPE_VERSION_OpenBSD		"1.6.5"
-#define WANPIPE_SUB_VERSION_OpenBSD	"8"
+#define WANPIPE_VERSION_OpenBSD			"1.6.5"
+#define WANPIPE_SUB_VERSION_OpenBSD		"8"
 #define WANPIPE_VERSION_BETA_OpenBSD	1
 #define WANPIPE_LITE_VERSION_OpenBSD	"1.1.1"
 
 /********** NetBSD **********/
-#define WANPIPE_VERSION_NetBSD		"1.1.1"
-#define WANPIPE_SUB_VERSION_NetBSD	"5"
-#define WANPIPE_VERSION_BETA_NetBSD	1
+#define WANPIPE_VERSION_NetBSD			"1.1.1"
+#define WANPIPE_SUB_VERSION_NetBSD		"5"
+#define WANPIPE_VERSION_BETA_NetBSD		1
 
 #if defined(__WINDOWS__)
-/********** Windows **********/
-typedef struct _DRIVER_VERSION {
-	unsigned int major;
-	unsigned int minor;
-	unsigned int minor1; 
-	unsigned int minor2; 
-}DRIVER_VERSION, *PDRIVER_VERSION;
 
-#define	WANPIPE_VERSION_MAJOR	6
-#define	WANPIPE_VERSION_MINOR	0
-#define	WANPIPE_VERSION_MINOR1	6
-#define	WANPIPE_VERSION_MINOR2	1
-
-static DRIVER_VERSION drv_version = {	WANPIPE_VERSION_MAJOR,
-					WANPIPE_VERSION_MINOR, 
-					WANPIPE_VERSION_MINOR1, 
-					WANPIPE_VERSION_MINOR2
-				};
+# define	WANPIPE_VERSION_MAJOR	6
+# define	WANPIPE_VERSION_MINOR	0
+# define	WANPIPE_VERSION_MINOR1	9
+# define	WANPIPE_VERSION_MINOR2	17
 
-#undef VER_PRODUCTVERSION
-#undef VER_PRODUCTVERSION_STR
-#undef VER_PRODUCTNAME_STR
-#undef VER_COMPANYNAME_STR
+# undef VER_PRODUCTVERSION
+# undef VER_PRODUCTVERSION_STR
+# undef VER_PRODUCTNAME_STR
+# undef VER_COMPANYNAME_STR
 
-#define VER_PRODUCTVERSION	6,0,6,1
-#define VER_PRODUCTVERSION_STR	"6.0.6.1"
-#define __BUILDDATE__		May 21, 2008
+# define VER_PRODUCTVERSION			6,0,9,17
+# define VER_PRODUCTVERSION_STR		"6.0.9.17"
+# define __BUILDDATE__				June 25, 2009
 
-#define VER_COMPANYNAME_STR		"Sangoma Technologies Corporation"
-#define VER_LEGALCOPYRIGHT_YEARS	"1984-2008"
-#define VER_LEGALCOPYRIGHT_STR		"Copyright (c) Sangoma Technologies Corporation"
-#define VER_PRODUCTNAME_STR		"Sangoma WANPIPE (TM)"
+# define VER_COMPANYNAME_STR		"Sangoma Technologies Corporation"
+# define VER_LEGALCOPYRIGHT_YEARS	"1984-2009"
+# define VER_LEGALCOPYRIGHT_STR		"Copyright (c) Sangoma Technologies Corporation"
+# define VER_PRODUCTNAME_STR		"Sangoma WANPIPE (TM)"
 
 # undef WANPIPE_VERSION
 # undef WANPIPE_VERSION_BETA
 # undef WANPIPE_SUB_VERSION
 
-# define WANPIPE_VERSION_Windows	"1.1.1"
-# define WANPIPE_SUB_VERSION_Windows	"4"
-# define WANPIPE_VERSION_BETA_Windows	1
+# define WANPIPE_VERSION_Windows		"6.0.9"
+# define WANPIPE_SUB_VERSION_Windows	"17"
+# define WANPIPE_VERSION_BETA_Windows	0
 
-# define WANPIPE_VERSION	WANPIPE_VERSION_Windows
+# define WANPIPE_VERSION		WANPIPE_VERSION_Windows
 # define WANPIPE_VERSION_BETA	WANPIPE_VERSION_BETA_Windows
 # define WANPIPE_SUB_VERSION	WANPIPE_SUB_VERSION_Windows
 #endif/* __WINDOWS__ */
Only in /usr/include/wanpipe/: wanpipe_x25.h
diff -dur include/wanpipe_x25_kernel.h /usr/include/wanpipe/wanpipe_x25_kernel.h
--- include/wanpipe_x25_kernel.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanpipe_x25_kernel.h	2009-07-14 13:02:00.000000000 -0400
@@ -71,7 +71,10 @@
 	SIOC_X25_SET_LCN_PID,
 	SIOC_X25_SET_LCN_LABEL,
 	SIOC_X25_INTERRUPT,	
-	SIOC_X25_HDLC_LINK_STATUS
+	SIOC_X25_HDLC_LINK_STATUS,
+	SIOC_X25_CLEAR_CONF,
+	SIOC_X25_RESET_CONF,
+	SIOC_X25_RESTART_CONF
 };
 
 
diff -dur include/wanproc.h /usr/include/wanpipe/wanproc.h
--- include/wanproc.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanproc.h	2009-07-14 13:02:00.000000000 -0400
@@ -13,7 +13,7 @@
 * Aug 20, 2001  Alex Feldman	Initial version.
 */
 
-#ifndef __WANPROC_H
+#if !defined(__WANPROC_H) && !defined(__WINDOWS__)
 # define __WANPROC_H
 
 # if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
diff -dur include/wanrouter.h /usr/include/wanpipe/wanrouter.h
--- include/wanrouter.h	2009-04-30 16:22:39.000000000 -0400
+++ /usr/include/wanpipe/wanrouter.h	2009-07-14 13:02:00.000000000 -0400
@@ -53,6 +53,9 @@
 #ifndef	_ROUTER_H
 #define	_ROUTER_H
 
+#include "wanpipe_cfg_def.h"
+#include "wanpipe_api_hdr.h"
+
 #define	ROUTER_NAME	"wanrouter"	/* in case we ever change it */
 #define	ROUTER_IOCTL	'W'		/* for IOCTL calls */
 #define	ROUTER_MAGIC	0x524D4157L	/* signature: 'WANR' reversed */
@@ -128,6 +131,8 @@
 #undef __LINUX__
 #endif
 
+#ifndef SPROTOCOL /* conflict with CISCO_IP in wanpipe_sppp.h */
+
 /* identifiers for displaying proc file data for dual port adapters */
 #define PROC_DATA_PORT_0 0x8000	/* the data is for port 0 */
 #define PROC_DATA_PORT_1 0x8001	/* the data is for port 1 */
@@ -141,11 +146,8 @@
 #define	NLPID_ISIS	0x83	/* ISO/IEC ISIS */
 #define	NLPID_Q933	0x08	/* CCITT Q.933 */
 
-#if !defined(__WINDOWS__)
-#ifndef WAN_DRVNAME_SZ  
-#define WAN_DRVNAME_SZ  15
-#endif
 #endif
+
 /****** Data Types **********************************************************/
 
 /*----------------------------------------------------------------------------
@@ -214,43 +216,24 @@
 
 #if defined(WAN_KERNEL)
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
-# include <wanpipe_debug.h>	
-# include <wanpipe_common.h>	
-# include <wanpipe_events.h>	
-# include <wanpipe_cfg.h>
-# ifdef CONFIG_PRODUCT_WANPIPE_TDM_VOICE
-#  include <sdla_tdmv.h>
-#  include <sdla_tdmv_dummy.h>
+# include "wanpipe_includes.h"
+# include "wanpipe_debug.h"
+# include "wanpipe_common.h"
+# include "wanpipe_events.h"
+# include "wanpipe_cfg.h"
+
+# if defined (CONFIG_PRODUCT_WANPIPE_TDM_VOICE)
+#  include "sdla_tdmv.h"
+#  include "sdla_tdmv_dummy.h"
 # endif
 
-#elif defined(__WINDOWS__)
-# include <wanpipe_debug.h>	
-# include <wanpipe_common.h>	
-# include <wanpipe_events.h>	
-# include <wanpipe_cfg.h>
-#else
-//# include <linux/version.h>
-# include <linux/wanpipe_includes.h>
-# include <linux/wanpipe_defines.h>
-# include <linux/wanpipe_debug.h>	
-# include <linux/wanpipe_common.h>	
-# include <linux/wanpipe_events.h>	
-# include <linux/wanpipe_cfg.h>
-//# include <linux/wanpipe_kernel.h>
+#if defined (__LINUX__)
 # include <linux/fs.h>		/* support for device drivers */
 # include <linux/proc_fs.h>	/* proc filesystem pragmatics */
-# include <linux/inet.h>		/* in_aton(), in_ntoa() prototypes */
-//# include <linux/netdevice.h>	/* support for network drivers */
+# include <linux/inet.h>	/* in_aton(), in_ntoa() prototypes */
 # ifndef KERNEL_VERSION
 #  define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 # endif
-
-# ifdef CONFIG_PRODUCT_WANPIPE_TDM_VOICE
-#  include <linux/sdla_tdmv.h>
-#  include <linux/sdla_tdmv_dummy.h>
-# endif
-
 #endif
 
 
@@ -372,19 +355,19 @@
 	void	(*ec_enable_timer) (void* card_id);	
 	struct {
 		void	(*rbsbits) (void* card_id, int, unsigned char);
-		void	(*alarms) (void* card_id, unsigned long);
-		void	(*dtmf) (void* card_id, wan_event_t*);	
+		void	(*alarms) (void* card_id, wan_event_t*);
+		void	(*tone) (void* card_id, wan_event_t*);	
 		void	(*hook) (void* card_id, wan_event_t*);	
 		void	(*ringtrip) (void* card_id, wan_event_t*);	
 		void	(*ringdetect) (void* card_id, wan_event_t*);	
 		void	(*linkstatus) (void* card_id, wan_event_t*);
+		void	(*polarityreverse) (void* card_id, wan_event_t*);
 	} event_callback;
 	
 	unsigned char 		ignore_front_end_status;
 	unsigned char		line_idle;
 #if defined(__WINDOWS__)
 	u32		card_type;
-	sdla_fe_cfg_t	fe_cfg;
 #else
 	unsigned char		card_type;
 #endif
@@ -427,8 +410,7 @@
 	
 	unsigned long		ec_enable_map;
 	unsigned long		fe_ec_map;
-	wan_ticks_t			ec_intmask;
-	unsigned long		ec_fax_detect_timeout;
+	wan_ticks_t		ec_intmask;
 		
 	int			(*ec_enable)(void *pcard, int, int);
 
@@ -443,6 +425,7 @@
 	void 			*rtp_dev;
 	int   			rtp_len;
 	void			(*rtp_tap)(void *card, u8 chan, u8* rx, u8* tx, u32 len);
+	void 			*port_cfg;
 } wan_device_t;
 
 WAN_LIST_HEAD(wan_devlist_, wan_device);
@@ -501,6 +484,14 @@
 int wanpipe_ec_poll(void*,void*);
 int wanpipe_ec_ready(void*);
 int wanpipe_ec_event_ctrl(void*,void*,wan_event_ctrl_t*);
+int wanpipe_wandev_create(void);
+int wanpipe_wandev_free(void);
+
+int wan_device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf, int user);
+int wan_device_shutdown (wan_device_t *wandev, wandev_conf_t *u_conf);
+int wan_device_setup (wan_device_t *wandev, wandev_conf_t *u_conf, int user);
+wan_device_t *wan_find_wandev_device(char *name);
+
 
 #endif	/* __KERNEL__ */
 #endif	/* _ROUTER_H */
Only in include/: xupdate
diff -dur include/zapcompat.h /usr/include/wanpipe/zapcompat.h
--- include/zapcompat.h	2009-07-03 15:34:54.000000000 -0400
+++ /usr/include/wanpipe/zapcompat.h	2009-07-14 13:02:00.000000000 -0400
@@ -11,6 +11,7 @@
  *		2 of the License, or (at your option) any later version.
  * ============================================================================
  * Sep 06,  2008 Moises Silva   Initial Version
+ * Nov 20,  2008 Alex Feldman   Added ZT_XLAW
  ******************************************************************************
  */
 
@@ -21,10 +22,13 @@
 // for DAHDI we need to map values and functions from ZT_XX to DAHDI_XX
 #if defined (DAHDI_ISSUES)
 
-#ifdef __KERNEL__
-#include <dahdi/kernel.h> // this will bring dahdi kernel stuff plus dahdi/user.h and friends
+#ifdef WAN_KERNEL
+# include <dahdi/kernel.h> // this will bring dahdi kernel stuff plus dahdi/user.h and friends
+#else
+# include <dahdi/user.h> // this will bring dahdi user stuff
 #endif
 
+
 #ifdef DAHDI_ECHOCANCEL_FAX_MODE 
 #define DAHDI_22
 #else
@@ -34,6 +38,7 @@
 // defines 
 #define ZT_CODE DAHDI_CODE
 
+
 #define ZT_ONHOOKTRANSFER DAHDI_ONHOOKTRANSFER
 #define ZT_SETPOLARITY DAHDI_SETPOLARITY
 #define ZT_CHUNKSIZE DAHDI_CHUNKSIZE
@@ -90,6 +95,7 @@
 
 #define ZT_LAW_ALAW DAHDI_LAW_ALAW
 #define ZT_LAW_MULAW DAHDI_LAW_MULAW
+#define ZT_XLAW	DAHDI_XLAW
 
 #define ZT_MAINT_REMOTELOOP DAHDI_MAINT_REMOTELOOP
 #define ZT_MAINT_NONE DAHDI_MAINT_NONE
@@ -142,12 +148,17 @@
 #define zt_qevent_lock dahdi_qevent_lock
 
 
+# define WP_ZT_QEVENT_LOCK(chan, event)	dahdi_qevent_lock((chan),(event))
+
 #else
 // zaptel is present
 // we will keep the same old names in wanpipe code, I thought of changing them
 // to something like WP_XX instead of ZT_XX, but I don't see any benefit on it
 // and would make this file bigger 
 #include <zaptel.h>
+
+
+# define WP_ZT_QEVENT_LOCK(chan, event)	zt_qevent_lock(&(chan),(event))
 #endif
 
 #endif	/* __ZAPCOMPAT_H */
