Logo Search packages:      
Sourcecode: gammu version File versions  Download package

gsmsms.h

/* (c) 2001-2006 by Marcin Wiacek */
/* Based on some Pawel Kot and others work from Gnokii (www.gnokii.org)
 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
 * GNU GPL version 2 or later
 */
/* Due to a problem in the source code management, the names of some of
 * the authors have unfortunately been lost. We do not mean to belittle
 * their efforts and hope they will contact us to see their names
 * properly added to the Copyright notice above.
 * Having published their contributions under the terms of the GNU
 * General Public License (GPL) [version 2], the Copyright of these
 * authors will remain respected by adhering to the license they chose
 * to publish their code under.
 */

#ifndef __gsm_sms_h
#define __gsm_sms_h

#include "../../gsmcomon.h"
#include "../gsmlogo.h"
#include "../gsmcal.h"
#include "../gsmpbk.h"
#include "../gsmdata.h"
#include "../gsmring.h"

/* --------------------- Some general definitions ------------------------- */

#define GSM_MAX_UDH_LENGTH          140
#define GSM_MAX_SMS_LENGTH          160
#define GSM_MAX_8BIT_SMS_LENGTH           140

/* -------------------- Cell Broadcast ------------------------------------ */

/**
 * Structure for Cell Broadcast messages.
 */
00037 typedef struct {
      /**
       * Message text.
       */
00041       char    Text[300];
      /**
       * Channel number.
       */
00045       int     Channel;
} GSM_CBMessage;

/* ------------------------ SMS status ------------------------------------ */

/**
 * Status of SMS memory.
 */
00053 typedef struct {
      /**
       * Number of unread messages on SIM.
       */
00057       int     SIMUnRead;
      /**
       * Number of all saved messages (including unread) on SIM.
       */
00061       int     SIMUsed;
      /**
       * Number of all possible messages on SIM.
       */
00065       int     SIMSize;
      /**
       * Number of used templates (62xx/63xx/7110/etc.).
       */
00069       int     TemplatesUsed;
      /**
       * Number of unread messages in phone.
       */
00073       int     PhoneUnRead;
      /**
       * Number of all saved messages in phone.
       */
00077       int     PhoneUsed;
      /**
       * Number of all possible messages on phone.
       */
00081       int     PhoneSize;
} GSM_SMSMemoryStatus;

/* --------------------- SMS Center --------------------------------------- */

/**
 * Enum defines format of SMS messages. See GSM 03.40 section 9.2.3.9
 */
typedef enum {
      SMS_FORMAT_Pager = 1,
      SMS_FORMAT_Fax,
      SMS_FORMAT_Email,
      SMS_FORMAT_Text
      /* Some values not handled here */
} GSM_SMSFormat;

/**
 * Enum defines some the most often used validity lengths for SMS messages
 * for relative validity format. See GSM 03.40 section 9.2.3.12.1 - it gives
 * more values
 */
typedef enum {
      SMS_VALID_1_Hour   = 0x0b,
      SMS_VALID_6_Hours  = 0x47,
      SMS_VALID_1_Day    = 0xa7,
      SMS_VALID_3_Days   = 0xa9,
      SMS_VALID_1_Week   = 0xad,
      SMS_VALID_Max_Time = 0xff
} GSM_ValidityPeriod;

/**
 * Enum defines format of validity period for SMS messages.
 * See GSM 03.40 section 9.2.3.12
 */
typedef enum {
      SMS_Validity_NotAvailable = 1,
      SMS_Validity_RelativeFormat
      /* Specification gives also other possibilities */
} GSM_ValidityPeriodFormat;

/**
 * Structure for validity of SMS messages
 */
00124 typedef struct {
      GSM_ValidityPeriodFormat      Format;
      /**
       * Value defines period for relative format
       */
00129       GSM_ValidityPeriod                  Relative;
} GSM_SMSValidity;

