[zaptel-commits] tzafrir: branch 1.4 r3646 - in /branches/1.4: ./ xpp/ xpp/utils/ xpp/utils/zc...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Thu Jan 10 14:10:15 CST 2008


Author: tzafrir
Date: Thu Jan 10 14:10:14 2008
New Revision: 3646

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3646
Log:
xpp.r5254:
* Improved polarity reversal hangups in FXO (r5194).
  Fixed false detection of polarity reversals.
* Optimize xframe allocation, by not zeroing the whole
  memory (in get_xframe()).
* Fixed erronous error message that appeared sometimes
  from fpga_load during USB renumeration.
* Zaptel::Chans now provides battery() reporting for some FXO
  channels (Astribank FXO and wcfxo).

Merged revisions 3643 via svnmerge from 
http://svn.digium.com/svn/zaptel/branches/1.2

Added:
    branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Line.pm
      - copied unchanged from r3644, branches/1.2/xpp/utils/zconf/Zaptel/Xpp/Line.pm
Modified:
    branches/1.4/   (props changed)
    branches/1.4/xpp/.version
    branches/1.4/xpp/Changelog_xpp
    branches/1.4/xpp/Kbuild
    branches/1.4/xpp/Makefile
    branches/1.4/xpp/README.Astribank
    branches/1.4/xpp/card_bri.c
    branches/1.4/xpp/card_fxo.c
    branches/1.4/xpp/card_global.c
    branches/1.4/xpp/card_pri.c
    branches/1.4/xpp/init_card_9_29
    branches/1.4/xpp/utils/Makefile
    branches/1.4/xpp/utils/astribank_hook
    branches/1.4/xpp/utils/fpga_load.c
    branches/1.4/xpp/utils/lszaptel
    branches/1.4/xpp/utils/zapconf
    branches/1.4/xpp/utils/zaptel_hardware
    branches/1.4/xpp/utils/zconf/Zaptel.pm
    branches/1.4/xpp/utils/zconf/Zaptel/Chans.pm
    branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm
    branches/1.4/xpp/utils/zconf/Zaptel/Hardware/PCI.pm
    branches/1.4/xpp/utils/zconf/Zaptel/Span.pm
    branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Xpd.pm
    branches/1.4/xpp/xbus-core.c
    branches/1.4/xpp/xbus-pcm.c
    branches/1.4/xpp/xdefs.h
    branches/1.4/xpp/xframe_queue.c
    branches/1.4/xpp/xpd.h
    branches/1.4/xpp/xpp_usb.c
    branches/1.4/xpp/xpp_zap.c
    branches/1.4/xpp/xproto.c
    branches/1.4/xpp/xproto.h
    branches/1.4/xpp/zap_debug.c
    branches/1.4/xpp/zap_debug.h

Propchange: branches/1.4/
------------------------------------------------------------------------------
--- branch-1.2-blocked (original)
+++ branch-1.2-blocked Thu Jan 10 14:10:14 2008
@@ -1,1 +1,1 @@
-/branches/1.2:917,937,1073,1206,1613,2018,2434,2583,2668,2750,2789,2868,2871,2878,3083,3098-3099,3201,3509
+/branches/1.2:917,937,1073,1206,1613,2018,2434,2583,2668,2750,2789,2868,2871,2878,3083,3098-3099,3201,3509,3645

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

Modified: branches/1.4/xpp/.version
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/.version?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/.version (original)
+++ branches/1.4/xpp/.version Thu Jan 10 14:10:14 2008
@@ -1,1 +1,1 @@
-trunk-r5178
+trunk-r5254

Modified: branches/1.4/xpp/Changelog_xpp
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/Changelog_xpp?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/Changelog_xpp (original)
+++ branches/1.4/xpp/Changelog_xpp Thu Jan 10 14:10:14 2008
@@ -1,4 +1,14 @@
-Mon Dec 24 2007 Tzafrir Cohen <tzafrir.cohen at xorcom.com> - xpp.r5178
+Thu Jan 10 2008 Oron Peled <oron.peled at xorcom.com> - xpp.r5254
+  * Improved polarity reversal hangups in FXO (r5194).
+    Fixed false detection of polarity reversals.
+  * Optimize xframe allocation, by not zeroing the whole
+    memory (in get_xframe()).
+  * Fixed erronous error message that appeared sometimes
+    from fpga_load during USB renumeration.
+  * Zaptel::Chans now provides battery() reporting for some FXO
+    channels (Astribank FXO and wcfxo).
+
+Tue Dec 25 2007 Tzafrir Cohen <tzafrir.cohen at xorcom.com> - xpp.r5179
   * xpd_pri: Basically ready.
   * PCM synchronization changes:
     - Each Astribank unit ticks independently. Each with its own PLL.

Modified: branches/1.4/xpp/Kbuild
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/Kbuild?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/Kbuild (original)
+++ branches/1.4/xpp/Kbuild Thu Jan 10 14:10:14 2008
@@ -30,7 +30,7 @@
 obj-m		+= xpd_bri.o
 endif
 
-xpp-y		+= xbus-core.o xbus-sysfs.o xbus-pcm.o xframe_queue.o xpp_zap.o xproto.o card_global.o
+xpp-y		+= xbus-core.o xbus-sysfs.o xbus-pcm.o xframe_queue.o xpp_zap.o xproto.o card_global.o zap_debug.o
 xpd_fxs-y	+= card_fxs.o
 xpd_fxo-y	+= card_fxo.o
 xpd_bri-y	+= card_bri.o
@@ -40,9 +40,6 @@
 EXTRA_CFLAGS	+= -DDEBUG_SYNC_PARPORT
 obj-m		+= parport_debug.o
 endif
-
-ctags:
-	ctags *.[ch]
 
 # Handle versioning
 XPP_VERSION_STR	?= $(shell if [ -r $(obj)/.version ]; then echo "\"`cat $(obj)/.version`\""; else echo '"Unknown"'; fi)

