[libpri-commits] rmudgett: branch 1.4 r2103 - in /branches/1.4: pri_q921.h q921.c

SVN commits to the libpri project libpri-commits at lists.digium.com
Fri Nov 5 14:48:04 CDT 2010


Author: rmudgett
Date: Fri Nov  5 14:48:00 2010
New Revision: 2103

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=2103
Log:
Convert TEI identity defines to enum and create 2str() function.

Modified:
    branches/1.4/pri_q921.h
    branches/1.4/q921.c

Modified: branches/1.4/pri_q921.h
URL: http://svnview.digium.com/svn/libpri/branches/1.4/pri_q921.h?view=diff&rev=2103&r1=2102&r2=2103
==============================================================================
--- branches/1.4/pri_q921.h (original)
+++ branches/1.4/pri_q921.h Fri Nov  5 14:48:00 2010
@@ -69,13 +69,16 @@
 #define Q921_SAPI_LAYER2_MANAGEMENT	63
 
 
-#define Q921_TEI_IDENTITY_REQUEST			1
-#define Q921_TEI_IDENTITY_ASSIGNED			2
-#define Q921_TEI_IDENTITY_DENIED			3
-#define Q921_TEI_IDENTITY_CHECK_REQUEST		4
-#define Q921_TEI_IDENTITY_CHECK_RESPONSE	5
-#define Q921_TEI_IDENTITY_REMOVE			6
-#define Q921_TEI_IDENTITY_VERIFY			7
+/*! Q.921 TEI management message type */
+enum q921_tei_identity {
+	Q921_TEI_IDENTITY_REQUEST = 1,
+	Q921_TEI_IDENTITY_ASSIGNED = 2,
+	Q921_TEI_IDENTITY_DENIED = 3,
+	Q921_TEI_IDENTITY_CHECK_REQUEST = 4,
+	Q921_TEI_IDENTITY_CHECK_RESPONSE = 5,
+	Q921_TEI_IDENTITY_REMOVE = 6,
+	Q921_TEI_IDENTITY_VERIFY = 7,
+};
 
 typedef struct q921_header {
 #if __BYTE_ORDER == __BIG_ENDIAN

Modified: branches/1.4/q921.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/q921.c?view=diff&rev=2103&r1=2102&r2=2103
==============================================================================
--- branches/1.4/q921.c (original)
+++ branches/1.4/q921.c Fri Nov  5 14:48:00 2010
@@ -61,6 +61,36 @@
 
 /*!
  * \internal
+ * \brief Convert Q.921 TEI management message type to a string.
+ *
+ * \param message Q.921 TEI management message type to convert.
+ *
+ * \return TEI management message type name string
+ */
+static const char *q921_tei_mgmt2str(enum q921_tei_identity message)
+{
+	switch (message) {
+	case Q921_TEI_IDENTITY_REQUEST:
+		return "TEI Identity Request";
+	case Q921_TEI_IDENTITY_ASSIGNED:
+		return "TEI Identity Assigned";
+	case Q921_TEI_IDENTITY_CHECK_REQUEST:
+		return "TEI Identity Check Request";
+	case Q921_TEI_IDENTITY_REMOVE:
+		return "TEI Identity Remove";
+	case Q921_TEI_IDENTITY_DENIED:
+		return "TEI Identity Denied";
+	case Q921_TEI_IDENTITY_CHECK_RESPONSE:
+		return "TEI Identity Check Response";
+	case Q921_TEI_IDENTITY_VERIFY:
+		return "TEI Identity Verify";
+	}
+
+	return "Unknown";
+}
+
+/*!
+ * \internal
  * \brief Convert Q.921 state to a string.
  *
  * \param state Q.921 state to convert.
@@ -168,7 +198,7 @@
 	return 0;
 }
 
-static void q921_send_tei(struct pri *ctrl, int message, int ri, int ai, int iscommand)
+static void q921_send_tei(struct pri *ctrl, enum q921_tei_identity message, int ri, int ai, int iscommand)
 {
 	q921_u *f;
 	struct q921_link *link;
@@ -187,7 +217,9 @@
 	f->data[3] = message;
 	f->data[4] = (ai << 1) | 1;
 	if (ctrl->debug & PRI_DEBUG_Q921_STATE) {
-		pri_message(ctrl, "Sending TEI management message %d, TEI=%d\n", message, ai);
+		pri_message(ctrl,
+			"Sending TEI management message %d(%s), TEI=%d\n",
+			message, q921_tei_mgmt2str(message), ai);
 	}
 	q921_transmit(ctrl, (q921_h *)f, 8);
 	free(f);
@@ -972,7 +1004,7 @@
 void q921_dump(struct pri *ctrl, q921_h *h, int len, int showraw, int txrx)
 {
 	int x;
-	char *type;
+	const char *type;
 	char direction_tag;
 	
 	direction_tag = txrx ? '>' : '<';
@@ -1111,33 +1143,8 @@
 		ri = (h->u.data[1] << 8) | h->u.data[2];
 		tei = (h->u.data[4] >> 1);
 		/* TEI assignment related */
-		switch (h->u.data[3]) {
-		case Q921_TEI_IDENTITY_REQUEST:
-			type = "TEI Identity Request";
-			break;
-		case Q921_TEI_IDENTITY_ASSIGNED:
-			type = "TEI Identity Assigned";
-			break;
-		case Q921_TEI_IDENTITY_CHECK_REQUEST:
-			type = "TEI Identity Check Request";
-			break;
-		case Q921_TEI_IDENTITY_REMOVE:
-			type = "TEI Identity Remove";
-			break;
-		case Q921_TEI_IDENTITY_DENIED:
-			type = "TEI Identity Denied";
-			break;
-		case Q921_TEI_IDENTITY_CHECK_RESPONSE:
-			type = "TEI Identity Check Response";
-			break;
-		case Q921_TEI_IDENTITY_VERIFY:
-			type = "TEI Identity Verify";
-			break;
-		default:
-			type = "Unknown";
-			break;
-		}
-		pri_message(ctrl, "%c MDL Message: %s (%d)\n", direction_tag, type, h->u.data[3]);
+		type = q921_tei_mgmt2str(h->u.data[3]);
+		pri_message(ctrl, "%c MDL Message: %d(%s)\n", direction_tag, h->u.data[3], type);
 		pri_message(ctrl, "%c RI: %d\n", direction_tag, ri);
 		pri_message(ctrl, "%c Ai: %d E:%d\n", direction_tag, (h->u.data[4] >> 1) & 0x7f, h->u.data[4] & 1);
 	}
@@ -1218,7 +1225,8 @@
 		}
 
 		if (tei != Q921_TEI_GROUP) {
-			pri_error(ctrl, "Received TEI identity request with invalid TEI %d\n", tei);
+			pri_error(ctrl, "Received %s with invalid TEI %d\n",
+				q921_tei_mgmt2str(Q921_TEI_IDENTITY_REQUEST), tei);
 			q921_send_tei(ctrl, Q921_TEI_IDENTITY_DENIED, ri, tei, 1);
 			return NULL;
 		}




More information about the libpri-commits mailing list