[libpri-commits] mattf: branch mattf/libpri-1.4-q921-rewrite r1300 - /team/mattf/libpri-1.4-q9...

SVN commits to the libpri project libpri-commits at lists.digium.com
Wed Nov 11 16:08:22 CST 2009


Author: mattf
Date: Wed Nov 11 16:08:18 2009
New Revision: 1300

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1300
Log:
Checkpoint: Able to start an overlapped call session from ISDN phone, and successfully stop multiframe mode when it sends us DISC

Modified:
    team/mattf/libpri-1.4-q921-rewrite/Makefile
    team/mattf/libpri-1.4-q921-rewrite/pri.c
    team/mattf/libpri-1.4-q921-rewrite/pri_internal.h
    team/mattf/libpri-1.4-q921-rewrite/pri_q921.h
    team/mattf/libpri-1.4-q921-rewrite/pri_q931.h
    team/mattf/libpri-1.4-q921-rewrite/q921.c
    team/mattf/libpri-1.4-q921-rewrite/q931.c

Modified: team/mattf/libpri-1.4-q921-rewrite/Makefile
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/Makefile?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/Makefile (original)
+++ team/mattf/libpri-1.4-q921-rewrite/Makefile Wed Nov 11 16:08:18 2009
@@ -144,7 +144,7 @@
 ifneq (${OSARCH},SunOS)
 	install -m 644 libpri.h $(INSTALL_PREFIX)$(INSTALL_BASE)/include
 	install -m 755 $(DYNAMIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
-	if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then /sbin/restorecon -v $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY); fi
+	#if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then /sbin/restorecon -v $(INSTALL_PREFIX)$(libdir)/$(DYNAMIC_LIBRARY); fi
 	( cd $(INSTALL_PREFIX)$(libdir) ; ln -sf libpri.so.$(SONAME) libpri.so)
 	install -m 644 $(STATIC_LIBRARY) $(INSTALL_PREFIX)$(libdir)
 	if test $$(id -u) = 0; then $(LDCONFIG) $(LDCONFIG_FLAGS) $(INSTALL_PREFIX)$(libdir); fi

Modified: team/mattf/libpri-1.4-q921-rewrite/pri.c
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/pri.c?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/pri.c (original)
+++ team/mattf/libpri-1.4-q921-rewrite/pri.c Wed Nov 11 16:08:18 2009
@@ -331,9 +331,7 @@
 	default:
 		break;
 	}
-	/* Start Q.921 layer, Wait if we're the network */
-	if (p)
-		q921_start(p, p->localtype == PRI_CPE);
+	p->k = p->timers[PRI_TIMER_K];
 	
 	return p;
 }

Modified: team/mattf/libpri-1.4-q921-rewrite/pri_internal.h
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/pri_internal.h?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/pri_internal.h (original)
+++ team/mattf/libpri-1.4-q921-rewrite/pri_internal.h Wed Nov 11 16:08:18 2009
@@ -500,6 +500,8 @@
 							   -1 - No reverse charging
 							    1 - Reverse charging
 							0,2-7 - Reserved for future use */
+	/*! \brief TEI associated with call */
+	int tei;
 	int t303_timer;
 	int t303_expirycnt;
 
@@ -612,13 +614,40 @@
 	return pri->bri && (((pri)->localtype == PRI_CPE) && ((pri)->tei == Q921_TEI_GROUP));
 }
 
-static inline int PRI_PTP(struct pri *mypri)
+static inline int NT_MODE(struct pri *mypri)
 {
 	struct pri *pri;
 
 	pri = PRI_MASTER(mypri);
 
-	return !pri->bri;
+	return pri->localtype == PRI_NETWORK;
+}
+
+static inline int TE_MODE(struct pri *mypri)
+{
+	struct pri *pri;
+
+	pri = PRI_MASTER(mypri);
+
+	return pri->localtype == PRI_CPE;
+}
+
+static inline int PTP_MODE(struct pri *mypri)
+{
+	struct pri *pri;
+
+	pri = PRI_MASTER(mypri);
+
+	return pri->tei == Q921_TEI_PRI;
+}
+
+static inline int PTMP_MODE(struct pri *mypri)
+{
+	struct pri *pri;
+
+	pri = PRI_MASTER(mypri);
+
+	return pri->tei == Q921_TEI_GROUP;
 }
 
 #define Q931_DUMMY_CALL_REFERENCE	-1