Modified: branches/1.4/xpp/Makefile
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/Makefile?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/Makefile (original)
+++ branches/1.4/xpp/Makefile Thu Jan 10 14:10:14 2008
@@ -1,4 +1,7 @@
 # We only get here on kernels 2.6.0-2.6.8 .
 # For newer kernels, Kbuild will be included directly by the kernel
 # build system.
-include $(obj)/Kbuild
+-include $(src)/Kbuild
+
+ctags:
+	ctags *.[ch]

Modified: branches/1.4/xpp/README.Astribank
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/README.Astribank?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/README.Astribank (original)
+++ branches/1.4/xpp/README.Astribank Thu Jan 10 14:10:14 2008
@@ -821,8 +821,8 @@
 On each time an Astribank is initialized or destroyed a udev event is
 generated. The rules from our sample udev rules file (xpp/utils/xpp.rules) 
 make that event run the script /usr/share/zaptel/astribank_hook with the
-parameter 'add' or 'remove'. Currently this script will just adjust the
-Astribank sync settings (by running xpp_sync). 
+parameter 'add' or 'remove', if such script exists. An example script
+that just adjusts the Astribank sync settings is included in xpp/utils. 
 
 
 Registering in Zaptel

Modified: branches/1.4/xpp/card_bri.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/card_bri.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/card_bri.c (original)
+++ branches/1.4/xpp/card_bri.c Thu Jan 10 14:10:14 2008
@@ -151,7 +151,11 @@
 				)
 #define	BRI_BCHAN_SIGCAP	ZT_SIG_CLEAR
 
-#define	IS_NT(xpd)	((xpd)->type == XPD_TYPE_BRI_NT)
+#define	IS_NT(xpd)		((xpd)->type == XPD_TYPE_BRI_NT)
+
+/* shift in PCM highway */
+#define	SUBUNIT_PCM_SHIFT	4
+#define	PCM_SHIFT(mask, sunit)	((mask) << (SUBUNIT_PCM_SHIFT * (sunit)))
 
 /*---------------- BRI Protocol Commands ----------------------------------*/
 
@@ -723,7 +727,7 @@
 		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));
+				tmp_pcm_mask |= PCM_SHIFT(sub_xpd->wanted_pcm_mask, i);
 				line_count += 2;
 			}
 		}
@@ -1077,7 +1081,7 @@
 				pcm += ZT_CHUNKSIZE;
 			}
 		}
-		pcm_mask |= (wanted_lines << SUBUNIT_PCM_SHIFT * subunit);
+		pcm_mask |= PCM_SHIFT(wanted_lines, subunit);
 		XPD_COUNTER(tmp_xpd, PCM_WRITE)++;
 		spin_unlock_irqrestore(&tmp_xpd->lock, flags);
 	}
@@ -1399,6 +1403,7 @@
 		.card_tick	= BRI_card_tick,
 		.card_pcm_fromspan	= BRI_card_pcm_fromspan,
 		.card_pcm_tospan	= BRI_card_pcm_tospan,
+		.card_ioctl	= BRI_card_ioctl,
 		.card_close	= BRI_card_close,
 		.card_register_reply	= BRI_card_register_reply,
 

Modified: branches/1.4/xpp/card_fxo.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/card_fxo.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/card_fxo.c (original)
+++ branches/1.4/xpp/card_fxo.c Thu Jan 10 14:10:14 2008
@@ -55,7 +55,6 @@
 #define	NUM_LEDS		1
 #define	DELAY_UNTIL_DIALTONE	3000
 
-#define	POLREV_START		3	/* time after offhook to ignore polarity reversals (in ticks) */
 #define	POLREV_THRESHOLD	1000	/* minimum duration for polarity reversal detection (in ticks) */
 #define	BAT_THRESHOLD		3
 #define	BAT_DEBOUNCE		1000	/* compensate for battery voltage fluctuation (in ticks) */
@@ -105,11 +104,11 @@
 #endif
 	struct proc_dir_entry	*fxo_info;
 	uint			poll_counter;
+	signed char		battery_voltage[CHANNELS_PERXPD];
 	xpp_line_t		battery;
 	ushort			battery_debounce[CHANNELS_PERXPD];
 	xpp_line_t		polarity;
 	ushort			polarity_counter[CHANNELS_PERXPD];
-	uint			offhook_timestamp[CHANNELS_PERXPD];
 	ushort			current_counter[CHANNELS_PERXPD];
 	xpp_line_t		ledstate[NUM_LEDS];	/* 0 - OFF, 1 - ON */
 	xpp_line_t		ledcontrol[NUM_LEDS];	/* 0 - OFF, 1 - ON */
@@ -280,7 +279,6 @@
 	ret = DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, DAA_REG_RING, value);
 	if(to_offhook) {
 		BIT_SET(xpd->offhook, pos);
-		priv->offhook_timestamp[pos] = priv->poll_counter;
 	} else {
 		BIT_CLR(xpd->offhook, pos);
 		BIT_CLR(xpd->cid_on, pos);
@@ -709,14 +707,21 @@
 	return 0;
 }
 
