[zaptel-commits] tzafrir: trunk r2813 - in /trunk: ./ xpp/ xpp/firmwares/ xpp/utils/ xpp/utils...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Thu Aug 2 07:21:12 CDT 2007


Author: tzafrir
Date: Thu Aug  2 07:21:11 2007
New Revision: 2813

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2813
Log:
Merge xpp r4372:
* Update to zaptel-1.2.18 and zaptel-1.4.3 (r4308 onward)
* Fix a critical race with zaptel synchronization (r4362)
* Added a /proc/xpp/cmds for statistics about command timing (r4360)
* Fix a digit mapping bug with hardware dtmf detection (r4357)
* In xpp/utils/Makefile add perl syntax checks to our scripts (r4337)
* Better USB data error checking (r4336)
* udev rules (xpp.rules) avoid false calls from wrong nodes (r4331)
* Improve hardware detection and reporting in lszaptel,
  zaptel_hardware. zapconf is basically functional.
* Leds are blinked synchronously on all Astribanks now (r4262)
* Fix a BRI bug if OPTIMIZE_CHANMUTE was compiled into zaptel (r4258)
  (This feature was not yet accepted into official zaptel)
* Removed compile warning about HZ != 1000 (r4218)
* Firmware updates.
* fpga_load now supports USB pathes without zeros (r4211)
* XPD numbers have changed to '<Unit><Subunit>' (r4196)
* Proper support for ZT_VMWI ioctl, if used in zaptel (r4092)
* Fix FXO power denial detection (r4054)
* FXO could accidentally go off-hook with some compilers (r4048)

(From branches/1.2 r2732, r2735 - branches/1.4 2736)


Added:
    trunk/xpp/README.metering
      - copied unchanged from r2736, branches/1.4/xpp/README.metering
    trunk/xpp/utils/zconf/Zaptel/Config/
      - copied from r2736, branches/1.4/xpp/utils/zconf/Zaptel/Config/
    trunk/xpp/utils/zconf/Zaptel/Config/Defaults.pm
      - copied unchanged from r2736, branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm
Modified:
    trunk/   (props changed)
    trunk/xpp/.version
    trunk/xpp/ChangeLog
    trunk/xpp/Makefile
    trunk/xpp/README.Astribank
    trunk/xpp/card_bri.c
    trunk/xpp/card_fxo.c
    trunk/xpp/card_fxs.c
    trunk/xpp/card_global.c
    trunk/xpp/card_global.h
    trunk/xpp/firmwares/FPGA_1141.hex
    trunk/xpp/firmwares/FPGA_1151.hex
    trunk/xpp/firmwares/FPGA_FXS.hex
    trunk/xpp/firmwares/USB_1130.hex
    trunk/xpp/firmwares/USB_1140.hex
    trunk/xpp/firmwares/USB_1150.hex
    trunk/xpp/init_card_3_26
    trunk/xpp/utils/Makefile
    trunk/xpp/utils/fpga_load.c
    trunk/xpp/utils/genzaptelconf
    trunk/xpp/utils/lszaptel
    trunk/xpp/utils/xpp.rules
    trunk/xpp/utils/xpp_blink
    trunk/xpp/utils/xpp_sync
    trunk/xpp/utils/zapconf
    trunk/xpp/utils/zaptel_hardware
    trunk/xpp/utils/zconf/Zaptel/Chans.pm
    trunk/xpp/utils/zconf/Zaptel/Hardware.pm
    trunk/xpp/utils/zconf/Zaptel/Hardware/PCI.pm
    trunk/xpp/utils/zconf/Zaptel/Span.pm
    trunk/xpp/utils/zt_registration
    trunk/xpp/xbus-core.c
    trunk/xpp/xbus-core.h
    trunk/xpp/xdefs.h
    trunk/xpp/xpd.h
    trunk/xpp/xpp_usb.c
    trunk/xpp/xpp_zap.c
    trunk/xpp/xpp_zap.h
    trunk/xpp/xproto.c
    trunk/xpp/xproto.h

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-1.4-blocked (original)
+++ branch-1.4-blocked Thu Aug  2 07:21:11 2007
@@ -1,1 +1,1 @@
-/branches/1.4:1889,2271,2297,2348,2354,2671
+/branches/1.4:1889,2271,2297,2348,2354,2671,2711

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/xpp/.version
URL: http://svn.digium.com/view/zaptel/trunk/xpp/.version?view=diff&rev=2813&r1=2812&r2=2813
==============================================================================
--- trunk/xpp/.version (original)
+++ trunk/xpp/.version Thu Aug  2 07:21:11 2007
@@ -1,1 +1,1 @@
-trunk-r3965
+trunk-r4372

Modified: trunk/xpp/ChangeLog
URL: http://svn.digium.com/view/zaptel/trunk/xpp/ChangeLog?view=diff&rev=2813&r1=2812&r2=2813
==============================================================================
--- trunk/xpp/ChangeLog (original)
+++ trunk/xpp/ChangeLog Thu Aug  2 07:21:11 2007
@@ -1,3 +1,24 @@
+Thu Jul 12 2007 Oron Peled <oron at actcom.co.il> - xpp.r4372
+  * Update to zaptel-1.2.18 and zaptel-1.4.3 (r4308 onward)
+  * Fix a critical race with zaptel synchronization (r4362)
+  * Added a /proc/xpp/cmds for statistics about command timing (r4360)
+  * Fix a digit mapping bug with hardware dtmf detection (r4357)
+  * In xpp/utils/Makefile add perl syntax checks to our scripts (r4337)
+  * Better USB data error checking (r4336)
+  * udev rules (xpp.rules) avoid false calls from wrong nodes (r4331)
+  * Improve hardware detection and reporting in lszaptel,
+    zaptel_hardware. zapconf is basically functional.
+  * Leds are blinked synchronously on all Astribanks now (r4262)
+  * Fix a BRI bug if OPTIMIZE_CHANMUTE was compiled into zaptel (r4258)
+    (This feature was not yet accepted into official zaptel)
+  * Removed compile warning about HZ != 1000 (r4218)
+  * Firmware updates.
+  * fpga_load now supports USB pathes without zeros (r4211)
+  * XPD numbers have changed to '<Unit><Subunit>' (r4196)
+  * Proper support for ZT_VMWI ioctl, if used in zaptel (r4092)
+  * Fix FXO power denial detection (r4054)
+  * FXO could accidentally go off-hook with some compilers (r4048)
+
 Tue May  1 2007 Oron Peled <oron at actcom.co.il> - xpp.r3898
   * Tested with zaptel-1.2.17.1
   * Add D-Channel TX, RX and BAD frames count in /proc/xpp/XBUS-*/XPD-*/bri_info