#define GSM_MAX_SMSC_NAME_LENGTH    50

/**
 * Structure for SMSC (SMS Center) information.
 */
00137 typedef struct {
      /**
       * Number of the SMSC on SIM
       */
00141       int         Location;
      /**
       * Name of the SMSC
       */
00145       unsigned char   Name[(GSM_MAX_SMSC_NAME_LENGTH+1)*2];
      /**
       * SMSC phone number.
       */
00149       unsigned char   Number[(GSM_MAX_NUMBER_LENGTH+1)*2];
      /**
       * Validity of SMS messages.
       */
00153       GSM_SMSValidity Validity;
      /**
       * Format of sent SMS messages.
       */
00157       GSM_SMSFormat   Format;
      /**
       * Default recipient number. In old DCT3 ignored
       */
00161       unsigned char   DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1)*2];
} GSM_SMSC;

/* --------------------- single SMS --------------------------------------- */

/**
 * Status of SMS message.
 */
typedef enum {
      SMS_Sent = 1,
      SMS_UnSent,
      SMS_Read,
      SMS_UnRead
} GSM_SMS_State;

/**
 * Coding type of SMS.
 */
typedef enum {
      /**
       * Unicode
       */
      SMS_Coding_Unicode_No_Compression = 1,
      SMS_Coding_Unicode_Compression,
      /**
       * Default GSM alphabet.
       */
      SMS_Coding_Default_No_Compression,
      SMS_Coding_Default_Compression,
      /**
       * 8-bit.
       */
      SMS_Coding_8bit
} GSM_Coding_Type;

/**
 * Types of UDH (User Data Header).
 */
typedef enum {
      UDH_NoUDH = 1,
      /**
       * Linked SMS.
       */
      UDH_ConcatenatedMessages,
      /**
       * Linked SMS with 16 bit reference.
       */
      UDH_ConcatenatedMessages16bit,
      UDH_DisableVoice,
      UDH_DisableFax,
      UDH_DisableEmail,
      UDH_EnableVoice,
      UDH_EnableFax,
      UDH_EnableEmail,
      UDH_VoidSMS,
      UDH_NokiaRingtone,
      UDH_NokiaRingtoneLong,
      UDH_NokiaOperatorLogo,
      UDH_NokiaOperatorLogoLong,
      UDH_NokiaCallerLogo,
      UDH_NokiaWAP,
      UDH_NokiaWAPLong,
      UDH_NokiaCalendarLong,
      UDH_NokiaProfileLong,
      UDH_NokiaPhonebookLong,
      UDH_UserUDH,
      UDH_MMSIndicatorLong
} GSM_UDH;

/**
 * Structure for User Data Header.
 */
00233 typedef struct {
      /**
       * UDH type.
       */
00237       GSM_UDH           Type;
      /**
       * UDH length.
       */
00241       int         Length;
      /**
       * UDH text.
       */
00245       unsigned char   Text[GSM_MAX_UDH_LENGTH];
      /**
       * 8-bit ID, when required (-1 otherwise).
       */
00249       int         ID8bit;
      /**
       * 16-bit ID, when required (-1 otherwise).
       */
00253       int         ID16bit;
      /**
       * Number of current part.
       */
00257       int         PartNumber;
      /**
       * Total number of parts.
       */
00261       int         AllParts;
} GSM_UDHHeader;

/**
 * TP-Message-Type-Indicator. See GSM 03.40 section 9.2.3.1.
 */
typedef enum {
      /**
       * SMS in Inbox.
       */
      SMS_Deliver = 1,
      /**
       * Delivery Report
       */
      SMS_Status_Report,
      /**
       * SMS for sending or in Outbox
       */
      SMS_Submit
      /* specification gives more */
} GSM_SMSMessageType;

/**
 * Maximal length of SMS name.
 */
#define GSM_MAX_SMS_NAME_LENGTH      200

/**
 * SMS message data.
 */