Modified: team/mattf/libpri-1.4-q921-rewrite/pri_q921.h
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/pri_q921.h?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/pri_q921.h (original)
+++ team/mattf/libpri-1.4-q921-rewrite/pri_q921.h Wed Nov 11 16:08:18 2009
@@ -169,22 +169,15 @@
 #define Q921_DEC(j) (j) = (((j) - 1) % 128)
 
 typedef enum q921_state {
-	Q921_DOWN = 0,
 	/* All states except Q921_DOWN are defined in Q.921 SDL diagrams */
 	Q921_TEI_UNASSIGNED = 1,
 	Q921_ASSIGN_AWAITING_TEI = 2,
 	Q921_ESTABLISH_AWAITING_TEI = 3,
 	Q921_TEI_ASSIGNED = 4,
-	Q921_LINK_CONNECTION_RELEASED = 4,	/* Also known as TEI_ASSIGNED */
-	Q921_AWAITING_ESTABLISH = 5,
 	Q921_AWAITING_ESTABLISHMENT = 5,
 	Q921_AWAITING_RELEASE = 6,
 	Q921_MULTI_FRAME_ESTABLISHED = 7,
-	Q921_LINK_CONNECTION_ESTABLISHED = 7,
 	Q921_TIMER_RECOVERY = 8,
-#if 1
-	Q921_NEGOTIATION,
-#endif
 } q921_state;
 
 static inline int Q921_ADD(int a, int b)
@@ -196,13 +189,13 @@
 extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx);
 
 /* Bring up the D-channel */
-extern void q921_start(struct pri *pri, int now);
+extern void q921_start(struct pri *pri);
 
 //extern void q921_reset(struct pri *pri, int reset_iqueue);
 
 extern pri_event *q921_receive(struct pri *pri, q921_h *h, int len);
 
-extern int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr);
+extern int q921_transmit_iframe(struct pri *pri, int tei, void *buf, int len, int cr);
 
 extern int q921_transmit_uiframe(struct pri *pri, void *buf, int len);
 

Modified: team/mattf/libpri-1.4-q921-rewrite/pri_q931.h
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/pri_q931.h?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/pri_q931.h (original)
+++ team/mattf/libpri-1.4-q921-rewrite/pri_q931.h Wed Nov 11 16:08:18 2009
@@ -452,7 +452,7 @@
 /* Q.SIG specific */
 #define QSIG_IE_TRANSIT_COUNT		0x31
 
-extern int q931_receive(struct pri *pri, q931_h *h, int len);
+extern int q931_receive(struct pri *pri, int tei, q931_h *h, int len);
 
 extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
 

Modified: team/mattf/libpri-1.4-q921-rewrite/q921.c
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/q921.c?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/q921.c (original)
+++ team/mattf/libpri-1.4-q921-rewrite/q921.c Wed Nov 11 16:08:18 2009
@@ -145,12 +145,11 @@
 		return;
 	}
 	pri->n202_counter++;
-#if 0
 	if (pri->n202_counter > pri->timers[PRI_TIMER_N202]) {
-		pri_error(pri, "Unable to assign TEI from network\n");
+		pri_error(pri, "Unable to receive TEI from network!\n");
+		pri->n202_counter = 0;
 		return;
 	}
-#endif
 	pri->ri = random() % 65535;
 	q921_send_tei(pri, Q921_TEI_IDENTITY_REQUEST, pri->ri, Q921_TEI_GROUP, 1);
 	pri_schedule_del(pri, pri->t202_timer);
@@ -739,13 +738,57 @@
 	return 0;
 }
 
+static struct pri * pri_find_tei(struct pri *vpri, int tei)
+{
+	struct pri *pri;
+	for (pri = vpri; pri; pri = pri->subchannel) {
+		if (pri->tei == tei)
+			return pri;
+	}
+
+	return NULL;
+}
+
 /* This is the equivalent of a DL-DATA request, as well as the I frame queued up outcome */
-int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
+int q921_transmit_iframe(struct pri *vpri, int tei, void *buf, int len, int cr)
 {
 	q921_frame *f, *prev=NULL;
+	struct pri *pri;
+
+	if (tei == Q921_TEI_GROUP) {
+		pri_error(vpri, "Huh?! Shouldn't be sending I-frames out the group TEI\n");
+		return 0;
+	}
+
+	pri = pri_find_tei(vpri, tei);
+
+	if (!pri) {
+		pri_error(vpri, "Huh?! Unable to locate PRI associated with TEI %d.  Did we have to ditch it due to error conditions?\n", tei);
+		return 0;
+	}
+
+	/* If we aren't in a state compatiable with DL-DATA requests, start getting us there here */
+	switch (pri->q921_state) {
+	case Q921_TEI_UNASSIGNED:
+		/* If we're unassigned, we have to DL-ESTABLISH first - first rev of this code is going to assume
+		 * we're PTMP, TE side.  We have different state rules when we're NT side */
+		q921_start(pri);
+		break;
+		
+	case Q921_TEI_ASSIGNED:
+		q921_establish_data_link(pri);
+		pri->l3initiated = 1;
+		q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);
+		break;
+	default:
+		break;
+	}
 
 	/* Figure B.7/Q.921 Page 70 */
 	switch (pri->q921_state) {
+	case Q921_TEI_UNASSIGNED:
+	case Q921_ASSIGN_AWAITING_TEI:
+	case Q921_TEI_ASSIGNED:
 	case Q921_TIMER_RECOVERY:
 	case Q921_AWAITING_ESTABLISHMENT:
 	case Q921_MULTI_FRAME_ESTABLISHED:
@@ -1220,7 +1263,7 @@
 	master->subchannel = NULL;
 	master->ev.gen.e = PRI_EVENT_DCHAN_DOWN;
 	master->schedev = 1;
-	q921_start(master, master->localtype == PRI_CPE);
+	q921_start(master);
 }
 
 static pri_event *q921_receive_MDL(struct pri *pri, q921_u *h, int len)