Modified: trunk/xpp/Makefile
URL: http://svn.digium.com/view/zaptel/trunk/xpp/Makefile?view=diff&rev=2813&r1=2812&r2=2813
==============================================================================
--- trunk/xpp/Makefile (original)
+++ trunk/xpp/Makefile Thu Aug  2 07:21:11 2007
@@ -1,19 +1,24 @@
 ZAPTEL_DIR	= $(SUBDIRS)
 
 EXTRA_CFLAGS	=	$(XPP_LOCAL_CFLAGS)	\
-			-g3 -I$(ZAPTEL_DIR)	\
+			-I$(ZAPTEL_DIR)	\
 			-DDEBUG			\
 			-DPOLL_DIGITAL_INPUTS	\
 			-DWITH_ECHO_SUPPRESSION	\
-			-DPROTOCOL_DEBUG
+			-DPROTOCOL_DEBUG	\
+			-DWITH_METERING		\
+			-DDEBUG_PCMTX		\
+			-DPROTOCOL_DEBUG	\
+			-g
+			#
 
 ifneq	(,$(shell grep -w echo_can_state_t $(ZAPTEL_DIR)/zaptel.h))
-EXTRA_CFLAGS	+=	-DZAPTEL_EC_TYPEDEF
+EXTRA_CFLAGS	+= -DZAPTEL_EC_TYPEDEF
 endif
 
 obj-m		+= xpp.o xpd_fxs.o xpd_fxo.o
 
-HAS_BRISTUFF			:= $(shell cpp $(CPPFLAGS) -dM $(ZAPTEL_DIR)/zconfig.h | sed -n 's/^.*CONFIG_ZAPATA_BRI_DCHANS/y/p')
+HAS_BRISTUFF		:= $(shell cpp $(CPPFLAGS) -dM $(ZAPTEL_DIR)/zconfig.h | sed -n 's/^.*CONFIG_ZAPATA_BRI_DCHANS/y/p')
 
 # Build only supported modules
 ifneq	(,$(filter y m,$(CONFIG_USB)))

Modified: trunk/xpp/README.Astribank
URL: http://svn.digium.com/view/zaptel/trunk/xpp/README.Astribank?view=diff&rev=2813&r1=2812&r2=2813
==============================================================================
--- trunk/xpp/README.Astribank (original)
+++ trunk/xpp/README.Astribank Thu Aug  2 07:21:11 2007
@@ -1,34 +1,37 @@
-This file documents the Zaptel drivers for the Xorcom Astribank8 Channel Bank.
+Xorcom Astribank Documentation
+==============================
+Xorcom Team <support at xorcom.com>
+$Revision$, $Date$
+
+This file documents the Zaptel drivers for the Xorcom Channel Bank.
 The drivers reside in a separate subdirectory, xpp/ .
 
-
-Building and Installation:
-"""""""""""""""""""""""""
+It is generally a more technical document than the 
+http://www.xorcom.com/documentation/manuals/[Astribank User Manual]
+
+
+Building and Installation
+-------------------------
 Building and installation is basically like the normal procedure of 
 installing Zaptel with some additions.
 
-Building drivers:
-""""""""""""""""
-Unlike earlier versions, the Astribank driver (xpp) will now build 
-automatically. To build the drivers follow the usual Zaptel
-documentation. E.g: run:
-
-  make
-
-in the top-level directory.
-
-Next you will need to build the user-space tools needed for loading the
-firmware and initialization files for the Astribank:
-
-  make -C xpp/utils
-  
+Building drivers
+~~~~~~~~~~~~~~~~
+On zaptel 1.2 you will need to run the following extra step to build the
+Astribank drivers, apart from the standard 'make':
+
+  make -C xpp/utils install
+
 In order to build the user space utilities, you will need the libusb-dev
 package on Debian (and derivatives like ubuntu) or libusb-devel on RedHat
 (and derivatives like Centox/Trixbox).
-  
-
-INSTALLATION:
-""""""""""""
+
+And the following extra step to install:
+
+  make -C xpp/utils install
+
+INSTALLATION
+------------
 
 apart from the standard 'make install' in the zaptel directory, 
 run:
@@ -55,8 +58,9 @@
 
 to load firmware.
 
-LEDs Indication:
-"""""""""""""""
+
+LEDs Indication
+---------------
 The Astribank has 4 global indication leds and one or two per-port leds.
 In the Astribank 16 and in the Astribank BRI (USB product IDs 113x and 
 114x, respectively) the indication leds will normally be in the side.
@@ -85,16 +89,18 @@
 The per-port green led on analog (both FXS and FXO) indicate that the
 port is off-hook.
 
-On the BRI, the green led blinks when the port is TE and has layer-1
-connectivity to the other party, and the orange led blinks when the unit
-is in NT mode and has layer-1 connectivity to the other party.
-
-
-DEVICE STARTUP:
-""""""""""""""
-
-Terminology:
-"""""""""""
+On the BRI, the green led indicates a TE port whereas an orange led
+indicates an NT port. If the led is solid, the port is down (not even
+layer-1 connection is up). If it is blinking a double blink, layer 1
+is up. A slower single blinking indicates that layer 2 is up as well
+(which means that Asterisk is driving the port).
+
+
+DEVICE STARTUP
+--------------
+
+Terminology
+~~~~~~~~~~~
 Some technical terms that are used throughout the document and in the
 driver / zaptel . Only used in the technical parts.
 
@@ -109,11 +115,12 @@
 
 XPD:
 This is basically a logical unit of the Astribank. It will be registered to
-Zaptel as a single span. This will basically be 8 analog channels.
-
-
-Loading Firmware:
-""""""""""""""""
+Zaptel as a single span. This can be either an analog (FXS or FXO)
+module or a single port in a BRI module.
+
+
+Loading Firmware
+~~~~~~~~~~~~~~~~
 Normally this is done using the script /usr/share/zaptel/xpp_fxloader .
 If it works fine, you don't need to bother reading this section. 
 Once the firmware is loaded the USB ID of the Astribank changes to e4e4