00291 typedef struct {
      /**
       * Message to be replaced.
       */
00295       unsigned char           ReplaceMessage;
      /**
       * Whether to reject duplicates.
       */
00299       bool              RejectDuplicates;
      /**
       * UDH (User Data Header)
       */
00303       GSM_UDHHeader           UDH;
      /**
       * Sender or recipient number.
       */
00307       unsigned char           Number[(GSM_MAX_NUMBER_LENGTH+1)*2];
      /**
       * SMSC (SMS Center)
       */
00311       GSM_SMSC          SMSC;
      /**
       * For saved SMS: where exactly it's saved (SIM/phone)
       */
00315       GSM_MemoryType          Memory;
      /**
       * For saved SMS: location of SMS in memory.
       */
00319       int               Location;
      /**
       * For saved SMS: number of folder, where SMS is saved
       */
00323       int               Folder;
      /**
       * For saved SMS: whether SMS is really in Inbox.
       */
00327       bool              InboxFolder;
      /**
       * Length of the SMS message.
       */
00331       int               Length;
      /**
       * Status (read/unread/...) of SMS message.
       */
00335       GSM_SMS_State           State;
      /**
       * Name in Nokia with SMS memory (6210/7110, etc.) Ignored in other.
       */
00339       unsigned char           Name[(GSM_MAX_SMS_NAME_LENGTH+1)*2];
      /**
       * Text for SMS.
       */
00343       unsigned char           Text[(GSM_MAX_SMS_LENGTH+1)*2];
      /**
       * Type of message.
       */
00347       GSM_SMSMessageType      PDU;
      /**
       * Type of coding.
       */
00351       GSM_Coding_Type         Coding;
      /**
       * Date and time, when SMS was saved or sent
       */
00355       GSM_DateTime            DateTime;
      /**
       * Date of SMSC response in DeliveryReport messages.
       */
00359       GSM_DateTime            SMSCTime;
      /**
       * In delivery reports: status.
       */
00363       unsigned char           DeliveryStatus;
      /**
       * Indicates whether "Reply via same center" is set.
       */
00367       bool              ReplyViaSameSMSC;
      /**
       * SMS class.
       */
00371       signed char       Class;
      /**
       * Message reference.
       */
00375       unsigned char           MessageReference;
} GSM_SMSMessage;

/* In layouts are saved locations for some SMS part. Below are listed
 * specs, which describe them
 */
