Update GSM SMS (LTE part).

This commit is contained in:
bossiel 2010-04-12 23:41:41 +00:00
parent 5743765ea1
commit 258f06c826
19 changed files with 655 additions and 80 deletions

View File

@ -132,14 +132,12 @@ int tsk_buffer_appendEx(tsk_buffer_t* self, const char* format, ...)
*/
int tsk_buffer_append(tsk_buffer_t* self, const void* data, size_t size)
{
if(self && size)
{
if(self && size){
size_t oldsize = self->size;
size_t newsize = oldsize + size;
self->data = tsk_realloc(self->data, newsize);
if(self->data)
{
if(self->data){
memcpy((void*)(TSK_BUFFER_TO_U8(self) + oldsize), data, size);
self->size = newsize;
return 0;

View File

@ -69,7 +69,7 @@ TSK_BEGIN_DECLS
* @param self @ref tsk_buffer_t object.
*/
#define TSK_BUFFER(self) ((tsk_buffer_t*)self)
#define TSK_BUFFER_DATA(self) (self ? TSK_BUFFER(self)->data : 0)
#define TSK_BUFFER_DATA(self) (self ? TSK_BUFFER(self)->data : tsk_null)
#define TSK_BUFFER_SIZE(self) (self ? TSK_BUFFER(self)->size : 0)
/**@ingroup tsk_buffer_group

View File

@ -49,7 +49,7 @@ typedef void tsk_object_t;
* In all case this operation will set the pointer (the object itself) to NULL.
* @param self The object to free or unref.
**/
#define TSK_OBJECT_SAFE_FREE(self) tsk_object_unref(self), self = tsk_null
#define TSK_OBJECT_SAFE_FREE(self) if(self) tsk_object_unref(self), self = tsk_null
/**@ingroup tsk_object_group
* tag a structure as an object. If this macro is used then you MUST

View File

@ -99,7 +99,8 @@ TINYSAK_API void tsk_str_to_hex(const char *str, size_t size, uint8_t* hex);
* @def tsk_strnequals
*/
#define tsk_strtrim_both(str) tsk_strtrim_left(str), tsk_strtrim_right(str);
#define tsk_strempty(s) (*s == '\0')
#define tsk_strempty(s) (*(s) == '\0')
#define tsk_strnullORempty(s) (!(s) || tsk_strempty((s)))
#define tsk_striequals(s1, s2) (tsk_stricmp((const char*)(s1), (const char*)(s2)) ? tsk_false : tsk_true)
#define tsk_strniequals(s1, s2, n) (tsk_strnicmp((const char*)(s1), (const char*)(s2), n) ? tsk_false : tsk_true)
#define tsk_strequals(s1, s2) (tsk_strcmp((const char*)(s1), (const char*)(s2)) ? tsk_false : tsk_true)

View File

@ -44,8 +44,8 @@ typedef struct tsms_tpdu_ctx_s
TSK_DECLARE_OBJECT;
uint8_t mr;
char* smsc; /**< SMSC*/
char* phone; /**< Remote Phone number. */
tsms_address_t* smsc; /**< SMSC*/
tsms_address_t* phone; /**< Remote Phone number. */
tsms_alphabet_t alphabet; /**< User data. */
tsk_buffer_t* usrdata; /**< User data. */
}
@ -53,7 +53,7 @@ tsms_tpdu_ctx_t;
typedef void tsms_tpdu_ctx_handle_t;
TINYSMS_API tsms_tpdu_ctx_handle_t* tsms_pdu_ctx_create(uint8_t mr, tsms_address_t smsc, tsms_address_t phone);
TINYSMS_API tsms_tpdu_ctx_handle_t* tsms_pdu_ctx_create(uint8_t mr, tsms_address_string_t smsc, tsms_address_string_t phone);
TINYSMS_API int tsms_pdu_ctx_set_alphabet(tsms_tpdu_ctx_handle_t* handle, tsms_alphabet_t alphabet);
TINYSMS_API int tsms_pdu_ctx_set_usrdata(tsms_tpdu_ctx_handle_t* handle, const void* data, size_t size);
TINYSMS_API tsk_buffer_t* tsms_pdu_ctx_getSUBMIT(tsms_tpdu_ctx_handle_t* handle);

View File

@ -34,7 +34,6 @@
#include "tinySMS/tsms_common.h"
TSMS_BEGIN_DECLS
#define TSMS_TPDU_COMMAND_CREATE() tsk_object_new(tsms_tpdu_command_def_t)
@ -65,7 +64,7 @@ typedef struct tsms_tpdu_command_s
uint8_t mn;
/** TP Destination Address (M - 2-12o)
* Parameter indicating the Destination Address to which the TP Command refers. */
tsms_address_t da;
tsms_address_t* da;
/** TP Command Data Length (M - o)
* Parameter indicating the length of the TP-CD field in octets. */
uint8_t cdl;

View File

@ -60,7 +60,7 @@ typedef struct tsms_tpdu_deliver_s
unsigned sri:1;
/** TP Originating Address (M - 2-12o)
* Address of the originating SME. */
tsms_address_t oa;
tsms_address_t* oa;
/** TP Protocol Identifier (M - o)
* Parameter identifying the above layer protocol, if any. */
uint8_t pid;

View File

@ -60,7 +60,7 @@ typedef struct tsms_tpdu_status_report_s
unsigned mr;
/** TP Recipient Address (M - 2-12o)
* Address of the recipient of the previously submitted mobile originated short message. */
tsms_address_t ra;
tsms_address_t* ra;
/** TP Service Centre Time Stamp (M - 7o)
* Parameter identifying time when the SC received the previously sent SMS SUBMIT. */
uint8_t scts[7];

View File

@ -21,7 +21,7 @@
*/
/**@file tsms_tpdu_submit.h
* @brief SMS TPDU SMS-SUBMIT message as per 3GPP TS 23.040 section 9.2.2.2.
* @brief SMS TPDU SMS-SUBMIT (MO) message as per 3GPP TS 23.040 section 9.2.2.2.
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*
@ -34,7 +34,6 @@
#include "tinySMS/tsms_common.h"
TSMS_BEGIN_DECLS
@ -68,7 +67,7 @@ typedef struct tsms_tpdu_submit_s
unsigned mr;
/** TP Destination Address (M - 2-12o)
* Address of the destination SME. */
tsms_address_t da;
tsms_address_t* da;
/** TP Protocol Identifier (M - o)
* Parameter identifying the above layer protocol, if any. */
uint8_t pid;
@ -83,10 +82,12 @@ typedef struct tsms_tpdu_submit_s
unsigned udl;
/** TP User Data (O - v)
* User data. */
uint8_t* ud;
tsk_buffer_t* ud;
}
tsms_tpdu_submit_t;
int tsms_submit_set_alpha(tsms_tpdu_submit_t* self, tsms_alphabet_t alpha);
int tsms_submit_set_usrdata(tsms_tpdu_submit_t* self, const char* ascii, tsms_alphabet_t alpha);
TINYSMS_GEXTERN const tsk_object_def_t *tsms_tpdu_submit_def_t;

View File

@ -0,0 +1,123 @@
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tsms_address.h
* @brief SMS address encoder/decoder.
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
*/
#ifndef TINYSMS_TSMS_ADDRESS_H
#define TINYSMS_TSMS_ADDRESS_H
#include "tinysms_config.h"
#include "tsk_buffer.h"
TSMS_BEGIN_DECLS
#define TSMS_ADDRESS_CREATE(addr_string, type) tsk_object_new(tsms_address_def_t, (/*tsms_address_string_t*/const char*)addr_string, (tsms_address_type_t)type)
#define TSMS_ADDRESS_OA_CREATE(addr_string) TSMS_ADDRESS_CREATE(addr_string, tsms_addr_oa)
#define TSMS_ADDRESS_DA_CREATE(addr_string) TSMS_ADDRESS_CREATE(addr_string, tsms_addr_da)
#define TSMS_ADDRESS_SMSC_CREATE(addr_string) TSMS_ADDRESS_CREATE(addr_string, tsms_addr_smsc)
typedef uint8_t tsms_address_string_t[13]; /* 12 + (+) */
/** Address type
*/
typedef enum tsms_address_type_e
{
tsms_addr_oa,
tsms_addr_da,
tsms_addr_smsc,
}
tsms_address_type_t;
/** Type-of-number
* 3GPP TS 23.040 v910 section 9.1.2.5.
*/
typedef enum tsms_address_ton_e
{
/** "Unknown" is used when the user or network has no a priori information about the numbering plan. In
this case, the Address-Value field is organized according to the network dialling plan, e.g. prefix or
escape digits might be present.*/
tsms_addr_ton_unknown = 0x00, // 0b000
/** International number
The international format shall be accepted also when the message is destined to a recipient in the
same country as the MSC. */
tsms_addr_ton_international = 0x01, // 0b001
/** National number
Prefix or escape digits shall not be included */
tsms_addr_ton_national = 0x02, // 0b010
/** "Network specific number" is used to indicate administration/service number specific to the serving
network, e.g. used to access an operator. */
tsms_addr_ton_network_specific = 0x03, // 0b011
/** "Subscriber number" is used when a specific short number representation is stored in one or more
SCs as part of a higher layer application. (Note that "Subscriber number" shall only be used in
connection with the proper PID referring to this application). */
tsms_addr_ton_subscriber = 0x04, // 0b100
/** Alphanumeric, (coded according to GSM TS 03.38 7-bit default alphabet) */
tsms_addr_ton_alphanumeric = 0x05, // 0b101
/** Abbreviated number */
tsms_addr_ton_abbreviated = 0x06, // 0b110
/** Reserved for extension */
tsms_addr_ton_reserved = 0x07, // 0b111
}
tsms_address_ton_t;
/** Numbering-Plan-Identification
* 3GPP TS 23.040 v910 section 9.1.2.5.
*/
typedef enum tsms_address_npi_e
{
/* 0000 */ tsms_addr_npi_unknown = 0x00, /**< Unknown */
/* 0001 */ tsms_addr_npi_isdn = 0x01, /**< ISDN/telephone numbering plan (E.164/E.163) */
/* 0011 */ tsms_addr_npi_x121 = 0x03, /**< Data numbering plan (X.121) */
/* 0100 */ tsms_addr_npi_telex = 0x04, /**< Telex numbering plan */
/* 1000 */ tsms_addr_npi_national = 0x08, /**< National numbering plan */
/* 1001 */ tsms_addr_npi_private = 0x09, /**< Private numbering plan */
/* 1010 */ tsms_addr_npi_ermes = 0x0A, /**< ERMES numbering plan (ETSI DE/PS 3 01-3) */
/* 1111 */ tsms_addr_npi_reserved = 0x0F, /**< Reserved for extension */
}
tsms_address_npi_t;
/** Address
*/
typedef struct tsms_address_s
{
TSK_DECLARE_OBJECT;
// Address Type
tsms_address_ton_t ton; /**< Type-of-number */
tsms_address_npi_t npi; /**< Numbering-Plan-Identification */
tsms_address_type_t type;
char* digits; /* BCD digits */
}
tsms_address_t;
int tsms_address_serialize(const tsms_address_t* address, tsk_buffer_t* output);
TINYSMS_GEXTERN const tsk_object_def_t *tsms_address_def_t;
#endif /* TSMS_BEGIN_DECLS */

View File

@ -32,12 +32,13 @@
#include "tinysms_config.h"
#include "tinySMS/tsms_address.h"
#include "tsk_buffer.h"
TSMS_BEGIN_DECLS
typedef uint8_t tsms_address_t[12];
typedef int (*tsms_tpdu_message_serialize_f)(const struct tsms_tpdu_message_s* self, const tsk_buffer_t* output);
typedef int (*tsms_tpdu_message_serialize_f)(const tsms_address_t* smsc, const struct tsms_tpdu_message_s* self, tsk_buffer_t* output);
/** SMS alphabet values as per 3GPP TS 23.038 v911 section 4.
* Part of TP-DCS (SMS Data Coding Scheme).
@ -51,6 +52,9 @@ typedef enum tsms_alphabet_e
}
tsms_alphabet_t;
/* 3GPP TS 23.038 v911 section 4 */
#define TSMS_ALPHA_FROM_DCS(dcs) (((dcs) & 0x0C) >> 2) /* Bit3 and Bit2 */
/** 3GPP TS 23.040 - 9.2.3.1 TP Message Type Indicator (TP MTI)
*/
typedef enum tsms_tpdu_mti_e

View File

@ -40,7 +40,7 @@
/**@ingroup tsms_pdu_group
*/
tsms_tpdu_ctx_handle_t* tsms_pdu_ctx_create(uint8_t mr, tsms_address_t smsc, tsms_address_t phone)
tsms_tpdu_ctx_handle_t* tsms_pdu_ctx_create(uint8_t mr, tsms_address_string_t smsc, tsms_address_string_t phone)
{
tsms_tpdu_ctx_t* ret = tsk_null;
@ -98,7 +98,7 @@ tsk_buffer_t* tsms_pdu_ctx_getSUBMIT(tsms_tpdu_ctx_handle_t* handle)
if((submit = TSMS_TPDU_SUBMIT_CREATE())){
output = TSK_BUFFER_CREATE_NULL();
TSMS_TPDU_MESSAGE(submit)->serialize(TSMS_TPDU_MESSAGE(submit), output);
TSMS_TPDU_MESSAGE(submit)->serialize(ctx->smsc, TSMS_TPDU_MESSAGE(submit), output);
}
else{
goto bail;
@ -119,13 +119,20 @@ static tsk_object_t* _tsms_tpdu_ctx_create(tsk_object_t * self, va_list * app)
{
tsms_tpdu_ctx_t *ctx = self;
if(ctx){
const char* smsc, *phone;
uint8_t mr;
#if defined(__GNUC__)
ctx->mr = va_arg(*app, unsigned);
mr = (uint8_t)va_arg(*app, unsigned);
#else
ctx->mr = va_arg(*app, uint8_t);
mr = va_arg(*app, uint8_t);
#endif
ctx->smsc = tsk_strdup( va_arg(*app, const char*) );
ctx->phone = tsk_strdup( va_arg(*app, const char*) );
smsc = va_arg(*app, const char*);
phone = va_arg(*app, const char*);
ctx->mr = mr;
ctx->smsc = TSMS_ADDRESS_SMSC_CREATE(smsc);
ctx->phone = TSMS_ADDRESS_DA_CREATE(phone);
ctx->alphabet = tsms_alpha_7bit;
}
return self;
@ -135,9 +142,9 @@ static tsk_object_t* tsms_tpdu_ctx_destroy(tsk_object_t * self)
{
tsms_tpdu_ctx_t *ctx = self;
if(ctx){
TSK_FREE(ctx->smsc);
TSK_FREE(ctx->phone);
TSK_OBJECT_SAFE_FREE(ctx->smsc);
TSK_OBJECT_SAFE_FREE(ctx->phone);
TSK_OBJECT_SAFE_FREE(ctx->usrdata);
}

View File

@ -53,7 +53,7 @@ static tsk_object_t* tsms_tpdu_command_destroy(tsk_object_t * self)
{
tsms_tpdu_command_t *command = self;
if(command){
TSK_OBJECT_SAFE_FREE(command->da);
}
return self;

View File

@ -21,7 +21,7 @@
*/
/**@file tsms_tpdu_submit.c
* @brief SMS TPDU SMS-SUBMIT message as per 3GPP TS 23.040 section 9.2.2.2.
* @brief SMS TPDU SMS-SUBMIT (MO) message as per 3GPP TS 23.040 section 9.2.2.2.
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*
@ -29,17 +29,21 @@
*/
#include "tinySMS/tpdu/tsms_tpdu_submit.h"
#include "tinySMS/tsms_packing.h"
#include "tsk_string.h"
#include "tsk_memory.h"
#include "tsk_debug.h"
int tsms_tpdu_submit_serialize(const tsms_tpdu_submit_t* self, const tsk_buffer_t* output)
#include <string.h> /* strlen() */
int tsms_tpdu_submit_serialize(const tsms_address_t* smsc, const tsms_tpdu_submit_t* self, tsk_buffer_t* output)
{
uint8_t _1byte;
/* SMSC address */
#if TSMS_TPDU_APPEND_SMSC
//address addr_smsc(this->smsc, true);
//result.append(addr_smsc.getString());
tsms_address_serialize(smsc, output);
#endif
/* SMS-SUBMIT first Octect:
@ -49,21 +53,24 @@ int tsms_tpdu_submit_serialize(const tsms_tpdu_submit_t* self, const tsk_buffer_
- TP-Reply-Path(1b)
- TP-User-Data-Header-Indicator(1b)
- TP-Status-Report-Request(1b)
+----+----+----+--------+----+--------+
|RP |UDHI|SRR |VPF | RD | MTI |
+----+----+----+--------+----+--------+
*/
_1byte = (TSMS_TPDU_MESSAGE(self)->mti & 0xF3); /*2b*/
_1byte |= ((uint8_t)self->rd) << 2; /*1b*/
_1byte |= ((uint8_t)self->vpf) << 3; /*1b*/
_1byte |= ((uint8_t)self->rp) << 4; /*1b*/
_1byte |= ((uint8_t)self->udhi) << 5; /*1b*/
_1byte |= ((uint8_t)self->srr) << 6; /*1b*/
_1byte |= ((uint8_t)self->vpf) << 3; /*2b*/
_1byte |= ((uint8_t)self->srr) << 5; /*1b*/
_1byte |= ((uint8_t)self->udhi) << 6; /*1b*/
//_1byte |= ((uint8_t)self->) << 7; /*1b*/
tsk_buffer_append(output, &_1byte, 1);
/* 3GPP TS 23.040 ==> 9.2.3.6 TP-Message-Reference (TP-MR) */
tsk_buffer_append(output, &self->mr, 1); /*0-255 ==> 1o*/
/* 3GPP TS 23.040 ==> 9.2.3.8 TP-Destination-Address (TP-DA) */
//address addr_desta(this->remote, false);
//result.append(addr_desta.getString());
tsms_address_serialize(self->da, output);
/* GSM 03.40 ==> 9.2.3.9 TP-Protocol-Identifier (TP-PID) */
tsk_buffer_append(output, &self->pid, 1); /*1o*/
@ -72,57 +79,85 @@ int tsms_tpdu_submit_serialize(const tsms_tpdu_submit_t* self, const tsk_buffer_
tsk_buffer_append(output, &self->dcs, 1); /*1o*/
/* 3GPP TS 23.040 ==> 9.2.3.12 TP-Validity-Period
* Only TP-VP (Relative format) is supported. 1o
*/
* Only TP-VP (Relative format) is supported.*/
tsk_buffer_append(output, &self->vp, 1); /*1o*/
/* 3GPP TS 23.040 ==> 9.2.3.16 TP-User-Data-Length (TP-UDL) */
tsk_buffer_append(output, &self->udl, 1); /*1o*/
/* 3GPP TS 23.040 ==> 9.2.3.24 TP-User Data (TP-UD) */
tsk_buffer_append(output, TSK_BUFFER_DATA(self->ud), TSK_BUFFER_SIZE(self->ud));
return 0;
}
int tsms_submit_set_alpha(tsms_tpdu_submit_t* self, tsms_alphabet_t alpha)
{
/* SMS alphabet values as per 3GPP TS 23.038 v911 section 4.
* Part of TP-DCS (SMS Data Coding Scheme).
*/
if(self){
self->dcs = ((self->dcs & 0xF3) | (alpha << 2)); /* Bit3 and Bit2 */
return 0;
}
return -1;
}
int tsms_submit_set_usrdata(tsms_tpdu_submit_t* self, const char* ascii, tsms_alphabet_t alpha)
{
if(tsk_strnullORempty(ascii)){
TSK_DEBUG_WARN("User data is Null or Empty");
return -1;
}
// update DCS
tsms_submit_set_alpha(self, alpha);
// remove old ud
TSK_OBJECT_SAFE_FREE(self->ud);
/* 3GPP TS 23.040 ==> 9.2.3.16 TP-User-Data-Length (TP-UDL)
* (alpha = SMS_ALPHA_7bit) ==> number of septets.
* ((alpha == SMS_ALPHA_8bit) || (alpha == SMS_ALPHA_UCS2)) ==> number of octes.
*/
// result.append(b10_to_b16(this->userdata.length()/2)); ==> see the switch below
// this->userdata ==> The ascii string to send/encode
/* 3GPP TS 23.040 ==> 9.2.3.24 TP-User Data (TP-UD) */
switch(this->alpha)
{
case SMS_ALPHA_7bit:
{
string pdu;
ascii_to_pdu(this->userdata, pdu);
result.append(b10_to_b16(this->userdata.length())); /* TP-UDL */
result.append(pdu); /* TP-UD */
}
break;
case SMS_ALPHA_8bit:
{
string bit8;
ascii_to_bit8(this->userdata, bit8);
result.append(b10_to_b16(bit8.length()/2)); /* TP-UDL */
result.append(bit8); /* TP-UD */
}
break;
case SMS_ALPHA_UCS2:
{
string ucs2;
ascii_to_ucs2(this->userdata, ucs2);
result.append(b10_to_b16(ucs2.length()/2)); /* TP-UDL */
result.append(ucs2); /* TP-UD */
}
break;
switch(alpha){
case tsms_alpha_7bit:
{
self->udl = strlen(ascii);
self->ud = tsms_pack_to_7bit(ascii);
}
break;
case tsms_alpha_8bit:
{
if((self->ud = tsms_pack_to_8bit(ascii))){
self->udl = self->ud->size;
}
else{
self->udl = 0;
}
}
break;
case tsms_alpha_ucs2:
{
if((self->ud = tsms_pack_to_ucs2(ascii))){
self->udl = self->ud->size;
}
else{
self->udl = 0;
}
}
break;
default:
throw "Unsupported alphabet";
{
TSK_DEBUG_ERROR("Invalid Alphabet.");
return -2;
}
}
return result;
return 0;
}
//=================================================================================================
// SMS TPDU SMS-COMMAND object definition
//
@ -141,7 +176,9 @@ static tsk_object_t* tsms_tpdu_submit_destroy(tsk_object_t * self)
{
tsms_tpdu_submit_t *submit = self;
if(submit){
TSK_FREE(submit->ud);
TSK_OBJECT_SAFE_FREE(submit->ud);
TSK_OBJECT_SAFE_FREE(submit->da);
}
return self;
}

View File

@ -0,0 +1,152 @@
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tsms_address.c
* @brief SMS address encoder/decoder.
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
*/
#include "tinySMS/tsms_address.h"
#include "tsk_string.h"
#include "tsk_memory.h"
#include <string.h>
/** swaps the address from 'abcd' to 'badc'
*/
char* tsms_address_swap(const char* in)
{
size_t i, in_len;
char* ret = tsk_null;
if(tsk_strnullORempty(in)){
goto bail;
}
in_len = strlen(in);
ret = tsk_calloc(in_len + 2/*\0 and trainling F*/, sizeof(uint8_t));
if(in_len>=2){
for(i=0; i<in_len; i+=2){
ret[i] = in[i+1];
ret[i+1] = in[i];
}
}
if(in_len & 0x01){ /* odd number? */
ret[i-2] = 'F';
ret[i-1] = in[i-2];
}
bail:
return ret;
}
/** Serialize the address as per 3GPP TS 23.040 v910 section 9.1.2.5. */
int tsms_address_serialize(const tsms_address_t* address, tsk_buffer_t* output)
{
char* number = tsk_null;
size_t len = 0;
uint8_t type_of_address;
if(!address ||!output){
return -1;
}
/* For more information see 3GPP TS 23.040 v910 section 9.1.2.5
1 - Address-Length
2 - Type-of-Address
+----+----+----+----+----+----+----+----+
| 1 | TON | NPI |
+----+----+----+----+----+----+----+----+
3 - Phone number in semi octets
*/
number = tsms_address_swap(address->digits);
if(number){
len = (address->type == tsms_addr_smsc) ?
((strlen(number)/2) + 1) /* Number of octets plus 1. */
: strlen(number); /* Number of BCD digits */
}
/* 1 - Address-Length */
tsk_buffer_append(output, &len, 1);
/* 2 - Type-of-Address */
type_of_address = (address->npi | (((address->ton << 4) | 0x80)));
tsk_buffer_append(output, &type_of_address, 1);
/* 3 - Phone number in semi octets */
tsk_buffer_append(output, number, len);
TSK_FREE(number);
return 0;
}
//=================================================================================================
// SMS Address object definition
//
static tsk_object_t* tsms_address_create(tsk_object_t * self, va_list * app)
{
tsms_address_t *address = self;
if(address){
const char* digits = va_arg(*app, const char*);
address->type = va_arg(*app, tsms_address_type_t);
if(!tsk_strnullORempty(digits)){
if(*digits == '+'){
address->npi = tsms_addr_npi_isdn;
address->ton = tsms_addr_ton_international;
address->digits = tsk_strdup((digits+1));
}
else{
address->npi = tsms_addr_npi_national;
address->ton = tsms_addr_ton_national;
address->digits = tsk_strdup((digits));
}
}
else{
address->npi = tsms_addr_npi_unknown;
address->ton = tsms_addr_ton_unknown;
}
}
return self;
}
static tsk_object_t* tsms_address_destroy(tsk_object_t * self)
{
tsms_address_t *address = self;
if(address){
TSK_FREE(address->digits);
}
return self;
}
static const tsk_object_def_t tsms_address_def_s =
{
sizeof(tsms_address_t),
tsms_address_create,
tsms_address_destroy,
tsk_null,
};
const tsk_object_def_t *tsms_address_def_t = &tsms_address_def_s;

View File

@ -0,0 +1,227 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="test"
ProjectGUID="{BD24A663-4018-41EC-A250-4A57CDD2F13B}"
RootNamespace="test"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\thirdparties\win32\include;..\..\tinySAK\src;..\..\tinySMS\include"
PreprocessorDefinitions="DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(OutDir)\tinySAK.lib $(OutDir)\tinySMS.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\tinySMS\test\stdafx.c"
>
</File>
<File
RelativePath="..\..\tinySMS\test\test.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\tinySMS\test\stdafx.h"
>
</File>
<File
RelativePath="..\..\tinySMS\test\targetver.h"
>
</File>
</Filter>
<Filter
Name="Tests"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath="..\..\tinySMS\test\test_packing.h"
>
</File>
<File
RelativePath="..\..\tinySMS\test\test_rpdu.h"
>
</File>
<File
RelativePath="..\..\tinySMS\test\test_tpdu.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -29,7 +29,8 @@ void test_tpdu()
tsms_tpdu_ctx_handle_t* handle;
tsk_buffer_t* buffer = tsk_null;
char* temp;
handle = tsms_pdu_ctx_create(__pdu_last_mr++, "+331000000", "+3361234567");
if((buffer = tsms_pdu_ctx_getSUBMIT(handle))){

View File

@ -5,6 +5,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinySMS", "tinySMS.vcproj",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinySAK", "..\tinySAK\tinySAK.vcproj", "{6BC9B796-10C6-4CF7-A6E4-E2DACCDA84DA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcproj", "{BD24A663-4018-41EC-A250-4A57CDD2F13B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -29,6 +31,12 @@ Global
{6BC9B796-10C6-4CF7-A6E4-E2DACCDA84DA}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)
{6BC9B796-10C6-4CF7-A6E4-E2DACCDA84DA}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Build.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)
{6BC9B796-10C6-4CF7-A6E4-E2DACCDA84DA}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).Deploy.0 = Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Debug|Win32.ActiveCfg = Debug|Win32
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Debug|Win32.Build.0 = Debug|Win32
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Debug|Win32
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Release|Win32.ActiveCfg = Release|Win32
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Release|Win32.Build.0 = Release|Win32
{BD24A663-4018-41EC-A250-4A57CDD2F13B}.Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I).ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -63,6 +63,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="$(OutDir)\tinySAK.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
@ -183,6 +184,10 @@
RelativePath=".\include\tinysms\tsms.h"
>
</File>
<File
RelativePath=".\include\tinysms\tsms_address.h"
>
</File>
<File
RelativePath=".\include\tinysms\tsms_common.h"
>
@ -191,6 +196,10 @@
RelativePath=".\include\tinysms\tsms_etsi_gsm_03_38.h"
>
</File>
<File
RelativePath=".\include\tinysms\tsms_packing.h"
>
</File>
<Filter
Name="tpdu"
>
@ -237,6 +246,14 @@
RelativePath=".\src\tsms.c"
>
</File>
<File
RelativePath=".\src\tsms_address.c"
>
</File>
<File
RelativePath=".\src\tsms_packing.c"
>
</File>
<Filter
Name="tpdu"
>