@@ -156,8 +163,8 @@
 this will be the old value + 1.
 
 
-Firmware Loading with Hotplug:
-"""""""""""""""""""""""""""""
+Firmware Loading with Hotplug
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 The Hotplug framework was popular for hotplugging and usually also 
 autoloading drivers. If it is used on your system, you'll see 
 /etc/hotplug with many files under it. Hotplug will automatically load
@@ -183,8 +190,8 @@
 "replug" to load the FPGA firmware.
 
 
-Firmware Loading with UDEV:
-""""""""""""""""""""""""""
+Firmware Loading with UDEV
+~~~~~~~~~~~~~~~~~~~~~~~~~~
 The UDEV framework has replaced Hotplug in most recent systems. If you
 have a recent 2.6 system with no Hotplug and files under /etc/udev,
 chances are you ude udev. udev does quite a few nice things.
@@ -205,8 +212,8 @@
 the FPGA firmware.
 
 
-Firmware Resetting (Experimental):
-"""""""""""""""""""""""""""""""""
+Firmware Resetting
+~~~~~~~~~~~~~~~~~~
 Newer versions of the USB firmware can now be reset using 'fpga_load -r'.
 This will only work when the device is not used by the driver, so you may 
 need to 'rmmod xpp_usb' in order to reset the firmware.
@@ -221,8 +228,8 @@
   # and start/restrart asterisk.
 
 
-Loading The Modules:
-"""""""""""""""""""
+Loading The Modules
+~~~~~~~~~~~~~~~~~~~
 Here is what should happen:
 In short: you should plug it or have it plugged at boot time, and all
 the modules should load. You will see xpp_usb , xpd_fxs and possibly
@@ -268,8 +275,8 @@
 the case.
 
 
-Device Initializations Scripts:
-""""""""""""""""""""""""""""""
+Device Initializations Scripts
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 The chips in the device need to be initialized. This involves sending a
 bunch of values to certain registers in those chips. We decided that
 hardwiring those values in the driver itself would not be a good idea.
@@ -283,8 +290,9 @@
 a directory for that XPD under the relevant /proc/xpp/XBUS-* directory)
 and not be registered with Zaptel.
 
-Registering With Zaptel:
-"""""""""""""""""""""""
+
+Registering With Zaptel
+~~~~~~~~~~~~~~~~~~~~~~~
 Now we finally got to the "lights party" part: the lights in a unit
 (XPD) get lit before it registers with Zaptel and are turned off after
 that.
@@ -302,21 +310,26 @@
 For your convenience the command zt_registration 
 
 
-SAMPLE CONFIGURATIONS:
-""""""""""""""""""""""
-
-/etc/zaptel.conf:
-
-  Astribank 8:
-
+SAMPLE CONFIGURATIONS
+---------------------
+We generally recommend generating the configuration with the utility
+genzaptelconf. The following reference configuration will work for a
+system whose sole Zaptel hardware device is the said Astribank.
+
+/etc/zaptel.conf
+~~~~~~~~~~~~~~~
+
+Astribank 8
+^^^^^^^^^^^
     fxoks=1-14
 
-  Astribank 16: 8FXS/8FXO
-
+Astribank 16: 8FXS/8FXO
+^^^^^^^^^^^^^^^^^^^^^^^
     fxoks=1-14
     fxsks=15-22
 
-  Astribank 4 BRI
+Astribank 4 BRI
+^^^^^^^^^^^^^^^
     # Assumed ports settings:
     # Ports 1,3: TE
     # Ports 2,4: NT
@@ -335,9 +348,9 @@
   
 
 /etc/asterisk/zapata.conf
-
-  Astribank 8:
-   
+~~~~~~~~~~~~~~~~~~~~~~~~~
+Astribank 8
+^^^^^^^^^^^   
     [channels]
     signalling=fxo_ks
     ; The real analog ports:
@@ -348,16 +361,16 @@
     channel => 1-8
 
     ; output ports:
-    context=astbank-outputs
+    context=astbank-output
     channel => 9-10
     ; input ports:
     immediate=yes
-    context=astbank-inputs
+    context=astbank-input
     channel => 11-14
     immediate=no
   
-  Astribank 16: 8FXS/8FXO
-   
+Astribank 16: 8FXS/8FXO
+^^^^^^^^^^^^^^^^^^^^^^^   
     [channels]
     signalling=fxo_ks
     ; The real analog ports:
@@ -368,11 +381,11 @@
     channel => 1-8
 
     ; output ports:
-    context=astbank-outputs
+    context=astbank-output
     channel => 9-10
     ; input ports:
     immediate=yes
-    context=astbank-inputs
+    context=astbank-input
     channel => 11-14
     immediate=no
 
@@ -382,8 +395,8 @@
     callerid=asreceived
     channel => 15-22
 
-  Astribank 4 BRI:
-    
+Astribank 4 BRI
+^^^^^^^^^^^^^^^    
     ; Assumed ports settings:
     ; Ports 1,3: TE
     ; Ports 2,4: NT
@@ -410,7 +423,6 @@
     
     group = 2,14
     channel => 7,8
-    
 
 
 See also the output of genzaptelconf for examples of mailbox and 
@@ -440,51 +452,78 @@
 
 Sample dialplan (extensions.conf) for all the above:
 
-[phones-zap] 
-; 401 will dial to channel 1, 420, to zaptel channel 20, etc. 
-exten => _4XX,1,Dial(ZAP/${EXTEN:1}) 
- 
+-----------------------------------------------------------
+[phones-zap]
+; 6001 will dial to channel 1, 6020, to zaptel channel 20, etc.
+exten => _6XXX,1,Dial(ZAP/${EXTEN:1})
+; Useful for debugging trunks. Will potentially allow users to
+; bypass context limitations.
+;exten => _6XXX.,1,Dial(ZAP/${EXTEN:1:3}/${EXTEN:4})
+
 [trunk]
 ; A number that begins with 9: dial it through a trunk
 ; (we put FXO channels and TE channels in group 0).
 ; The leading 9 is stripped.
 exten => _9.,1,Dial(Zap/g0/${EXTEN:1})