typedef struct {
      /**
       * TP-User-Data. GSM 03.40 section 9.2.3.24.
       */
      unsigned char Text;
      /**
       * - In SMS-Deliver:       TP-Originating-Address. GSM 03.40 section 9.2.3.7.
       * - In SMS-Submit:        TP-Destination-Address. GSM 03.40 section 9.2.3.8.
       * - In SMS-Status-Report: TP-Recipient-Address.   GSM 03.40 section 9.2.3.14.
       */
      unsigned char Number;
      /**
       * SMSC number
       */
      unsigned char SMSCNumber;
      /**
       * TP-Data-Coding-Scheme. GSM 03.40 section 9.2.3.10.
       * Contains alphabet type, SMS class (and some others)
       */
      unsigned char TPDCS;
      /**
       * - For SMS-Submit:        TP-Validity-Period. GSM 03.40 section 9.2.3.12.
       * - For SMS-Status-Report: TP-Discharge Time.  GSM 03.40 section 9.2.3.13.
       */
      unsigned char DateTime;
      /**
       * TP-Service-Centre-Time-Stamp in SMS-Status-Report. GSM 03.40 section 9.2.3.11.
       */
      unsigned char SMSCTime;
      /**
       * TP-Status in SMS-Status-Report. GSM 03.40 section 9.2.3.15.
       */
      unsigned char TPStatus;
      /**
       * TP-User-Data-Length. GSM 03.40 section 9.2.3.16.
       */
      unsigned char TPUDL;
      /**
       * TP-Validity Period in SMS-Submit. GSM 03.40 section 9.2.3.12.
       */
      unsigned char TPVP;
      /**
       * Byte contains in SMS-Deliver:
       * - TP-Message-Type-Indicator     (2 bits) GSM 03.40 section 9.2.3.1
       * - TP-More-Messages-To-Send      (1 bit). GSM 03.40 section 9.2.3.2
       * - TP-Reply-Path                 (1 bit). GSM 03.40 section 9.2.3.17
       * - TP-User-Data-Header-Indicator (1 bit). GSM 03.40 section 9.2.3.23
       * - TP-Status-Report-Indicator    (1 bit). GSM 03.40 section 9.2.3.4
       *
       * Byte contains in SMS-Submit:
       * - TP-Message-Type-Indicator     (2 bits) GSM 03.40 section 9.2.3.1
       * - TP-Reject-Duplicates          (1 bit). GSM 03.40 section
       * - TP-Validity-Period-Format     (2 bits).GSM 03.40 section 9.2.3.3
       * - TP-Reply-Path                 (1 bit). GSM 03.40 section 9.2.3.17
       * - TP-User-Data-Header-Indicator (1 bit). GSM 03.40 section 9.2.3.23
       * - TP-Status-Report-Request      (1 bit). GSM 03.40 section 9.2.3.5
       */
      unsigned char firstbyte;
      /**
       * TP-Message Reference in SMS-Submit. GSM 03.40 section 9.2.3.6
       */
      unsigned char TPMR;
      /**
       * TP-Protocol-Identifier. GSM 03.40 section 9.2.3.9
       */
      unsigned char TPPID;
} GSM_SMSMessageLayout;

GSM_Error GSM_DecodeSMSFrame(GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout);
GSM_Error GSM_EncodeSMSFrame(GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, bool clear);

GSM_Error GSM_DecodeSMSFrameStatusReportData    (GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout);
GSM_Error GSM_DecodeSMSFrameText          (GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout);

void GSM_DecodeUDHHeader(GSM_UDHHeader *UDH);
void GSM_EncodeUDHHeader(GSM_UDHHeader *UDH);

void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS);

/* ---------------------- SMS folders ------------------------------------- */

/**
 * Number of possible SMS folders.
 */
#define GSM_MAX_SMS_FOLDERS         24
/**
 * Maximal length of SMS folder name.
 */
#define GSM_MAX_SMS_FOLDER_NAME_LEN     20

/**
 * Information about SMS folder.
 */
00474 typedef struct {
      /**
       * Whether it is really inbox.
       */
00478       bool              InboxFolder;
      /**
       * Where exactly it's saved
       */
00482       GSM_MemoryType          Memory;
        /**
       * Name for SMS folder.
       */
00486         unsigned char         Name[(GSM_MAX_SMS_FOLDER_NAME_LEN+1)*2];
} GSM_OneSMSFolder;

/**
 * List of SMS folders.
 */
00492 typedef struct {
        /**
       * Array of structures holding information about each folder.
       */
00496         GSM_OneSMSFolder      Folder[GSM_MAX_SMS_FOLDERS];
        /**
       * Number of SMS folders.
       */
00500         unsigned char         Number;
} GSM_SMSFolders;

typedef struct {
      unsigned long     SequenceID;
      unsigned int      PacketsNum;
      unsigned int      PacketNum;
      unsigned long     AllDataLen;

      unsigned char     DataType[10];
      unsigned char     DataName[40];
      unsigned int      DataLen;
      unsigned char     Data[140];
} GSM_SiemensOTASMSInfo;

bool GSM_DecodeSiemensOTASMS(GSM_SiemensOTASMSInfo    *Info,
                       GSM_SMSMessage           *SMS);

#endif

/* How should editor hadle tabs in this file? Add editor commands here.
 * vim: noexpandtab sw=8 ts=8 sts=8:
 */

Generated by  Doxygen 1.6.0   Back to index