+#ifndef ZT_GET_PARAMS_V1
+#define zt_alarm_channel(a,b) zt_qevent_lock(a,( (b)==ZT_ALARM_NONE )? \
+	ZT_EVENT_NOALARM : ZT_EVENT_ALARM)
+#endif
 static void update_battery_status(xpd_t *xpd, byte data_low, lineno_t chipsel)
 {
 	struct FXO_priv_data	*priv;
 	byte			bat = abs((signed char)data_low);
 	byte			pol = IS_SET(data_low, 7);
-
-	priv = xpd->priv;
-	BUG_ON(!priv);
+	int			msec;
+
+
+	priv = xpd->priv;
+	BUG_ON(!priv);
+	priv->battery_voltage[chipsel] = data_low;
 	if(bat < BAT_THRESHOLD) {
 		/*
 		 * Check for battery voltage fluctuations
@@ -725,12 +730,12 @@
 			int	milliseconds;
 
 			milliseconds = priv->battery_debounce[chipsel]++ *
-					poll_battery_interval;
+				poll_battery_interval;
 			if(milliseconds > BAT_DEBOUNCE) {
 				LINE_DBG(SIGNAL, xpd, chipsel, "BATTERY OFF voltage=%d\n", bat);
 				BIT_CLR(priv->battery, chipsel);
 				if(SPAN_REGISTERED(xpd))
-					zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_ALARM);
+					zt_alarm_channel(&xpd->chans[chipsel], ZT_ALARM_RED);
 			}
 
 		}
@@ -740,45 +745,47 @@
 			LINE_DBG(SIGNAL, xpd, chipsel, "BATTERY ON voltage=%d\n", bat);
 			BIT_SET(priv->battery, chipsel);
 			if(SPAN_REGISTERED(xpd))
-				zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_NOALARM);
+				zt_alarm_channel(&xpd->chans[chipsel], ZT_ALARM_NONE);
 		}
 	}
 	/*
 	 * Handle reverse polarity
 	 */
-	if (IS_SET(xpd->offhook, chipsel)) {				/* Learn the current polarity */
-		if (priv->poll_counter - priv->offhook_timestamp[chipsel] < POLREV_START) {
-			priv->polarity_counter[chipsel] = 0;
-			if (pol)
-				BIT_SET(priv->polarity, chipsel);
-			else
-				BIT_CLR(priv->polarity, chipsel);
-		} else if (IS_SET(priv->polarity, chipsel) != pol) {	/* Polarity has reversed */
-			int	milliseconds;
-
-			milliseconds = priv->polarity_counter[chipsel]++ * poll_battery_interval;
-			if (milliseconds >= POLREV_THRESHOLD) {
-				if (pol)
-					BIT_SET(priv->polarity, chipsel);
-				else
-					BIT_CLR(priv->polarity, chipsel);
-				priv->polarity_counter[chipsel] = 0;
-				/* Inform Zaptel */
-				LINE_DBG(SIGNAL, xpd, chipsel, "Send ZT_EVENT_POLARITY\n");
-				zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_POLARITY);
+	if(IS_SET(priv->polarity, chipsel) == pol) {
+		/* same, same, nothing to see here, move on */
+		priv->polarity_counter[chipsel] = 0;
+		return;
+	}
+	/*
+	 * Track polarity reversals and debounce spikes.
+	 * Only reversals with long duration count.
+	 */
+	msec = priv->polarity_counter[chipsel]++ * poll_battery_interval;
+	if (msec >= POLREV_THRESHOLD) {
+		LINE_DBG(SIGNAL, xpd, chipsel, "Polarity is %s\n",
+				(pol)?"Positive":"Negative");
+		priv->polarity_counter[chipsel] = 0;
+		if (pol)
+			BIT_SET(priv->polarity, chipsel);
+		else
+			BIT_CLR(priv->polarity, chipsel);
+		/* polarity reversal during offhook should be reported to zaptel */
+		if(IS_SET(xpd->offhook, chipsel)) {
+			/* Inform Zaptel */
+			LINE_DBG(SIGNAL, xpd, chipsel, "Send ZT_EVENT_POLARITY\n");
+			zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_POLARITY);
 #if 0
-				/*
-				 * These two lines hangup the channel (by sending a message to
-				 * the firmware), and inform Zaptel that the line has been hung-up.
-				 * They are not needed if Asterisk does the hangup after receiving
-				 * a notification from Zaptel (which is sent by the above zt_qevent_lock().
-				 * Asterisk does that if it has "hanguponpolarityswitch=1" in zapata.conf.
-				 */
-				do_sethook(xpd, chipsel, 0);
-				update_line_status(xpd, chipsel, 0);
-				pcm_recompute(xpd, 0);
-#endif
-			}
+			/*
+			 * These two lines hangup the channel (by sending a message to
+			 * the firmware), and inform Zaptel that the line has been hung-up.
+			 * They are not needed if Asterisk does the hangup after receiving
+			 * a notification from Zaptel (which is sent by the above zt_qevent_lock().
+			 * Asterisk does that if it has "hanguponpolarityswitch=1" in zapata.conf.
+			 */
+			do_sethook(xpd, chipsel, 0);
+			update_line_status(xpd, chipsel, 0);
+			pcm_recompute(xpd, 0);
+#endif
 		}
 	}
 }
@@ -931,34 +938,38 @@
 	len += sprintf(page + len, "\t%-17s: ", "Channel");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%2d ", i % 10);
+			len += sprintf(page + len, "%3d ", i % 10);
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "ledstate");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%2d ", IS_SET(priv->ledstate[LED_GREEN], i));
+			len += sprintf(page + len, "%3d ", IS_SET(priv->ledstate[LED_GREEN], i));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "blinking");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%2d ", IS_BLINKING(priv,i,LED_GREEN));
+			len += sprintf(page + len, "%3d ", IS_BLINKING(priv,i,LED_GREEN));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "battery");
 	for_each_line(xpd, i) {
-		len += sprintf(page + len, "%2d ", IS_SET(priv->battery, i));
+		len += sprintf(page + len, "%3d ", IS_SET(priv->battery, i));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "polarity");
 	for_each_line(xpd, i) {
-		len += sprintf(page + len, "%2d ", IS_SET(priv->polarity, i));
+		len += sprintf(page + len, "%3d ", IS_SET(priv->polarity, i));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "polarity_counter");
 	for_each_line(xpd, i) {
-		len += sprintf(page + len, "%2d ", priv->polarity_counter[i]);
+		len += sprintf(page + len, "%3d ", priv->polarity_counter[i]);
+	}
+	len += sprintf(page + len, "\n\t%-17s: ", "battery_voltage");
+	for_each_line(xpd, i) {
+		len += sprintf(page + len, "%3d ", priv->battery_voltage[i]);
 	}
 #ifdef	WITH_METERING
 	len += sprintf(page + len, "\n\t%-17s: ", "metering");
 	for_each_line(xpd, i) {
-		len += sprintf(page + len, "%2d ", priv->metering_count[i]);
+		len += sprintf(page + len, "%3d ", priv->metering_count[i]);
 	}
 #endif
 	len += sprintf(page + len, "\n");