-; dialing a number that begins with 81 will dial it through
-; span 1, etc. The two leading digits are stripped.
-; (Each digital span is also added to group 10+span number ).
+; dialing a number that begins with 83 will dial it through
+; span 3, and so forth. The two leading digits are stripped.
+; (Each digital span is also added to group 10+span number).
 exten => _8X.,1,Dial(Zap/g1${EXTEN:1:1}/${EXTEN:2})
 
 [from-internal] 
-;  The context of FXS ports: analog phones.  
+; The context of FXS ports: analog phones.
 ; They are allowed to dial to all other phones 
 include => phones-zap 
 ; They are also allowed to call through the trunk: 
 include => trunk
- 
+; some simple tests:
+include => astbank-test
+
 [from-pstn] 
 ; Calls from the PSTN enter here. Redirect calls to an IVR 
 ; or a default extension in the s context here. In this case we  
 ; redirect calls to Zaptel channel 1: 
 exten => s,1,Dial(Zap/1) 
- 
-[astbank-inputs] 
-exten => s,1,Set(ZAP_CHAN=Cut(${CHANNEL},-,1)) 
-exten => s,n,Set(ZAP_CHAN=Cut(${ZAP_CHAN},/,2)) 
+
+; Alternatively, the following will redirect you to the demo IVR 
+; from the sample extenbtions.conf of Asterisk:
+include => demo
+
+; An extra context with some simple tests
+[astbank-test]
+; 200: echo test
+exten => 200,1,Answer
+exten => 200,n,Wait(1)
+exten => 200,n,Echo()
+exten => 200,n,Hangup
+
+; 203: say extension number. Will only work if caller ID 
+; is properly set in zapata.conf / zapata-channels.conf
+exten => 203,1,Answer
+exten => 203,n,Wait(1)
+exten => 203,n,SayNumber(${CALLERID(num)})
+exten => 203,n,Hangup
+
+[astbank-input] 
+exten => s,1,Set(ZAP_CHAN=${CUT(CHANNEL,-,1)}) 
+exten => s,n,Set(ZAP_CHAN=${CUT(ZAP_CHAN,/,2)}) 
 ; 11 is the number of the first input port. At least in the sample 
 ; configuration below. 
-exten => s,n,Set(INPUT_NUM=Math(${ZAP_CHAN}-11)) 
+;exten => s,n,Set(INPUT_NUM=$[${ZAP_CHAN}-11)]) 
 ; The sample below just logs the signal.  
-exten => s,n,NoOp(Got signal from input port number ${INPUT_NUM}) 
+exten => s,n,NoOp(Got signal from Zaptel Channel ${ZAP_CHAN}) 
 ; Alternatively: 
 ;exten => s,n,System(run something) 
- 
+
 ; No. We did not forget the context astbank-outputs. Output 
 ; ports only get calls from the PBX. Thus they don't need a context 
-; of their own. 
+; of their own. Sending them to a context of their on makes 
+; 'zap show channels' in the CLI provide useful display, though.
+-----------------------------------------------------------
 
 
 /proc Interface
