r3265 - in trunk/src/target/gsm: include/gsmd src/gsmd src/util

tick at sita.openmoko.org tick at sita.openmoko.org
Thu Oct 25 12:35:32 CEST 2007


Author: tick
Date: 2007-10-25 12:35:26 +0200 (Thu, 25 Oct 2007)
New Revision: 3265

Modified:
   trunk/src/target/gsm/include/gsmd/usock.h
   trunk/src/target/gsm/src/gsmd/sms_pdu.c
   trunk/src/target/gsm/src/util/event.c
   trunk/src/target/gsm/src/util/shell.c
Log:
Adding decoder TP-DCS, and it's based on 3GPP TS23.038 Clause 4. (Erin Yueh)


Modified: trunk/src/target/gsm/include/gsmd/usock.h
===================================================================
--- trunk/src/target/gsm/include/gsmd/usock.h	2007-10-25 10:25:43 UTC (rev 3264)
+++ trunk/src/target/gsm/include/gsmd/usock.h	2007-10-25 10:35:26 UTC (rev 3265)
@@ -121,6 +121,58 @@
 	ALPHABET_RESERVED		= (0x11<<2),
 };
 
+/* bit 1 & bit0 */
+enum gsmd_sms_msg_class {
+	MSG_CLASS_CLASS0	= 0,
+	MSG_CLASS_CLASS1	= 1,
+	MSG_CLASS_CLASS2	= 2,
+	MSG_CLASS_CLASS3	= 3,
+	MSG_CLASS_NONE		= 4,
+};
+
+/* bit 3 & bit 2*/
+enum gsmd_sms_alphabet_type {
+	SMS_ALPHABET_7_BIT_DEFAULT 	= 0,
+	SMS_ALPHABET_8_BIT		= 1,
+	SMS_ALPHABET_UCS2		= 2,
+	SMS_ALPHABET_RESESRVED		= 3,
+};
+
+enum gsmd_sms_msg_compressed {
+	NOT_COMPRESSED	= 0,
+	COMPRESSED	= 1,
+};
+
+/* message waiting indication */
+enum gsmd_sms_msg_waiting_group {
+	MESSAGE_WAITING_NONE		= 0,
+	MESSAGE_WAITING_DISCARD	= 1,
+	MESSAGE_WAITING_STORE		= 2,
+	MESSAGE_WAITING_NONE_1111	= 3,
+};
+
+enum gsmd_sms_msg_waiting_type {
+	MESSAGE_WAITING_VOICEMAIL	= 0,
+	MESSAGE_WAITING_FAX 		= 1,
+	MESSAGE_WAITING_EMAIL 		= 2,
+	MESSAGE_WAITING_OTHER 		= 3,
+};
+
+enum gsmd_sms_msg_waiting_active {
+	NOT_ACTIVE	= 0,
+	ACTIVE		= 1,
+};
+
+struct gsmd_sms_datacodingscheme {
+	enum gsmd_sms_msg_class		        msg_class;
+	enum gsmd_sms_alphabet_type 		alphabet;
+	enum gsmd_sms_msg_compressed        	is_compressed;
+	enum gsmd_sms_msg_waiting_group 	mwi_group;
+	enum gsmd_sms_msg_waiting_active    	mwi_active;
+	enum gsmd_sms_msg_waiting_type    	mwi_kind;
+	u_int8_t                            	raw_dcs_data;
+} __attribute__ ((packed));
+
 /* Refer to GSM 03.40 subclause 9.2.3.1 */
 enum gsmd_sms_tp_mti {
 	GSMD_SMS_TP_MTI_DELIVER		= 0,
@@ -325,6 +377,8 @@
 	u_int8_t length;	
 	u_int8_t coding_scheme;
 	int has_header;
+	int is_voicemail;
+	struct gsmd_sms_datacodingscheme dcs;
 	char data[GSMD_SMS_DATA_MAXLEN+1];	
 } __attribute__ ((packed));
 

Modified: trunk/src/target/gsm/src/gsmd/sms_pdu.c
===================================================================
--- trunk/src/target/gsm/src/gsmd/sms_pdu.c	2007-10-25 10:25:43 UTC (rev 3264)
+++ trunk/src/target/gsm/src/gsmd/sms_pdu.c	2007-10-25 10:35:26 UTC (rev 3265)
@@ -87,6 +87,9 @@
 	if (len < 1 || len < 1 + src[0] + pdulen || pdulen < 1)
 		return 1;
 
+	/* init voicemail is false */
+	dst->payload.is_voicemail = 0;
+	
 	/* Skip SMSC number and its Type-of-address */
 	len -= 1 + src[0];
 	src += 1 + src[0];
@@ -111,7 +114,19 @@
 
 		len -= 3 + i;
 		src += 3 + i;
+		
+		/* check voicemail by TP-PID */
+		if(src[0] == 0x5f)  /* return call message */
+			dst->payload.is_voicemail = 1;
 
+		/* decode TP-DCS */
+		if(sms_pdu_decode_dcs(&dst->payload.dcs,src+1))
+			return 1;
+		/* check voicemail by MWI */
+		if(dst->payload.dcs.mwi_kind == MESSAGE_WAITING_VOICEMAIL &&
+			(dst->payload.dcs.mwi_group == MESSAGE_WAITING_DISCARD || 
+			dst->payload.dcs.mwi_group == MESSAGE_WAITING_STORE))
+			dst->payload.is_voicemail = 1;
 		/* TP-DCS */
 		switch (src[1] >> 4) {
 		case 0x0 ... 3:	/* General Data Coding indication */
@@ -315,3 +330,88 @@
 	memcpy(dst->data, src + 6, len - 6);
 	return 0;
 }