Modified: branches/1.4/xpp/card_global.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/card_global.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/card_global.c (original)
+++ branches/1.4/xpp/card_global.c Thu Jan 10 14:10:14 2008
@@ -78,7 +78,10 @@
 			regnum, subreg, data_low, data_high);
 	reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
 	reg_cmd->bytes = sizeof(*reg_cmd) - 1;	// do not count the 'bytes' field
+	reg_cmd->eoframe = 0;
+	reg_cmd->multibyte = 0;
 	REG_FIELD(reg_cmd, chipsel) = chipsel;
+	REG_FIELD(reg_cmd, reserved) = 0;	/* force reserved bits to 0 */
 	REG_FIELD(reg_cmd, read_request) = (writing) ? 0 : 1;
 	REG_FIELD(reg_cmd, do_subreg) = do_subreg;
 	REG_FIELD(reg_cmd, regnum) = regnum;
@@ -137,11 +140,10 @@
 	struct card_desc_struct	*card_desc;
 
 	BUG_ON(!xbus);
-	if((card_desc = kmalloc(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) {
+	if((card_desc = KZALLOC(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) {
 		XBUS_ERR(xbus, "Card description allocation failed.\n");
 		return -ENOMEM;
 	}
-	memset(card_desc, 0, sizeof(struct card_desc_struct));
 	card_desc->magic = CARD_DESC_MAGIC;
 	INIT_LIST_HEAD(&card_desc->card_list);
 	card_desc->xbus = xbus;
@@ -168,7 +170,7 @@
 	if(!xpd) {
 		XBUS_NOTICE(xbus, "%s: received %s for non-existing unit (%1d%1d)\n",
 				__FUNCTION__, cmd->name,
-				XPACKET_ADDR(pack).unit, XPACKET_ADDR(pack).subunit);
+				XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack));
 		return -EPROTO;
 	}
 	return CALL_XMETHOD(card_register_reply, xbus, xpd, reg);
@@ -205,7 +207,7 @@
 		return 0;
 	if(!xpd) {
 		snprintf(tmp_name, TMP_NAME_LEN, "%s(%1d%1d)", xbus->busname,
-			XPACKET_ADDR(pack).unit, XPACKET_ADDR(pack).subunit);
+			XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack));
 	} else {
 		snprintf(tmp_name, TMP_NAME_LEN, "%s/%s", xbus->busname, xpd->xpdname);
 	}

Modified: branches/1.4/xpp/card_pri.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/card_pri.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/card_pri.c (original)
+++ branches/1.4/xpp/card_pri.c Thu Jan 10 14:10:14 2008
@@ -1214,8 +1214,16 @@
 	if(!priv->layer1_up)
 		dchan_state(xpd, 0);
 	if(SPAN_REGISTERED(xpd) && xpd->span.alarms != alarms) {
-			xpd->span.alarms = alarms;
-			zt_alarm_notify(&xpd->span);
+		char	str1[MAX_PROC_WRITE];
+		char	str2[MAX_PROC_WRITE];
+
+		alarm2str(xpd->span.alarms, str1, sizeof(str1));
+		alarm2str(alarms, str2, sizeof(str2));
+		XPD_NOTICE(xpd, "Alarms: 0x%X (%s) => 0x%X (%s)\n",
+				xpd->span.alarms, str1,
+				alarms, str2);
+		xpd->span.alarms = alarms;
+		zt_alarm_notify(&xpd->span);
 	}
 	priv->reg_frs0 = data_low;
 	priv->layer1_replies++;

Modified: branches/1.4/xpp/init_card_9_29
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/init_card_9_29?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/init_card_9_29 (original)
+++ branches/1.4/xpp/init_card_9_29 Thu Jan 10 14:10:14 2008
@@ -126,23 +126,21 @@
 	my @pri_specs;
 	my $match;
 	my $setup;
+	# For lab tests
+	my $labfile = "${0}.setup";
 
 	# Source default files
-	foreach my $default_file ("${0}.setup", '/etc/default/zaptel', '/etc/sysconfig/zaptel') {
-		next unless -r $default_file;
-		my $setup_var = 'XPP_PRI_SETUP';
-		my %source_defaults;
-		my $setup_string;
-		%source_defaults = Zaptel::Config::Defaults::do_source($default_file, $setup_var);
-		last unless defined $source_defaults{$setup_var};
-		$setup_string = $source_defaults{$setup_var};
-		$setup_string =~ s/^\s+//;		# trim
-		$setup_string =~ s/\s+$//;		# trim
-		$setup_string =~ s/\s+/\n/g;		# cannonical spaces
-		logit "From $default_file: $setup_var=\n$setup_string\n";
-		@pri_specs = split(/\s+/, $setup_string);
-		last;
-	}
+	$ENV{ZAPTEL_DEFAULTS} = "$labfile" if -r "$labfile";
+	my $setup_var = 'XPP_PRI_SETUP';
+	my $setup_string;
+	my ($default_file, %source_defaults) =
+		Zaptel::Config::Defaults::source_vars($setup_var);
+	$setup_string = $source_defaults{$setup_var};
+	$setup_string =~ s/^\s+//;		# trim
+	$setup_string =~ s/\s+$//;		# trim
+	$setup_string =~ s/\s+/\n/g;		# cannonical spaces
+	logit "From $default_file: $setup_var=\n$setup_string\n";
+	@pri_specs = split(/\s+/, $setup_string);
 	push(@pri_specs, 'NUM/*=TE,E1');	# Fall back default (last)
 	logit "pri_specs: @pri_specs";
 SPEC:

Modified: branches/1.4/xpp/utils/Makefile
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/Makefile?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/Makefile (original)
+++ branches/1.4/xpp/utils/Makefile Thu Jan 10 14:10:14 2008
@@ -31,7 +31,6 @@
 XPD_FIRMWARE	= $(wildcard ../firmwares/*.hex)
 XPD_INIT_DATA	= $(XPD_FIRMWARE) init_fxo_modes
 XPD_INIT	= $(wildcard ../init_card_?_*) ../calibrate_slics xpp_fxloader
-XPD_INIT_PERL	= ../init_card_6_29 ../init_card_7_29 ../init_card_9_29
 
 # Variables that should be defined above, but need sane defaults:
 # FIXME: Are those values really sane?
@@ -82,7 +81,6 @@
 	$(INSTALL) -d $(DESTDIR)$(DATADIR)
 	$(INSTALL_DATA) $(XPD_INIT_DATA) $(DESTDIR)$(DATADIR)/
 	$(INSTALL) $(XPD_INIT) $(DESTDIR)$(DATADIR)/
-	$(INSTALL) astribank_hook $(DESTDIR)$(DATADIR)/
 	$(INSTALL) -d $(DESTDIR)$(MANDIR)
 	$(INSTALL_DATA) $(MAN_INSTALL) $(DESTDIR)$(MANDIR)/
 	$(INSTALL) -d $(DESTDIR)$(HOTPLUG_USB_DIR)
@@ -130,7 +128,7 @@
 init_fxo_modes: print_modes
 	./$< >$@
 
-perlcheck: $(PERL_SCRIPTS) $(XPD_INIT_PERL)
+perlcheck: $(PERL_SCRIPTS)
 	for i in $^; do perl -I./zconf -c $$i || exit 1; done
 	touch $@
 

Modified: branches/1.4/xpp/utils/astribank_hook
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/astribank_hook?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/astribank_hook (original)
+++ branches/1.4/xpp/utils/astribank_hook Thu Jan 10 14:10:14 2008
@@ -1,14 +1,22 @@
 #! /bin/sh
+
+# This is an example of an Astribank device hook. The xpp.rules file
+# calls /usr/share/zaptel/astribank_hook after a new Astribank is ready 
+# and after and old Astribank device has been destroyed.
+#
+# This example script sets the sync source, and thus makes the call to
+# xpp_sync in the init.d script unnecessary.
 
 set -e
 
-xpp_sync="/root/xortel/xpp_sync"
+xpp_sync="/usr/sbin/xpp_sync"
 
 me=`basename $0`
 INIT_DIR=`dirname $0`
 XPP_BASE=/proc/xpp
 export XPP_BASE
 LOGGER="logger -s -t $me"
+XPP_SYNC='auto'
 
 ZAPTEL_BOOT_DEBIAN=${ZAPTEL_BOOT_DEBIAN:-/etc/default/zaptel}
 ZAPTEL_BOOT_FEDORA=${ZAPTEL_BOOT_FEDORA:-/etc/sysconfig/zaptel}
@@ -29,16 +37,14 @@
 ## If you wish to trace this script:
 #exec 2> "/tmp/astribank_hook_$XBUS_NAME"
 
-$LOGGER -p kern.info "$ACTION: $*"
-
-$LOGGER -p kern.info "Change Sync"
+$LOGGER -p kern.info "$ACTION: $*. Setting sync to $XPP_SYNC."
 
 case "$ACTION" in
 add)
-	"$xpp_sync" auto
+	"$xpp_sync" $XPP_SYNC
 	;;
 remove)
-	"$xpp_sync" auto
+	"$xpp_sync" $XPP_SYNC
 	;;
 *)
 	;;

Modified: branches/1.4/xpp/utils/fpga_load.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/fpga_load.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/fpga_load.c (original)
+++ branches/1.4/xpp/utils/fpga_load.c Thu Jan 10 14:10:14 2008
@@ -28,6 +28,7 @@
 
 static int	verbose = LOG_WARNING;
 static char	*progname;
+static int	disconnected = 0;
 
 #define	MAX_HEX_LINES	10000
 #define	PACKET_SIZE	512
@@ -238,18 +239,22 @@
 	return snprintf(buf, len, "%s", tmp);
 }
 
-void my_usb_device_cleanup(struct my_usb_device *mydev, const struct astribank_type *abtype)
+void my_usb_device_cleanup(struct my_usb_device *mydev)
 {
 	assert(mydev != NULL);
 	if(!mydev->handle) {
 		return;	/* Nothing to do */
 	}
-	if(usb_release_interface(mydev->handle, abtype->my_interface_num) != 0) {
-		ERR("Releasing interface: usb: %s\n", usb_strerror());
+	if(!disconnected) {
+		if(usb_release_interface(mydev->handle, mydev->abtype->my_interface_num) != 0) {
+			ERR("Releasing interface: usb: %s\n", usb_strerror());
+		}
 	}
 	if(usb_close(mydev->handle) != 0) {
 		ERR("Closing device: usb: %s\n", usb_strerror());
 	}
+	disconnected = 1;
+	mydev->handle = NULL;
 }
 
 static void show_device_info(const struct my_usb_device *mydev)
@@ -295,8 +300,17 @@
 	}
 	ret = usb_bulk_write(mydev->handle, mydev->my_ep_out, p, len, timeout);
 	if(ret < 0) {
-		ERR("bulk_write to endpoint 0x%x failed: %s\n", mydev->my_ep_out, usb_strerror());
-		dump_packet("send_usb[ERR]", p, len);
+		/*
+		 * If the device was gone, it may be the
+		 * result of renumeration. Ignore it.
+		 */
+		if(ret != -ENODEV) {
+			ERR("bulk_write to endpoint 0x%x failed: %s\n", mydev->my_ep_out, usb_strerror());
+			dump_packet("send_usb[ERR]", p, len);
+		} else {
+			disconnected = 1;
+			my_usb_device_cleanup(mydev);
+		}
 		return ret;
 	} else if(ret != len) {
 		ERR("bulk_write to endpoint 0x%x short write: %s\n", mydev->my_ep_out, usb_strerror());
@@ -611,8 +625,8 @@
 	DBG("Renumerating with 0x%X\n", pt);
 	phead->header.op = pt;
 	ret = send_usb("renumerate[W]", mydev, phead, 1, TIMEOUT);
-	if(ret < 0)
-		return ret;
+	if(ret < 0 && ret != -ENODEV)
+			return ret;
 #if 0
 	/*
 	 * FIXME: we count on our USB firmware to reset the device... should we?
@@ -984,6 +998,6 @@
 	}
 	DBG("Exiting\n");
 dev_err:
-	my_usb_device_cleanup(&mydev, abtype);
+	my_usb_device_cleanup(&mydev);
 	return ret;
 }

Modified: branches/1.4/xpp/utils/lszaptel
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/lszaptel?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/lszaptel (original)
+++ branches/1.4/xpp/utils/lszaptel Thu Jan 10 14:10:14 2008
@@ -13,8 +13,20 @@
 
 use Zaptel;
 use Zaptel::Span;
+use Zaptel::Xpp;
+use Zaptel::Xpp::Xbus;
+use Zaptel::Xpp::Xpd;
+
+my @xbuses = Zaptel::Xpp::xbuses("SORT_CONNECTOR");
+my @xpds = map { $_->xpds } @xbuses;
 
 foreach my $span (Zaptel::spans()) {
+	my $spanno = $span->num;
+	my $xpd = $span->xpd;
+	my @lines;
+	my $index = 0;
+
+	@lines = @{$xpd->lines} if defined $xpd;
 	printf "### Span %2d: %s %s\n", $span->num, $span->name, $span->description;
 	foreach my $chan ($span->chans()) {
 		my %type_map = (
@@ -22,7 +34,11 @@
 			IN	=> 'Input'
 			);
 		my ($type) = map { $type_map{$_} or $_ } $chan->type || ("unknown");
-		printf "%3d %-10s %-10s %s\n", $chan->num, $type, $chan->signalling, $chan->info;
+		my $batt = "";
+		$batt = "(battery)" if $chan->battery;
+		printf "%3d %-10s %-10s %s %s\n",
+			$chan->num, $type, $chan->signalling, $chan->info, $batt;
+		$index++;
 	}
 }
 

Modified: branches/1.4/xpp/utils/zapconf
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zapconf?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zapconf (original)
+++ branches/1.4/xpp/utils/zapconf Thu Jan 10 14:10:14 2008
@@ -502,16 +502,9 @@
 }
 
 sub set_defaults {
-	my $zaptel_boot_debian = $ENV{ZAPTEL_BOOT_DEBIAN} || "/etc/default/zaptel";
-	my $zaptel_boot_fedora = $ENV{ZAPTEL_BOOT_FEDORA} || "/etc/sysconfig/zaptel";
-
 	# Source default files
-	my %source_defaults;
-	foreach my $defaults ($zaptel_boot_debian, $zaptel_boot_fedora) {
-		%source_defaults = Zaptel::Config::Defaults::do_source(
-					$defaults, keys(%zaptel_default_vars))
-						if -r $defaults;
-	}
+	my ($default_file, %source_defaults) =
+		Zaptel::Config::Defaults::source_vars(keys(%zaptel_default_vars));
 	map_zaptel_defaults(%source_defaults);
 	# Fixups
 	foreach my $val (values %default_zaptel_signalling, values %default_zapata_signalling) {

Modified: branches/1.4/xpp/utils/zaptel_hardware
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zaptel_hardware?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zaptel_hardware (original)
+++ branches/1.4/xpp/utils/zaptel_hardware Thu Jan 10 14:10:14 2008
@@ -75,9 +75,9 @@
 	my $loaded;
 	if($dev->is_astribank) {
 		$xbus = $dev->xbus;
-		$loaded = $dev->loaded;
 	}
-	die "driver should be '$driver' but is actually '$loaded'"
+	$loaded = $dev->loaded;
+	warn "driver should be '$driver' but is actually '$loaded'\n"
 		if defined($loaded) && $driver ne $loaded;
 	$driver = "$driver" . (($loaded) ? "+" : "-");
 	my $description = $dev->description || "";

Modified: branches/1.4/xpp/utils/zconf/Zaptel.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel.pm Thu Jan 10 14:10:14 2008
@@ -14,7 +14,7 @@
 
 Zaptel - Perl interface to Zaptel information
 
-This package allows access from perl to information about Zaptel
+This package allows access from Perl to information about Zaptel
 hardware and loaded Zaptel devices.
 
 =head1 SYNOPSIS

Modified: branches/1.4/xpp/utils/zconf/Zaptel/Chans.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel/Chans.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel/Chans.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel/Chans.pm Thu Jan 10 14:10:14 2008
@@ -10,24 +10,74 @@
 use strict;
 use Zaptel::Utils;
 
+=head1 NAME
+
+Zaptel::Chans - Perl interface to a Zaptel channel information
+
+This package allows access from perl to information about a Zaptel
+channel. It is part of the Zaptel Perl package.
+
+=head1 battery()
+
+Returns 1 if channel reports to have battery (A remote PBX connected to
+an FXO port), 0 if channel reports to not have battery and C<undef>
+otherwise.
+
+Currently only wcfxo and Astribank FXO modules report battery. For the
+rest of the channels 
+
+=head1 fqn()
+
+(Fully Qualified Name) Returns the full "name" of the channel.
+
+=head1 index()
+
+Returns the number of this channel (in the span).
+
+=head1 num()
+
+Returns the number of this channel as a Zaptel channel.
+
+=head signalling()
+
+Returns the signalling set for this channel through /etc/zaptel.conf .
+This is always empty before ztcfg was run. And shows the "other" type
+for FXS and for FXO.
+
+=head1 span()
+
+Returns a reference to the span to which this channel belongs.
+
+=head1 type()
+
+Returns the type of the channel: 'FXS', 'FXO', 'EMPTY', etc.
+
+=cut
+
 sub new($$$$$$) {
 	my $pack = shift or die "Wasn't called as a class method\n";
 	my $span = shift or die "Missing a span parameter\n";
+	my $index = shift;
 	my $line = shift or die "Missing an input line\n";
+	defined $index or die "Missing an index parameter\n";
+	my $self = {
+			'SPAN' => $span,
+			'INDEX' => $index,
+		};
+	bless $self, $pack;
 	my ($num, $fqn, $rest) = split(/\s+/, $line, 3);
 	$num or die "Missing a channel number parameter\n";
 	$fqn or die "Missing a channel fqn parameter\n";
 	my $signalling = '';
-	if(defined $rest && ($rest =~ s/(\w+)//)) {
-		$signalling = $1;
+	my $info = '';
+	if(defined $rest) {
+		if($rest =~ s/^\s*(\w+)\s*//) {
+			$signalling = $1;
+		}
+		if($rest =~ s/(.*)//) {
+			$info = $1;
+		}
 	}