@@ -1262,11 +1305,17 @@
 				++tei;
 			sub = sub->subchannel;
 		}
+
+		if (tei >= Q921_TEI_GROUP) {
+			pri_error(pri, "Reached maximum TEI quota, cannot assign new TEI\n");
+			return NULL;
+		}
 		sub->subchannel = __pri_new_tei(-1, pri->localtype, pri->switchtype, pri, NULL, NULL, NULL, tei, 1);
 		if (!sub->subchannel) {
 			pri_error(pri, "Unable to allocate D-channel for new TEI %d\n", tei);
 			return NULL;
 		}
+		q921_setstate(sub->subchannel, Q921_TEI_ASSIGNED);
 		q921_send_tei(pri, Q921_TEI_IDENTITY_ASSIGNED, ri, tei, 1);
 		break;
 	case Q921_TEI_IDENTITY_ASSIGNED:
@@ -1323,14 +1372,14 @@
 
 static int is_command(struct pri *pri, q921_h *h)
 {
-	int	command =0;
+	int command = 0;
 	int c_r = h->s.h.c_r;
 
 	if ((pri->localtype == PRI_NETWORK && c_r == 0) ||
 		(pri->localtype == PRI_CPE && c_r == 1))
 		command = 1;
 
-	return( command );
+	return command;
 }
 
 static void q921_clear_exception_conditions(struct pri *pri)
@@ -1398,6 +1447,33 @@
 }
 #endif
 
