summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gsmd/sms_pdu.c100
-rw-r--r--src/util/event.c2
-rw-r--r--src/util/shell.c2
3 files changed, 104 insertions, 0 deletions
diff --git a/src/gsmd/sms_pdu.c b/src/gsmd/sms_pdu.c
index d461999..ae7a69d 100644
--- a/src/gsmd/sms_pdu.c
+++ b/src/gsmd/sms_pdu.c
@@ -87,6 +87,9 @@ int sms_pdu_to_msg(struct gsmd_sms_list *dst,
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 @@ int sms_pdu_to_msg(struct gsmd_sms_list *dst,
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 @@ int cbs_pdu_to_msg(struct gsmd_cbm *dst, u_int8_t *src, int pdulen, int len)
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;
+}
diff --git a/src/util/event.c b/src/util/event.c
index ea0dcb4..f14f906 100644
--- a/src/util/event.c
+++ b/src/util/event.c
@@ -42,6 +42,8 @@ static int insms_handler(struct lgsm_handle *lh, int evt,
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) ==
diff --git a/src/util/shell.c b/src/util/shell.c
index 922b64e..096b2cf 100644
--- a/src/util/shell.c
+++ b/src/util/shell.c
@@ -152,6 +152,8 @@ static int sms_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
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,
personal git repositories of Harald Welte. Your mileage may vary