-	my $info = '';
-	if(defined $rest && ($rest =~ s/(.*)//)) {
-		$info = $1;
-	}
-	my $self = {};
-	bless $self, $pack;
-	$self->{SPAN} = $span;
 	$self->{NUM} = $num;
 	$self->{FQN} = $fqn;
 	$self->{SIGNALLING} = $signalling;
@@ -37,6 +87,9 @@
 		$type = $1;		# An Astribank
 	} elsif ($fqn =~ m{\bWCFXO/.*}) {
 		$type = "FXO"; # wcfxo - x100p and relatives.
+		# A single port card. The driver issue RED alarm when
+		# There's no better
+		$self->{BATTERY} = !($span->description =~ /\bRED\b/);
 	} elsif ($fqn =~ m{\bFXS/.*}) {
 		$type = "FXS"; # likely Rhino
 	} elsif ($fqn =~ m{\bFXO/.*}) {
@@ -71,6 +124,18 @@
 	return $self;
 }
 
+=head1 probe_type()
+
+In the case of some cards, the information in /proc/zaptel is not good
+enough to tell the type of each channel. In this case an extra explicit
+probe is needed.
+
+Currently this is implemented by using some invocations of ztcfg(8).
+
+It may later be replaced by ztscan(8).
+
+=cut
+
 my $ztcfg = $ENV{ZTCFG} || '/sbin/ztcfg';
 sub probe_type($) {
 	my $self = shift;
@@ -102,4 +167,21 @@
 	return $type;
 }
 