+static pri_event *q921_disc_rx(struct pri *pri, q921_h *h)
+{
+	pri_event * res = NULL;
+
+	switch (pri->q921_state) {
+	case Q921_AWAITING_RELEASE:
+		q921_send_ua(pri, h->u.p_f);
+		break;
+	case Q921_MULTI_FRAME_ESTABLISHED:
+	case Q921_TIMER_RECOVERY:
+		q921_discard_iqueue(pri);
+		q921_send_ua(pri, h->u.p_f);
+		/* DL-RELEASE Indication */
+		stop_t200(pri);
+		if (pri->q921_state == Q921_MULTI_FRAME_ESTABLISHED)
+			stop_t203(pri);
+		q921_setstate(pri, Q921_TEI_ASSIGNED);
+		break;
+	default:
+		pri_error(pri, "Don't know what to do with DISC in state %d\n", pri->q921_state);
+		break;
+
+	}
+
+	return res;
+}
+
 static pri_event *q921_ua_rx(struct pri *pri, q921_h *h)
 {
 	pri_event * res = NULL;
@@ -1406,7 +1482,7 @@
 	case Q921_TEI_ASSIGNED:
 		pri_error(pri, "MDL-ERROR (C, D): UA received in state %d\n", pri->q921_state);
 		break;
-	case Q921_AWAITING_ESTABLISH:
+	case Q921_AWAITING_ESTABLISHMENT:
 		if (!h->u.p_f) {
 			pri_error(pri, "MDL-ERROR: Received UA with F = 0 while awaiting establishment\n");
 			break;
@@ -1699,7 +1775,8 @@
 
 			pri->reject_exception = 0;
 
-			res = q931_receive(pri, (q931_h *)h->i.data, len - 4);
+			//res = q931_receive(PRI_MASTER(pri), pri->tei, (q931_h *)h->i.data, len - 4);
+			res = q931_receive(pri, pri->tei, (q931_h *)h->i.data, len - 4);
 
 			if (h->i.p_f) {
 				q921_rr(pri, 1, 0);
@@ -1726,7 +1803,7 @@
 
 		if (!n_r_is_valid(pri, h->i.n_r)) {
 			n_r_error_recovery(pri);
-			q921_setstate(pri, Q921_AWAITING_ESTABLISH);
+			q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);
 		} else {
 			if (pri->q921_state == Q921_TIMER_RECOVERY) {
 				update_v_a(pri, h->i.n_r);
@@ -1951,14 +2028,14 @@
 #endif
 			} else if (!h->u.m2) {
 				if ((pri->sapi == Q921_SAPI_LAYER2_MANAGEMENT) && (pri->tei == Q921_TEI_GROUP)) {
-					pri_error(pri, "%s:%d FIXME!!!\n", __FUNCTION__, __LINE__);
-					return NULL;
 
 					q921_receive_MDL(pri, (q921_u *)h, len);
+
 				} else {
 					int res;
 
-					res = q931_receive(pri, (q931_h *) h->u.data, len - 3);
+					//res = q931_receive(PRI_MASTER(pri), pri->tei, (q931_h *) h->u.data, len - 3);
+					res = q931_receive(pri, pri->tei, (q931_h *) h->u.data, len - 3);
 					if (res == -1) {
 						return NULL;
 					}
@@ -1968,8 +2045,7 @@
 			}
 			break;
 		case 2:
-			pri_error(pri, "%s:%d FIXME!!!\n", __FUNCTION__, __LINE__);
-			return NULL;
+			return q921_disc_rx(pri, h);
 #if 0
 			if (pri->debug & (PRI_DEBUG_Q921_STATE | PRI_DEBUG_Q921_DUMP))
 				pri_message(pri, "-- Got Disconnect from peer.\n");
@@ -2147,7 +2223,6 @@
 
 static void q921_establish_data_link(struct pri *pri)
 {
-	pri->k = 20;
 	q921_clear_exception_conditions(pri);
 	pri->RC = 0;
 	stop_t203(pri);
@@ -2155,16 +2230,15 @@
 	q921_send_sabme(pri);
 }
 
-void q921_start(struct pri *pri, int isCPE)
-{
-	//q921_reset(pri, 1);
-	if ((pri->sapi == Q921_SAPI_LAYER2_MANAGEMENT) && (pri->tei == Q921_TEI_GROUP)) {
-#ifndef NO_OLD_CODE
+void q921_start(struct pri *pri)
+{
+	if (PTMP_MODE(pri)) {
 		q921_setstate(pri, Q921_TEI_UNASSIGNED);
-		if (isCPE)
+		if (TE_MODE(pri)) {
 			q921_tei_request(pri);
-#endif
+		}
 	} else {
+		/* PTP mode, no need for TEI management junk */
 		q921_establish_data_link(pri);
 		pri->l3initiated = 1;
 		q921_setstate(pri, Q921_AWAITING_ESTABLISHMENT);

Modified: team/mattf/libpri-1.4-q921-rewrite/q931.c
URL: http://svnview.digium.com/svn/libpri/team/mattf/libpri-1.4-q921-rewrite/q931.c?view=diff&rev=1300&r1=1299&r2=1300
==============================================================================
--- team/mattf/libpri-1.4-q921-rewrite/q931.c (original)
+++ team/mattf/libpri-1.4-q921-rewrite/q931.c Wed Nov 11 16:08:18 2009
@@ -3850,12 +3850,12 @@
 	*mhb = mh;
 }
 
-static int q931_xmit(struct pri *ctrl, q931_h *h, int len, int cr, int uiframe)
+static int q931_xmit(struct pri *ctrl, int tei, q931_h *h, int len, int cr, int uiframe)
 {
 	if (uiframe) {
 		q921_transmit_uiframe(ctrl, h, len);
 	} else {
-		q921_transmit_iframe(ctrl, h, len, cr);
+		q921_transmit_iframe(ctrl, tei, h, len, cr);
 	}
 	/* The transmit operation might dump the q921 header, so logging the q931
 	   message body after the transmit puts the sections of the message in the
@@ -3975,7 +3975,7 @@
 				ctrl, ctrl->tei, ctrl->sapi,
 				call->pri, call->pri->tei, call->pri->sapi);
 		}
-		q931_xmit(ctrl, h, len, 1, uiframe);
+		q931_xmit(ctrl, ctrl->tei, h, len, 1, uiframe);
 	}
 	call->acked = 1;
 	return 0;
@@ -5697,7 +5697,7 @@
 	return cur;
 }
 
-int q931_receive(struct pri *ctrl, q931_h *h, int len)
+int q931_receive(struct pri *ctrl, int tei, q931_h *h, int len)
 {
 	q931_mh *mh;
 	q931_call *c;
@@ -5731,7 +5731,7 @@
 		   KLUDGE this by changing byte 4 from a 0xf (SERVICE) 
 		   to a 0x7 (SERVICE ACKNOWLEDGE) */
 		h->raw[h->crlen + 2] -= 0x8;
-		q931_xmit(ctrl, h, len, 1, 0);
+		q931_xmit(ctrl, ctrl->tei, h, len, 1, 0);
 		return 0;
 	}
 




More information about the libpri-commits mailing list