-"""""""""""""""
+---------------
 The Astribank drivers provide their own /proc interface under /proc/xpp .
 (Note that the details of this interface are still potentially subject to 
 changes)
@@ -499,6 +538,9 @@
 synchronization source. printing to it can change the synchronization
 source. Host-synchronization is currently the default but for better
 sound quality you should synchronize from the Astribank.
+
+Reading it may provide you some information regarding the timing
+behaviour of Asterisk.
 
 /proc/xpp/XBUS-nn gives information about device number nn (starting from
 00). under it, /proc/XBUS-nn/XPD-mm gives information regarding span number
@@ -517,16 +559,32 @@
 shows the current audio sample in both direction, which is useful to 
 see if there is something going at all.
 
-(There are a bunch of other status files under /proc/xpp/ )
+
+For FXO modules, /proc/xpp/XBUS-nn/XPD-mm/fxo_info also provides a
+"battery" line to show if the 
+
+
+For the BRI module, /proc/xpp/XBUS-nn/XPD-mm/bri_info provides very
+useful information regarding layer 1 and layer 2 status. For the
+lower-layer status:
+
+  watch -n1 -d 'grep "Layer 1:" /proc/xpp/XBUS-*/XPD-*/bri_info'
+
+For the status of the D channel of the span, see:
+
+  watch -n1 -d 'grep D-Channel: /proc/xpp/XBUS-*/XPD-*/bri_info'
+
+
+There are a bunch of other status files under /proc/xpp/ .
 
 
 Zaptel Init Configuration File
-""""""""""""""""""""""""""""""
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 The zaptel init.d script, genzaptelconf and the XPD init scripts source 
 the file /etc/init.d/zaptel (on Debian) or /etc/sysconfig/zaptel (on 
 RedHats). A number of useful values for there:
 
-############################### 
+-----------------------------------------------------------
 # Lines beginning with '#' are considered comments and ignored.
 
 # A two-letter country code. genzaptelconf uses it to better guess 
@@ -542,14 +600,13 @@
 # /usr/share/zaptel/init_fxo_mode .
 #opermode=FCC
 #opermode=FRANCE
-
-# If you feel like flooding your logs with debug output of the calibration 
-# process:
-#DEBUG_CALIBRATION=1
-###############################
-
-Useful Module Parameters:
-""""""""""""""""""""""""
+-----------------------------------------------------------
+
+Useful Module Parameters
+~~~~~~~~~~~~~~~~~~~~~~~~
+Compile-time defaults of all modules can be shown as part of the
+description line for the parameter in the output of modinfo.
+
 zap_autoreg: (xpp)
 Register spans automatically (1) or not (0). Default: 1. 
 Unsetting this could be useful if you have several Astribanks and you 
@@ -566,9 +623,24 @@
 even handy, but overly-verbose in the case of xpp_usb. Can be safely 
 set/unset at run-time using /sys/modules .
 
-
-
-BTW: XPP here does not stand for X Printing Panel, XML Pull Parser, 
+vmwineon: (xpd_fxs)
+Enable (1) or disable (0) sending voicemail message waiting indication
+to phones with a neon lamp. Disabled by default as it requires extra
+work of the driver even without such a phone and may potentially have
+some strange sideeffects with some phones.
+
+poll intervals: (various)
+There are various values which the driver occasionally polls the device
+for. For instance ,the parameter poll_battery_interval for xpd_fxo
+to poll the battery (if the telco is actually connected).
+
+The value of those parameters is typically a number in milliseconds or 0
+to disable. Under normal operation there should be no reason to play
+with such parameters.
+
+
+NOTE: XPP here does not stand for X Printing Panel, XML Pull Parser, 
 X-Windows Phase Plane or XML Professional Publisher. It is simply the 
 Xorcom Peripheral Protocol, which connects a computer to a XPD (Xorcom 
-Peripheral Device).
+Peripheral Device). An XBus (originally XPP Bus) is actually a single
+Astribank device and the XPDs have become the single modules in it.

Modified: trunk/xpp/card_bri.c
URL: http://svn.digium.com/view/zaptel/trunk/xpp/card_bri.c?view=diff&rev=2813&r1=2812&r2=2813
==============================================================================
--- trunk/xpp/card_bri.c (original)
+++ trunk/xpp/card_bri.c Thu Aug  2 07:21:11 2007
@@ -42,6 +42,10 @@
 
 DEF_PARM(int, print_dbg, 0, 0644, "Print DBG statements");	/* must be before zap_debug.h */
 DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)");
+#ifdef	DEBUG_PCMTX
+DEF_PARM(int, pcmtx, -1, 0644, "Forced PCM value to transmit (negative to disable)");
+DEF_PARM(int, pcmtx_chan, 0, 0644, "channel to force PCM value");
+#endif
 
 enum xhfc_states {
 	ST_RESET		= 0,	/* G/F0	*/
@@ -146,6 +150,7 @@
 				)
 #define	BRI_BCHAN_SIGCAP	ZT_SIG_CLEAR
 
+#define	IS_NT(xpd)	((xpd)->type == XPD_TYPE_BRI_NT)
 
 /*---------------- BRI Protocol Commands ----------------------------------*/
 
@@ -155,6 +160,10 @@
 static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data);
 static int proc_xpd_register_read(char *page, char **start, off_t off, int count, int *eof, void *data);
 static int proc_xpd_register_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
+static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc);
+static int bri_chanconfig(struct zt_chan *chan, int sigtype);
+static int bri_startup(struct zt_span *span);
+static int bri_shutdown(struct zt_span *span);
 
 #define	PROC_REGISTER_FNAME	"slics"
 #define	PROC_BRI_INFO_FNAME	"bri_info"
@@ -205,6 +214,7 @@
 	bool				reg30_good;
 	uint				reg30_ticks;
 	bool				layer1_up;
+	xpp_line_t			card_pcm_mask;
 
 	/*
 	 * D-Chan: buffers + extra state info.
@@ -228,16 +238,19 @@
 	enum led_state			ledstate[NUM_LEDS];
 };
 
-xproto_table_t	PROTO_TABLE(BRI_NT);
-xproto_table_t	PROTO_TABLE(BRI_TE);
+static xproto_table_t	PROTO_TABLE(BRI_NT);
+static xproto_table_t	PROTO_TABLE(BRI_TE);
 
 
 DEF_RPACKET_DATA(BRI, SET_LED,	/* Set one of the LED's */
 	struct bri_leds		bri_leds;
 	);
 
-static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, bool red_led, enum led_state to_led_state);
+static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state);
 static /* 0x0F */ DECLARE_CMD(BRI, REGISTER_REQUEST, byte chipsel, bool writing, bool do_subreg, byte regnum, byte subreg, byte data_low, byte data_high);
+
+#define	DO_LED(xpd, which, tostate)	\
+			CALL_PROTO(BRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate))
 
 #define DEBUG_BUF_SIZE (100)
 static void dump_hex_buf(xpd_t *xpd, char *msg, byte *buf, size_t len)
@@ -474,7 +487,7 @@
 		ERR("%s: len=%d is too long. dropping.\n", __FUNCTION__, len);
 		return -EINVAL;
 	}
-	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->id);
+	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx);
 	reg_cmd = &RPACKET_FIELD(pack, BRI, REGISTER_REQUEST, reg_cmd);
 	reg_cmd->bytes = len;
 	reg_cmd->eoframe = eoftx;
@@ -490,7 +503,7 @@
 	if(print_dbg)
 		dump_xframe("SEND_BRI_MULTI", xbus, xframe);
 #endif
-	ret = xframe_send(xbus, xframe);
+	ret = send_cmd_frame(xbus, xframe);
 	if(ret < 0)
 		NOTICE("%s: %s: failed sending xframe\n", __FUNCTION__, xbus->busname);
 	return ret;
@@ -509,7 +522,7 @@
 
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	if(xpd->type == XPD_TYPE_BRI_TE) {
+	if(!IS_NT(xpd)) {
 		static int	rate_limit;
 
 		if (priv->t3 > HFC_TIMER_OFF) {
@@ -562,25 +575,27 @@
 	if(ret < 0)
 		NOTICE("%s/%s: %s: failed sending xframe\n",
 				__FUNCTION__, xpd->xbus->busname, xpd->xpdname);
-	priv->dchan_tx_counter++;
+	if(eoframe)
+		priv->dchan_tx_counter++;
 	priv->dchan_notx_ticks = 0;
 	return ret;
 }
 
 /*---------------- BRI: Methods -------------------------------------------*/
 
-static xpd_t *BRI_card_new(xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, byte revision)
+static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte revision)
 {
 	xpd_t		*xpd = NULL;
 	int		channels = min(3, CHANNELS_PERXPD);
 
 	DBG("\n");
 
-	xpd = xpd_alloc(sizeof(struct BRI_priv_data), xbus, xpd_num, proto_table, channels, revision);
+	xpd = xpd_alloc(sizeof(struct BRI_priv_data), proto_table, channels);
 	if(!xpd)
 		return NULL;
 	xpd->direction = (proto_table == &PROTO_TABLE(BRI_NT)) ? TO_PHONE : TO_PSTN;
 	xpd->revision = revision;
+	xpd->type_name = proto_table->name;
 	return xpd;
 }
 
@@ -643,6 +658,7 @@
 	 */
 	CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_HOST, 0);
 	DBG("done: %s/%s\n", xbus->busname, xpd->xpdname);
+
 	priv->initialized = 1;
 	return 0;
 err:
@@ -666,6 +682,9 @@
 {
 	xbus_t			*xbus;
 	struct BRI_priv_data	*priv;
+	xpp_line_t		tmp_pcm_mask;
+	int			tmp_pcm_len;
+	unsigned long		flags;
 	int			i;
 	
 	BUG_ON(!xpd);
@@ -677,10 +696,6 @@
 		/* Nothing to do yet */
 		return 0;
 	}
-	snprintf(xpd->span.desc, MAX_SPANDESC, "Xorcom XPD #%d/%d: %s",
-			xbus->num, xpd->id,
-			xpd->xproto->name
-			);
 	xpd->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS;
 	xpd->span.deflaw = ZT_LAW_ALAW;
 	BIT_SET(xpd->digital_signalling, 2);	/* D-Channel */
@@ -688,8 +703,9 @@
 		struct zt_chan	*cur_chan = &xpd->chans[i];
 
 		DBG("setting BRI channel %d\n", i);
-		snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%d/%d/%d",
-				xpd->xproto->name, xbus->num, xpd->id, i);
+		snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d",
+				xpd->xproto->name, xbus->num,
+				xpd->addr.unit, xpd->addr.subunit, i);
 		cur_chan->chanpos = i + 1;
 		cur_chan->pvt = xpd;
 		if(i == 2) {	/* D-CHAN */
@@ -710,6 +726,34 @@
 			cur_chan->sigcap = BRI_BCHAN_SIGCAP;
 	}
 	xpd->offhook = BIT(0) | BIT(1);	/* 2*bchan */
+
+	/*
+	 * Compute PCM lentgh and mask
+	 * We know all cards have been initialized until now
+	 */
+	tmp_pcm_mask = 0;
+	if(xpd->addr.subunit == 0) {
+		int	line_count = 0;
+
+		for(i = 0; i < MAX_SUBUNIT; i++) {
+			xpd_t	*sub_xpd = xpd_byaddr(xbus, xpd->addr.unit, i);
+			if(sub_xpd) {
+				tmp_pcm_mask |= (sub_xpd->wanted_pcm_mask << (SUBUNIT_PCM_SHIFT * i));
+				line_count += 2;
+			}
+		}
+		tmp_pcm_len = RPACKET_HEADERSIZE + sizeof(xpp_line_t)  +  line_count * ZT_CHUNKSIZE;
+	} else
+		tmp_pcm_len = 0;
+	spin_lock_irqsave(&xpd->lock, flags);
+	xpd->pcm_len = tmp_pcm_len;
+	xpd->wanted_pcm_mask = xpd->offhook;
+	priv->card_pcm_mask = tmp_pcm_mask;
+	xpd->span.spanconfig = bri_spanconfig;
+	xpd->span.chanconfig = bri_chanconfig;
+	xpd->span.startup = bri_startup;
+	xpd->span.shutdown = bri_shutdown;
+	spin_unlock_irqrestore(&xpd->lock, flags);
 	return 0;
 }
 
@@ -744,45 +788,42 @@
 	unsigned int		timer_count;
 	int			which_led;
 	int			other_led;
-	enum led_state		ledstate;
 	int			mod;
 
 	BUG_ON(!xpd);
-	if(xpd->type == XPD_TYPE_BRI_TE) {
+	if(IS_NT(xpd)) {
+		which_led = RED_LED;
+		other_led = GREEN_LED;
+	} else {
 		which_led = GREEN_LED;
 		other_led = RED_LED;
-	} else {
-		which_led = RED_LED;
-		other_led = GREEN_LED;
 	}
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	ledstate = priv->ledstate[which_led];
 	timer_count = xpd->timer_count;
-	if((timer_count % DEFAULT_LED_PERIOD) == 0) {
-		if(xpd->blink_mode) {
+	if(xpd->blink_mode) {
+		if((timer_count % DEFAULT_LED_PERIOD) == 0) {
 			// led state is toggled
-				if(ledstate == BRI_LED_OFF) {
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON);
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_ON);
-				} else {
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF);
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_OFF);
-				}
-			return;
-		} else if(priv->ledstate[other_led] == BRI_LED_ON)	/* cleanup after blink */
-			CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_OFF);
-	}
+			if(priv->ledstate[which_led] == BRI_LED_OFF) {
+				DO_LED(xpd, which_led, BRI_LED_ON);
+				DO_LED(xpd, other_led, BRI_LED_ON);
+			} else {
+				DO_LED(xpd, which_led, BRI_LED_OFF);
+				DO_LED(xpd, other_led, BRI_LED_OFF);
+			}
+		}
+		return;
+	}
+	if(priv->ledstate[other_led] != BRI_LED_OFF)
+		DO_LED(xpd, other_led, BRI_LED_OFF);
 	if(priv->dchan_alive) {
 		mod = timer_count % 1000;
 		switch(mod) {
 			case 0:
-				if(ledstate == BRI_LED_OFF)
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON);
+				DO_LED(xpd, which_led, BRI_LED_ON);
 				break;
 			case 500:
-				if(ledstate == BRI_LED_ON)
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF);
+				DO_LED(xpd, which_led, BRI_LED_OFF);
 				break;
 		}
 	} else if(priv->layer1_up) {
@@ -790,18 +831,16 @@
 		switch(mod) {
 			case 0:
 			case 100:
-				if(ledstate == BRI_LED_OFF)
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON);
+				DO_LED(xpd, which_led, BRI_LED_ON);
 				break;
 			case 50:
 			case 150:
-				if(ledstate == BRI_LED_ON)
-					CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF);
+				DO_LED(xpd, which_led, BRI_LED_OFF);
 				break;
 		}
 	} else {
 		if(priv->ledstate[which_led] != BRI_LED_ON)
-			CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON);
+			DO_LED(xpd, which_led, BRI_LED_ON);
 	}
 }
 
@@ -854,7 +893,7 @@
 	*/
 
 	/* Detect T1 timer expiry on NT */
-	if(xpd->type == XPD_TYPE_BRI_NT) {
+	if(IS_NT(xpd)) {
 		if (priv->t1 > HFC_TIMER_OFF) {
 			if (--priv->t1 == 0) {
 				DBG("%s/%s: T1 Expired. Kick NT\n", xbus->busname, xpd->xpdname);
@@ -882,8 +921,69 @@
 	return 0;
 }
 
-static int BRI_span_startup(xpd_t *xpd)
-{
+/*
+ * Called only for 'span' keyword in /etc/zaptel.conf
+ */
+static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
+{
+	xpd_t		*xpd = span->pvt;
+	const char	*framingstr = "";
+	const char	*codingstr = "";
+	const char	*crcstr = "";
+
+	/* framing first */
+	if (lc->lineconfig & ZT_CONFIG_B8ZS)
+		framingstr = "B8ZS";
+	else if (lc->lineconfig & ZT_CONFIG_AMI)
+		framingstr = "AMI";
+	else if (lc->lineconfig & ZT_CONFIG_HDB3)
+		framingstr = "HDB3";
+	/* then coding */
+	if (lc->lineconfig & ZT_CONFIG_ESF)
+		codingstr = "ESF";
+	else if (lc->lineconfig & ZT_CONFIG_D4)
+		codingstr = "D4";
+	else if (lc->lineconfig & ZT_CONFIG_CCS)
+		codingstr = "CCS";
+	/* E1's can enable CRC checking */
+	if (lc->lineconfig & ZT_CONFIG_CRC4)
+		crcstr = "CRC4";
+	DBG("%s/%s[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n",
+		xpd->xbus->busname, xpd->xpdname,
+		IS_NT(xpd)?"NT":"TE",
+		lc->span,
+		lc->name,
+		lc->lbo,
+		framingstr, codingstr, crcstr,
+		lc->lineconfig,
+		lc->sync);
+	/*
+	 * FIXME: validate
+	 */
+	span->lineconfig = lc->lineconfig;
+	return 0;
+}
+
+/*
+ * Set signalling type (if appropriate)
+ * Called from zaptel with spinlock held on chan. Must not call back
+ * zaptel functions.
+ */
+static int bri_chanconfig(struct zt_chan *chan, int sigtype)
+{
+	DBG("channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype));
+	// FIXME: sanity checks:
+	// - should be supported (within the sigcap)
+	// - should not replace fxs <->fxo ??? (covered by previous?)
+	return 0;
+}
+
+/*
+ * Called only for 'span' keyword in /etc/zaptel.conf
+ */
+static int bri_startup(struct zt_span *span)
+{
+	xpd_t			*xpd = span->pvt;
 	struct BRI_priv_data	*priv;
 	struct zt_chan		*dchan;
 
@@ -891,11 +991,13 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	DBG("%s/%s: STARTUP\n", xpd->xbus->busname, xpd->xpdname);
+	// Turn on all channels
+	CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 1);
 	write_state_register(xpd, 0);	/* Enable L1 state machine */
 	xpd_activation(xpd, 1);
 	if(SPAN_REGISTERED(xpd)) {
-		dchan = &xpd->span.chans[2];
-		xpd->span.flags |= ZT_FLAG_RUNNING;
+		dchan = &span->chans[2];
+		span->flags |= ZT_FLAG_RUNNING;
 		/*
 		 * Zaptel (wrongly) assume that D-Channel need HDLC decoding
 		 * and during zaptel registration override our flags.
@@ -908,17 +1010,113 @@
 	return 0;
 }
 
-static int BRI_span_shutdown(xpd_t *xpd)
-{
+/*
+ * Called only for 'span' keyword in /etc/zaptel.conf
+ */
+static int bri_shutdown(struct zt_span *span)
+{
+	xpd_t			*xpd = span->pvt;
 	struct BRI_priv_data	*priv;
 
 	BUG_ON(!xpd);
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	DBG("%s/%s: SHUTDOWN\n", xpd->xbus->busname, xpd->xpdname);
-	if(xpd->type == XPD_TYPE_BRI_NT)
+	// Turn off all channels
+	CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0);
+	if(IS_NT(xpd))
 		xpd_activation(xpd, 0);
 	return 0;
+}
+
+static void BRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpp_line_t wanted_lines, xpacket_t *pack)
+{
+	byte		*pcm;
+	struct zt_chan	*chans;
+	unsigned long	flags;
+	int		i;
+	int		subunit;
+	xpp_line_t	pcm_mask = 0;
+
+
+	BUG_ON(!xbus);
+	BUG_ON(!xpd);
+	BUG_ON(!pack);
+	pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm);
+	for(subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
+		xpd_t		*tmp_xpd;
+
+		tmp_xpd = xpd_byaddr(xbus, xpd->addr.unit, subunit);
+		if(!tmp_xpd || !tmp_xpd->card_present)
+			continue;
+		spin_lock_irqsave(&tmp_xpd->lock, flags);
+		chans = tmp_xpd->span.chans;
+		for_each_line(tmp_xpd, i) {
+			if(IS_SET(wanted_lines, i)) {
+				if(SPAN_REGISTERED(tmp_xpd)) {
+#ifdef	DEBUG_PCMTX
+					if(pcmtx >= 0 && pcmtx_chan == i)
+						memset((u_char *)pcm, pcmtx, ZT_CHUNKSIZE);
+					else
+#endif
+						memcpy((u_char *)pcm, chans[i].writechunk, ZT_CHUNKSIZE);
+					// fill_beep((u_char *)pcm, tmp_xpd->addr.subunit, 2);
+				} else
+					memset((u_char *)pcm, 0x7F, ZT_CHUNKSIZE);
+				pcm += ZT_CHUNKSIZE;
+			}
+		}
+		pcm_mask |= (wanted_lines << SUBUNIT_PCM_SHIFT * subunit);
+		XPD_COUNTER(tmp_xpd, PCM_WRITE)++;
+		spin_unlock_irqrestore(&tmp_xpd->lock, flags);
+	}
+	RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines) = pcm_mask;
+}
+
+static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack)
+{
+	volatile u_char	*r;
+	byte		*pcm;
+	xpp_line_t	pcm_mask;
+	unsigned long	flags;
+	int		subunit;
+	int		i;
+
+	/*
+	 * Subunit 0 handle all other subunits
+	 */
+	if(xpd->addr.subunit != 0)
+		return;
+	pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm);
+	pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines);
+	for(subunit = 0; subunit < MAX_SUBUNIT; subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) {
+		xpd_t		*tmp_xpd;
+
+		if(!pcm_mask)
+			break;	/* optimize */
+		tmp_xpd = xpd_byaddr(xbus, xpd->addr.unit, subunit);
+		if(!tmp_xpd || !tmp_xpd->card_present)
+			continue;
+		spin_lock_irqsave(&tmp_xpd->lock, flags);
+		if (tmp_xpd->timer_count & 1) {
+			/* First part */
+			r = tmp_xpd->readchunk;
+		} else {
+			r = tmp_xpd->readchunk + ZT_CHUNKSIZE * CHANNELS_PERXPD;
+		}
+		for (i = 0; i < 2; i++, r += ZT_CHUNKSIZE) {
+			xpp_line_t	tmp_mask = pcm_mask & (BIT(0) | BIT(1));
+
+			if(IS_SET(tmp_mask, i)) {
+				// memset((u_char *)r, 0x5A, ZT_CHUNKSIZE);	// DEBUG
+				// fill_beep((u_char *)r, 1, 1);	// DEBUG: BEEP
+				memcpy((u_char *)r, pcm, ZT_CHUNKSIZE);
+				pcm += ZT_CHUNKSIZE;
+			}
+		}
+		XPD_COUNTER(tmp_xpd, PCM_READ)++;
+		spin_unlock_irqrestore(&tmp_xpd->lock, flags);
+	}
 }
 
 /*---------------- BRI: HOST COMMANDS -------------------------------------*/
@@ -934,7 +1132,7 @@
 		DBG("NO XBUS\n");
 		return -EINVAL;
 	}
-	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->id);
+	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx);
 #if 0
 	DBG("%s/%s/%d: %c%c R%02X S%02X %02X %02X\n",
 			xbus->busname, xpd->xpdname, chipsel,
@@ -951,7 +1149,7 @@
 	REG_FIELD(reg_cmd, subreg) = subreg;
 	REG_FIELD(reg_cmd, data_low) = data_low;
 	REG_FIELD(reg_cmd, data_high) = data_high;
-	ret = xframe_send(xbus, xframe);
+	ret = send_cmd_frame(xbus, xframe);
 	return ret;
 }
 
@@ -975,24 +1173,29 @@
 	return -ENOSYS;
 }
 
-/* 0x33 */ HOSTCMD(BRI, SET_LED, bool red_led, enum led_state to_led_state)
+/* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state)
 {
 	int			ret = 0;
-	xframe_t	*xframe;
+	xframe_t		*xframe;
 	xpacket_t		*pack;
 	struct bri_leds		*bri_leds;
 	struct BRI_priv_data	*priv;
-	int			which_led = (red_led) ? RED_LED : GREEN_LED;
 
 	BUG_ON(!xbus);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	XFRAME_NEW(xframe, pack, xbus, BRI, SET_LED, xpd->id);
+#if 0
+	DBG("%s/%s: %s -> %d\n",
+		xbus->busname, xpd->xpdname,
+		(which_led)?"RED":"GREEN",
+		to_led_state);
+#endif
+	XFRAME_NEW(xframe, pack, xbus, BRI, SET_LED, xpd->xbus_idx);
 	bri_leds = &RPACKET_FIELD(pack, BRI, SET_LED, bri_leds);
 	bri_leds->state = to_led_state;
 	bri_leds->led_sel = which_led;
 	pack->datalen = RPACKET_SIZE(BRI, SET_LED);
-	ret = xframe_send(xbus, xframe);
+	ret = send_cmd_frame(xbus, xframe);
 	priv->ledstate[which_led] = to_led_state;
 	return ret;
 }
@@ -1033,8 +1236,8 @@
 	new_state.reg = reg_x30;
 	priv->reg30_ticks = 0;
 	priv->reg30_good = 1;
-	if((xpd->type == XPD_TYPE_BRI_TE && new_state.bits.v_su_sta == ST_TE_ACTIVATED) ||
-		(xpd->type == XPD_TYPE_BRI_NT && new_state.bits.v_su_sta == ST_NT_ACTIVATED)) {
+	if((!IS_NT(xpd) && new_state.bits.v_su_sta == ST_TE_ACTIVATED) ||
+		(IS_NT(xpd) && new_state.bits.v_su_sta == ST_NT_ACTIVATED)) {
 		if(!priv->layer1_up) {
 			layer1_state(xpd, 1);
 			update_xpd_status(xpd, ZT_ALARM_NONE);
@@ -1063,10 +1266,10 @@
 		return;	/* same same */
 	DBG("%02X ---> %02X\n", priv->state_register.reg, reg_x30);
 	DBG("%s/%s: %s%i\n", xbus->busname, xpd->xpdname,
-				(xpd->type == XPD_TYPE_BRI_NT)?"G":"F",
+				IS_NT(xpd)?"G":"F",
 				new_state.bits.v_su_sta);
 
-	if(xpd->type == XPD_TYPE_BRI_TE) {
+	if(!IS_NT(xpd)) {
 		/* disable T3 ? */
 		if ((new_state.bits.v_su_sta <= ST_TE_DEACTIVATED) || (new_state.bits.v_su_sta >= ST_TE_ACTIVATED)) {
 			DBG("%s/%s: Disable T3 ?\n", xbus->busname, xpd->xpdname);
@@ -1105,7 +1308,7 @@
 				break;
 		}
 
-	} else if(xpd->type == XPD_TYPE_BRI_NT) {
+	} else if(IS_NT(xpd)) {
 		switch (new_state.bits.v_su_sta) {
 			case ST_NT_DEACTIVATED:		/* G1 */
 				DBG("%s/%s: State ST_NT_DEACTIVATED (G1)\n", xbus->busname, xpd->xpdname);
@@ -1144,8 +1347,9 @@
 	int			ret;
 
 	if(!xpd) {
-		NOTICE("%s: received %s for non-existing xpd: %d\n",
-				__FUNCTION__, cmd->name, XPD_NUM(pack->addr));
+		NOTICE("%s: received %s for non-existing %s(%1d%1d)\n",
+				__FUNCTION__, cmd->name,
+				xbus->busname, pack->addr.unit, pack->addr.subunit);
 		return -EPROTO;
 	}
 	spin_lock_irqsave(&xpd->lock, flags);
@@ -1192,7 +1396,7 @@
 	return 0;
 }
 
-xproto_table_t PROTO_TABLE(BRI_NT) = {
+static xproto_table_t PROTO_TABLE(BRI_NT) = {
 	.owner = THIS_MODULE,
 	.entries = {
 		/*	Table	Card	Opcode		*/
@@ -1208,9 +1412,9 @@
 		.card_zaptel_postregistration	= BRI_card_zaptel_postregistration,
 		.card_hooksig	= BRI_card_hooksig,

[... 8725 lines stripped ...]



More information about the zaptel-commits mailing list