+sub battery($) {
+	my $self = shift or die;
+	my $span = $self->span or die;
+
+	return undef unless $self->type eq 'FXO';
+	return $self->{BATTERY} if defined $self->{BATTERY};
+
+	my $xpd = $span->xpd;
+	my $index = $self->index;
+	return undef if !$xpd;
+
+	# It's an XPD (FXO)
+	my @lines = @{$xpd->lines};
+	my $line = $lines[$index];
+	return $line->battery;
+}
+
 1;

Modified: branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel/Config/Defaults.pm Thu Jan 10 14:10:14 2008
@@ -26,4 +26,29 @@
 	return %vars;
 }
 
+sub source_vars {
+	my @vars = @_;
+	my $default_file;
+	my %system_files = (
+			"/etc/default/zaptel"	=> 'Debian and friends',
+			"/etc/sysconfig/zaptel"	=> 'Red Hat and friends',
+		);
+
+	if(defined $ENV{ZAPTEL_DEFAULTS}) {
+		$default_file = $ENV{ZAPTEL_DEFAULTS};
+	} else {
+		foreach my $f (keys %system_files) {
+			if(-r $f) {
+				if(defined $default_file) {
+					die "An '$f' collides with '$default_file'";
+				}
+				$default_file = $f;
+			}
+		}
+	}
+	die "No default_file" unless $default_file;
+	my %vars = Zaptel::Config::Defaults::do_source($default_file, @vars);
+	return ($default_file, %vars);
+}
+
 1;