+
+/* Refer to GSM 03.38 Clause 4, for TP-DCS */  
+int sms_pdu_decode_dcs(struct gsmd_sms_datacodingscheme *dcs, 
+	const u_int8_t *data)
+{
+	int pos = 0, i;
+
+	/* init dcs value */
+	dcs->mwi_active		= NOT_ACTIVE;
+	dcs->mwi_kind		= MESSAGE_WAITING_OTHER;
+	
+	/* bits 7-6 */
+	i = ( data[pos] & 0xC0 ) >> 6;
+	switch( i )
+	{
+	case 0: /* pattern 00xx xxxx */
+		dcs->is_compressed = data[pos] & 0x20;
+		if( data[pos] & 0x10 )
+			dcs->msg_class = data[pos] & 0x03;
+		else
+			/* no class information */
+			dcs->msg_class = MSG_CLASS_NONE;
+		dcs->alphabet  = ( data[pos] & 0x0C ) >> 2;     
+		dcs->mwi_group 	= MESSAGE_WAITING_NONE;
+		break;
+	case 3: /* pattern 1111 xxxx */
+		/* bits 5-4 */
+		if( (data[pos] & 0x30) == 0x30 )
+		{
+			/* bit 3 is reserved */
+			/* bit 2 */
+			dcs->alphabet = (data[pos] & 0x04 ) ? SMS_ALPHABET_8_BIT:
+					   SMS_ALPHABET_7_BIT_DEFAULT;
+			/* bits 1-0 */
+			dcs->msg_class = data[pos] & 0x03;
+			/* set remaining fields */
+			dcs->is_compressed  = NOT_COMPRESSED;
+			dcs->mwi_group    = MESSAGE_WAITING_NONE_1111;
+		}
+		else
+		{
+			/* Message waiting groups */
+			dcs->is_compressed  = NOT_COMPRESSED;
+			dcs->msg_class      = MSG_CLASS_NONE;
+			/* bits 5-4 */
+			if( (data[pos] & 0x30) == 0x00 )
+			{
+				dcs->mwi_group  = MESSAGE_WAITING_DISCARD;
+				dcs->alphabet   = SMS_ALPHABET_7_BIT_DEFAULT;
+			}
+			else if( (data[pos] & 0x30) == 0x10 )
+			{
+				dcs->mwi_group  = MESSAGE_WAITING_STORE;
+				dcs->alphabet   = SMS_ALPHABET_7_BIT_DEFAULT;
+			}
+			else
+			{
+				dcs->mwi_group  = MESSAGE_WAITING_STORE;
+				dcs->alphabet   = SMS_ALPHABET_UCS2;
+			}
+			/* bit 3 */
+			dcs->mwi_active = ( data[pos] & 0x08 ) ? ACTIVE : 
+				NOT_ACTIVE;
+			/* bit 2 is reserved */
+			/* bits 1-0 */
+			dcs->mwi_kind = data[pos] & 0x03;
+		}
+		break;
+	default:
+		/* reserved values	*/
+		dcs->msg_class      	= MSG_CLASS_NONE;
+		dcs->alphabet       	= SMS_ALPHABET_7_BIT_DEFAULT;
+		dcs->is_compressed  	= NOT_COMPRESSED;
+		dcs->mwi_group    	= MESSAGE_WAITING_NONE;
+		dcs->mwi_active		= NOT_ACTIVE;
+		dcs->mwi_kind		= MESSAGE_WAITING_OTHER;
+		break;
+	}
+
+	if ( dcs->alphabet > SMS_ALPHABET_UCS2 )
+		dcs->alphabet = SMS_ALPHABET_7_BIT_DEFAULT;
+	/* keep raw dcs data*/
+	dcs->raw_dcs_data = data[pos];
+	return 0;
+}

Modified: trunk/src/target/gsm/src/util/event.c
===================================================================
--- trunk/src/target/gsm/src/util/event.c	2007-10-25 10:25:43 UTC (rev 3264)
+++ trunk/src/target/gsm/src/util/event.c	2007-10-25 10:35:26 UTC (rev 3265)
@@ -42,6 +42,8 @@
 	char payload[GSMD_SMS_DATA_MAXLEN];
 	if (aux->u.sms.inlined) {
 		sms = (struct gsmd_sms_list *) aux->data;
+		if(sms->payload.is_voicemail)
+			printf("EVENT: You have a voice mail \n");
 		printf("EVENT: Incoming SMS from/to %s%s, at %i%i-%i%i-%i%i "
 				"%i%i:%i%i:%i%i, GMT%c%i\n",
 				((sms->addr.type & __GSMD_TOA_TON_MASK) ==

Modified: trunk/src/target/gsm/src/util/shell.c
===================================================================
--- trunk/src/target/gsm/src/util/shell.c	2007-10-25 10:25:43 UTC (rev 3264)
+++ trunk/src/target/gsm/src/util/shell.c	2007-10-25 10:35:26 UTC (rev 3265)
@@ -152,6 +152,8 @@
 	case GSMD_SMS_LIST:
 	case GSMD_SMS_READ:
 		sms = (struct gsmd_sms_list *) ((void *) gmh + sizeof(*gmh));
+		if(sms->payload.is_voicemail)
+			printf("it's a voicemail \n");
 		printf("%s message %i from/to %s%s, at %i%i-%i%i-%i%i "
 				"%i%i:%i%i:%i%i, GMT%c%i\n",
 				msgtype[sms->stat], sms->index,





More information about the commitlog mailing list