Modified: branches/1.4/xpp/utils/zconf/Zaptel/Hardware/PCI.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel/Hardware/PCI.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel/Hardware/PCI.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel/Hardware/PCI.pm Thu Jan 10 14:10:14 2008
@@ -91,7 +91,9 @@
 	'1397:08b4/b556'	=> { DRIVER => 'qozap', DESCRIPTION => 'Junghanns DuoBRI ISDN card' },
 	'1397:08b4'		=> { DRIVER => 'qozap', DESCRIPTION => 'Junghanns QuadBRI ISDN card' },
 	'1397:16b8'		=> { DRIVER => 'qozap', DESCRIPTION => 'Junghanns OctoBRI ISDN card' },
+	'1397:30b1'		=> { DRIVER => 'cwain', DESCRIPTION => 'HFC-E1 ISDN E1 card' },
 	'1397:2bd0'		=> { DRIVER => 'zaphfc', DESCRIPTION => 'HFC-S ISDN BRI card' },
+	'1397:f001'		=> { DRIVER => 'ztgsm', DESCRIPTION => 'HFC-GSM Cologne Chips GSM' },
 
 	# Rhino cards (based on pci.ids)
 	'0b0b:0105'	=> { DRIVER => 'r1t1', DESCRIPTION => 'Rhino R1T1' },
@@ -159,8 +161,19 @@
 	}
 
 	while(</sys/bus/pci/drivers/*/[0-9]*>) {
-		m,([^/]+)/([^/]+)$,,;
-		$pci_devs{$2}{LOADED} = $1;
+		m,^(.*?)/([^/]+)/([^/]+)$,;
+		my $prefix = $1;
+		my $drvname = $2;
+		my $id = $3;
+		my $l = readlink "$prefix/$drvname/module";
+		# Find the real module name (if we can).
+		if(defined $l) {
+			my $moduledir = "$prefix/$drvname/$l";
+			my $modname = $moduledir;
+			$modname =~ s:^.*/::;
+			$drvname = $modname;
+		}
+		$pci_devs{$id}{LOADED} = $drvname;
 	}
 	foreach (sort keys %pci_devs) {
 		my $dev = $pci_devs{$_};

Modified: branches/1.4/xpp/utils/zconf/Zaptel/Span.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel/Span.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel/Span.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel/Span.pm Thu Jan 10 14:10:14 2008
@@ -10,6 +10,7 @@
 use strict;
 use Zaptel::Utils;
 use Zaptel::Chans;
+use Zaptel::Xpp::Xpd;
 
 my $proc_base = "/proc/zaptel";
 
@@ -50,6 +51,12 @@
 	my $self = { NUM => $num };
 	bless $self, $pack;
 	$self->{TYPE} = "UNKNOWN";
+	my @xpds = Zaptel::Xpp::Xpd::xpds_by_spanno;
+	my $xpd = $xpds[$num];
+	if(defined $xpd) {
+		die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num;
+		$self->{XPD} = $xpd;
+	}
 	open(F, "$proc_base/$num") or die "Failed to open '$proc_base/$num\n";
 	my $head = <F>;
 	chomp $head;
@@ -92,16 +99,20 @@
 	$self->{IS_ZAPTEL_SYNC_MASTER} =
 		($self->{DESCRIPTION} =~ /\(MASTER\)/) ? 1 : 0;
 	$self->{CHANS} = [];
+	my @channels;
+	my $index = 0;
 	while(<F>) {
 		chomp;
 		s/^\s*//;
 		s/\s*$//;
 		next unless /\S/;
-		my $c = Zaptel::Chans->new($self, $_);
-		push(@{$self->{CHANS}}, $c);
+		my $c = Zaptel::Chans->new($self, $index, $_);
+		push(@channels, $c);
+		$index++;
 	}
 	close F;
-
+	@channels = sort { $a->num <=> $b->num } @channels;
+	$self->{CHANS} = \@channels;
 	$self->{YELLOW} = undef;
 	$self->{CRC4} = undef;
 	if($self->is_bri()) {

Modified: branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Xpd.pm
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Xpd.pm?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Xpd.pm (original)
+++ branches/1.4/xpp/utils/zconf/Zaptel/Xpp/Xpd.pm Thu Jan 10 14:10:14 2008
@@ -9,6 +9,8 @@
 #
 use strict;
 use Zaptel::Utils;
+use Zaptel::Xpp;
+use Zaptel::Xpp::Line;
 
 my $proc_base = "/proc/xpp";
 
@@ -64,21 +66,15 @@
 	return $result;
 }
 
-#
-# Backward compatibility for old drivers
-# before changeset:5119
-#
-# Newer drivers should directly have $xpd->spanno
-#
-sub spanno_of_xpd($) {
-	my $xpd = shift || die;
-
-	warn "Running on old driver. Keep going...\n";
-	use Zaptel;
-	my @spans = Zaptel::spans;
-
-	my ($span) = grep { $_->name eq $xpd->fqn } @spans;
-	return ($span) ? $span->num : 0;
+sub xpds_by_spanno() {
+	my @xbuses = Zaptel::Xpp::xbuses("SORT_CONNECTOR");
+	my @xpds = map { $_->xpds } @xbuses;
+	@xpds = grep { $_->spanno } @xpds;
+	@xpds = sort { $a->spanno <=> $b->spanno } @xpds;
+	my @spanno = map { $_->spanno } @xpds;
+	my @idx;
+	@idx[@spanno] = @xpds;	# The spanno is the index now
+	return @idx;
 }
 
 sub new($$) {
@@ -92,8 +88,18 @@
 	local $/ = "\n";
 	open(F, "$procdir/summary") || die "Missing summary file in $procdir";
 	my $head = <F>;
-	chomp $head;
-	# "XPD-00 (BRI_TE ,card present, span 3)"
+	chomp $head;	# "XPD-00 (BRI_TE ,card present, span 3)"
+	# The driver does not export the number of channels...
+	# Let's find it indirectly
+	while(<F>) {
+		chomp;
+		if(s/^\s*offhook\s*:\s*//) {
+			my @offhook = split;
+			@offhook || die "No channels in '$procdir/summary'";
+			$self->{CHANNELS} = @offhook;
+			last;
+		}
+	}
 	close F;
 	$head =~ s/^(XPD-(\d\d))\s+// || die;
 	$self->{ID} = $2;
@@ -105,13 +111,12 @@
 	#warn "Garbage in '$procdir/summary': rest='$rest'\n" if $rest;
 	if($span =~ s/span\s+(\d+)//) {	# since changeset:5119
 		$self->{SPANNO} = $1;
-	} else {
-		$self->{SPANNO} = $self->spanno_of_xpd;
 	}
 	$self->{TYPE} = $type;
 	$self->{IS_BRI} = ($type =~ /BRI_(NT|TE)/);
 	$self->{IS_PRI} = ($type =~ /[ETJ]1_(NT|TE)/);
 	$self->{IS_DIGITAL} = ( $self->{IS_BRI} || $self->{IS_PRI} );
+	Zaptel::Xpp::Line->create_all($self, $procdir);
 	return $self;
 }
 

Modified: branches/1.4/xpp/xbus-core.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/xbus-core.c?view=diff&rev=3646&r1=3645&r2=3646
==============================================================================
--- branches/1.4/xpp/xbus-core.c (original)
+++ branches/1.4/xpp/xbus-core.c Thu Jan 10 14:10:14 2008
@@ -282,11 +282,10 @@
 	XBUS_DBG(GENERAL, xbus, "\n");
 	if (xbus->debugfs_data)
 		return -EBUSY;
-	d = kmalloc(sizeof(struct debugfs_data), GFP_KERNEL);
+	d = KZALLOC(sizeof(struct debugfs_data), GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 	try_module_get(THIS_MODULE);
-	memset(d, 0, sizeof(struct debugfs_data));
 	spin_lock_init(&d->lock);
 	d->xbus = xbus;
 	d->head = d->tail = 0;
@@ -463,7 +462,7 @@
 				num, XPACKET_LEN(pack),
 				XPACKET_IS_PCM(pack), XPACKET_PCMSLOT(pack),
 				XPACKET_OP(pack),
-				XPACKET_ADDR(pack).unit, XPACKET_ADDR(pack).subunit,

[... 619 lines stripped ...]



More information about the zaptel-commits mailing list