1 /* 2 3 $Id$ 4 5 G N O K I I 6 7 A Linux/Unix toolset and driver for the mobile phones. 8 9 This file is part of gnokii. 10 11 Gnokii is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 2 of the License, or 14 (at your option) any later version. 15 16 Gnokii is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with gnokii; if not, write to the Free Software 23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 25 Copyright (C) 1999-2000 Hugh Blemings, Pavel Janik 26 Copyright (C) 2001-2003 Pawel Kot 27 Copyright (C) 2002 Pavel Machek, Markus Plail, BORBELY Zoltan 28 Copyright (C) 2003 Ladis Michl 29 30 Include file for the SMS library. 31 32 */ 33 34 #ifndef _gnokii_sms_h 35 #define _gnokii_sms_h 36 37 #include <gnokii/error.h> 38 #include <gnokii/common.h> 39 #include <gnokii/bitmaps.h> 40 #include <gnokii/ringtones.h> 41 #include <gnokii/encoding.h> 42 43 /* Maximum length of SMS center name */ 44 #define GN_SMS_CENTER_NAME_MAX_LENGTH 20 45 46 /* Limits of SMS messages. */ 47 #define GN_SMS_MAX_LENGTH 160 48 #define GN_SMS_8BIT_MAX_LENGTH 140 49 #define GN_SMS_LONG_MAX_LENGTH 10240 50 51 #define GN_SMS_PART_MAX_NUMBER 3 52 53 /* FIXME: what value should be here? (Pawel Kot) */ 54 #define GN_SMS_UDH_MAX_NUMBER 10 55 56 /* Maximal number of SMS folders */ 57 #define GN_SMS_FOLDER_MAX_NUMBER 64 58 #define GN_SMS_MESSAGE_MAX_NUMBER 1024 59 60 #define GN_SMS_DATETIME_MAX_LENGTH 7 61 #define GN_SMS_SMSC_NUMBER_MAX_LENGTH 20 62 #define GN_SMS_NUMBER_MAX_LENGTH 20 63 #define GN_SMS_USER_DATA_MAX_LENGTH 256 64 #define GN_SMS_VP_MAX_LENGTH 8 65 66 /* flags for encoding/decoding PDU */ 67 #define GN_SMS_PDU_DEFAULT 0 68 #define GN_SMS_PDU_NOSMSC 1 69 70 /*** MEMORY INFO ***/ 71 typedef struct { 72 int Unread; /* Number of unread messages */ 73 int Number; /* Number of all messages */ 74 } gn_sms_memory_status; 75 76 typedef struct { 77 /* Number of message we get from GetSMSStatus */ 78 unsigned int number; 79 /* Number of unread messages we get from GetSMSStatus */ 80 unsigned int unread; 81 /* when a message is moved between folders status wouldn't change */ 82 unsigned int changed; 83 /* Number of Folders we get from GetFolders */ 84 unsigned int folders_count; 85 /* Message store used for new received messages (this is used 86 * internally by AT_SetSMSMemoryType() in common/phones/atgen.c). */ 87 /* Note: this field is unused since revision 1.128 of common/phones/atgen.c */ 88 gn_memory_type new_message_store; 89 } gn_sms_status; 90 91 92 /*** USER DATA HEADER ***/ 93 /* types of User Data Header */ 94 typedef enum { 95 GN_SMS_UDH_None = 0x00, 96 GN_SMS_UDH_ConcatenatedMessages = 0x01, 97 GN_SMS_UDH_Ringtone = 0x02, 98 GN_SMS_UDH_OpLogo = 0x03, 99 GN_SMS_UDH_CallerIDLogo = 0x04, 100 GN_SMS_UDH_MultipartMessage = 0x05, 101 GN_SMS_UDH_WAPvCard = 0x06, 102 GN_SMS_UDH_WAPvCalendar = 0x07, 103 GN_SMS_UDH_WAPvCardSecure = 0x08, 104 GN_SMS_UDH_WAPvCalendarSecure = 0x09, 105 GN_SMS_UDH_VoiceMessage = 0x0a, 106 GN_SMS_UDH_FaxMessage = 0x0b, 107 GN_SMS_UDH_EmailMessage = 0x0c, 108 GN_SMS_UDH_WAPPush = 0x0d, 109 GN_SMS_UDH_OtherMessage = 0x0e, 110 GN_SMS_UDH_Unknown = 0x0f 111 } gn_sms_udh_type; 112 113 GNOKII_API const char *gn_sms_udh_type2str(gn_sms_udh_type t); 114 115 typedef struct { 116 gn_sms_udh_type type; 117 union { 118 struct { 119 unsigned short reference_number; 120 unsigned short maximum_number; 121 unsigned short current_number; 122 } concatenated_short_message; /* SMS_ConcatenatedMessages */ 123 struct { 124 int store; 125 unsigned short message_count; 126 } special_sms_message_indication; /* GN_SMS_VoiceMessage, GN_SMS_FaxMessage, 127 GN_SMS_EmailMessage, GN_SMS_OtherMessage */ 128 struct { 129 char network_code[6]; 130 unsigned int width, height; 131 } logo; /* GN_SMS_OpLogo, GN_SMS_CallerIDLogo */ 132 struct { 133 unsigned int notes; /* Number of the notes */ 134 } ringtone; /* GN_SMS_Ringtone */ 135 } u; 136 } gn_sms_udh_info; 137 138 typedef struct { 139 unsigned int number; /* Number of the present UDH */ 140 unsigned int length; 141 gn_sms_udh_info udh[GN_SMS_UDH_MAX_NUMBER]; 142 } gn_sms_udh; 143 144 typedef enum { 145 GN_SMS_MW_PID, /* Set Protocol Identifier to `Return Call Message' */ 146 GN_SMS_MW_DCS, /* Set Data Coding Scheme "to indicate the type of 147 * message waiting and whether there are some messages 148 * or no messages" */ 149 GN_SMS_MW_UDH /* Use User Data Header - Special SMS Message 150 * Indication; the maximium level of information, 151 * may not be supported by all phones */ 152 } gn_sms_message_waiting_type; 153 154 /*** DATA CODING SCHEME ***/ 155 typedef enum { 156 GN_SMS_DCS_GeneralDataCoding, 157 GN_SMS_DCS_MessageWaiting 158 } gn_sms_dcs_type; 159 160 typedef enum { 161 GN_SMS_DCS_DefaultAlphabet = 0x00, 162 GN_SMS_DCS_8bit = 0x01, 163 GN_SMS_DCS_UCS2 = 0x02 164 } gn_sms_dcs_alphabet_type; 165 166 typedef enum { 167 GN_SMS_DCS_VoiceMail = 0x00, 168 GN_SMS_DCS_Fax = 0x01, 169 GN_SMS_DCS_Email = 0x02, 170 GN_SMS_DCS_Text = 0x03, 171 GN_SMS_DCS_Other = 0x04 172 } gn_sms_dcs_indication_type; 173 174 typedef struct { 175 gn_sms_dcs_type type; 176 union { 177 struct { 178 /* Message class: 179 * 0 - no class 180 * 1 - Class 0 181 * 2 - Class 1 182 * 3 - Class 2 183 * 4 - Class 3 */ 184 unsigned short m_class; 185 int compressed; 186 gn_sms_dcs_alphabet_type alphabet; 187 } general; 188 struct { 189 int discard; 190 gn_sms_dcs_alphabet_type alphabet; /* ucs16 not supported */ 191 int active; 192 gn_sms_dcs_indication_type type; 193 } message_waiting; 194 } u; 195 } gn_sms_dcs; 196 197 /*** VALIDITY PERIOD ***/ 198 typedef enum { 199 GN_SMS_VP_None = 0x00, 200 GN_SMS_VP_EnhancedFormat = 0x01, 201 GN_SMS_VP_RelativeFormat = 0x02, 202 GN_SMS_VP_AbsoluteFormat = 0x03 203 } gn_sms_vp_format; 204 205 typedef enum { 206 GN_SMS_VPE_None = 0x00, 207 GN_SMS_VPE_RelativeFormat = 0x01, 208 GN_SMS_VPE_RelativeSeconds = 0x02, /* Only one octet more is used */ 209 GN_SMS_VPE_RelativeSemiOctet = 0x03 /* 3 octets contain relative time in hours, minutes and seconds in semi-octet representation */ 210 } gn_sms_vp_enhanced_type; 211 212 typedef struct { 213 int extension; /* we need to set it to 0 at the moment; FIXME: how to handle `1' here? */ 214 int single_shot; 215 gn_sms_vp_enhanced_type type; 216 union { 217 unsigned short relative; 218 unsigned short seconds; 219 gn_timestamp hms; 220 } period; 221 } gn_sms_vp_enhanced; 222 223 /* Validity of SMS Messages. */ 224 typedef enum { 225 GN_SMS_VP_1H = 0x0b, 226 GN_SMS_VP_6H = 0x47, 227 GN_SMS_VP_24H = 0xa7, 228 GN_SMS_VP_72H = 0xa9, 229 GN_SMS_VP_1W = 0xad, 230 GN_SMS_VP_Max = 0xff 231 } gn_sms_vp_time; 232 233 GNOKII_API const char *gn_sms_vp_time2str(gn_sms_vp_time t); 234 235 typedef struct { 236 gn_sms_vp_format vpf; 237 union { 238 gn_sms_vp_enhanced enhanced; 239 gn_sms_vp_time relative; /* 8 bit */ 240 gn_timestamp absolute; 241 } u; 242 } gn_sms_vp; 243 244 245 /*** MESSAGE CENTER ***/ 246 247 typedef enum { 248 GN_SMS_MF_Text = 0x00, /* Plain text message. */ 249 GN_SMS_MF_Fax = 0x22, /* Fax message. */ 250 GN_SMS_MF_Voice = 0x24, /* Voice mail message. */ 251 GN_SMS_MF_ERMES = 0x25, /* ERMES message. */ 252 GN_SMS_MF_Paging = 0x26, /* Paging. */ 253 GN_SMS_MF_UCI = 0x2d, /* Email message in 8110i. */ 254 GN_SMS_MF_Email = 0x32, /* Email message. */ 255 GN_SMS_MF_X400 = 0x31 /* X.400 message. */ 256 } gn_sms_message_format; 257 258 GNOKII_API const char *gn_sms_message_format2str(gn_sms_message_format t); 259 260 typedef struct { 261 int id; /* Number of the SMSC in the phone memory. */ 262 char name[GN_SMS_CENTER_NAME_MAX_LENGTH]; /* Name of the SMSC. */ 263 int default_name; /* >= 1 if default name used, otherwise -1 */ 264 gn_sms_message_format format; /* SMS is sent as text/fax/paging/email. */ 265 gn_sms_vp_time validity; /* Validity of SMS Message. */ 266 gn_gsm_number smsc; /* Number of the SMSC. */ 267 gn_gsm_number recipient; /* Number of the default recipient. */ 268 } gn_sms_message_center; 269 270 /*** SHORT MESSAGE CORE ***/ 271 272 typedef enum { 273 /* First 2 digits are taken from GSM 03.40 version 6.1.0 Release 1997 274 * Section 9.2.3.1; 3rd digit is to mark a report. */ 275 GN_SMS_MT_Deliver = 0x00, /* 00 0 */ 276 GN_SMS_MT_DeliveryReport = 0x01, /* 00 1 */ 277 GN_SMS_MT_Submit = 0x02, /* 01 0 */ 278 GN_SMS_MT_SubmitReport = 0x03, /* 01 1 */ 279 GN_SMS_MT_Command = 0x04, /* 10 0 */ 280 GN_SMS_MT_StatusReport = 0x05, /* 10 1 */ 281 /* Looks like Happy N*kia Engineers invention. Text, picture, outbox 282 * sent templates are needed for Nokia 6510 and family. */ 283 GN_SMS_MT_Picture = 0x07, 284 GN_SMS_MT_TextTemplate = 0x08, 285 GN_SMS_MT_PictureTemplate = 0x09, 286 GN_SMS_MT_SubmitSent = 0x0a 287 } gn_sms_message_type; 288 289 GNOKII_API const char *gn_sms_message_type2str(gn_sms_message_type t); 290 291 typedef enum { 292 GN_SMS_CT_Enquiry = 0x00, /* Enquiry relating to previosly 293 submitted short message; sets 294 SRR to 1 */ 295 GN_SMS_CT_CancelStatusReport = 0x01, /* Cancel Status Report Request 296 relating to previously submitted 297 short message; sets SRR to 0 */ 298 GN_SMS_CT_DeleteSM = 0x02, /* Delete previously submitted 299 Short Message; sets SRR to 0 */ 300 GN_SMS_CT_EnableStatusReport = 0x03 /* Enable Status Report Request 301 relating to previously submitted 302 short message; sets SRR to 0 */ 303 } gn_sms_command_type; 304 305 typedef struct { 306 gn_sms_command_type type; 307 } gn_sms_message_command; 308 309 /* Datatype for SMS Delivery Report Statuses */ 310 typedef enum { 311 GN_SMS_DR_Status_None = 0, 312 GN_SMS_DR_Status_Invalid, 313 GN_SMS_DR_Status_Delivered, 314 GN_SMS_DR_Status_Pending, 315 GN_SMS_DR_Status_Failed_Temporary, 316 GN_SMS_DR_Status_Failed_Permanent /* FIXME: add more reasons for failure? */ 317 } gn_sms_delivery_report_status; 318 319 /* Datatype for SMS status */ 320 typedef enum { 321 GN_SMS_Unknown= 0x00, 322 GN_SMS_Read = 0x01, 323 GN_SMS_Unread = 0x03, 324 GN_SMS_Sent = 0x05, 325 GN_SMS_Unsent = 0x07 326 } gn_sms_message_status; 327 328 GNOKII_API const char *gn_sms_message_status2str(gn_sms_message_status t); 329 330 typedef enum { 331 GN_SMS_DATA_None = 0x00, 332 GN_SMS_DATA_Text = 0x01, 333 GN_SMS_DATA_Bitmap = 0x02, 334 GN_SMS_DATA_Ringtone = 0x03, 335 GN_SMS_DATA_iMelody = 0x04, 336 GN_SMS_DATA_Multi = 0x05, 337 GN_SMS_DATA_NokiaText = 0x06, 338 GN_SMS_DATA_Animation = 0x07, 339 GN_SMS_DATA_Concat = 0x08, 340 GN_SMS_DATA_WAPPush = 0x09, 341 GN_SMS_DATA_Other = 0x0a 342 } gn_sms_data_type; 343 344 /*** FOLDER INFO ***/ 345 346 typedef enum { 347 GN_SMS_FLD_Old = 0x00, 348 GN_SMS_FLD_New = 0x01, 349 GN_SMS_FLD_Deleted = 0x02, 350 GN_SMS_FLD_ToBeRemoved = 0x03, 351 GN_SMS_FLD_NotRead = 0x04, 352 GN_SMS_FLD_NotReadHandled = 0x05, 353 GN_SMS_FLD_Changed = 0x06 354 } gn_sms_location_status; 355 356 typedef struct { 357 gn_sms_location_status status; /* deleted, new, old, ToBeRemoved */ 358 unsigned int location; 359 gn_sms_message_type message_type; 360 } gn_sms_message_list; 361 362 typedef struct { 363 int number; /* -1 if folder is not supported by the phone */ 364 unsigned int unread; /* only valid for INBOX */ 365 unsigned int changed; 366 unsigned int used; /* because 'Used' can vary from 'Number' when we have deleted messages */ 367 } gn_sms_folder_stats; 368 369 typedef struct { 370 unsigned char binary[GN_SMS_MAX_LENGTH]; 371 int curr, total; /* Number of this part, total number of parts */ 372 } gn_sms_multi; 373 374 typedef struct { 375 int curr, total, serial; 376 } gn_sms_concat; 377 378 typedef struct { 379 gn_sms_data_type type; 380 unsigned int length; /* Number of bytes used */ 381 unsigned int chars; /* Number of chars used */ 382 union { 383 unsigned char text[10 * GN_SMS_MAX_LENGTH + 1]; 384 gn_sms_multi multi; 385 gn_bmp bitmap; 386 gn_ringtone ringtone; 387 gn_bmp animation[4]; 388 gn_sms_concat concat; 389 } u; 390 /* That should be in the union, but for delivery reports we already 391 * set text there. Currently we don't want to break API, so I put it here 392 * Pawel Kot, 2007-11-21 393 */ 394 gn_sms_delivery_report_status dr_status; 395 } gn_sms_user_data; 396 397 /* Define datatype for SMS messages exported to the user applications. */ 398 typedef struct { 399 /* General fields */ 400 gn_sms_message_type type; /* Type of the message. */ 401 int delivery_report; /* Do we request the delivery report? Only for setting. */ 402 gn_sms_message_status status; /* Status of the message read/unread/sent/unsent. */ 403 unsigned int validity; /* Message validity in minutes. Only for setting. */ 404 gn_memory_type memory_type; /* Memory type where the message is/should be stored. */ 405 unsigned int number; /* Location of the message in the memory/folder. */ 406 407 /* Number related fields */ 408 gn_gsm_number smsc; /* SMSC Number. */ 409 gn_gsm_number remote; /* Remote (sender/recipient) number. */ 410 411 /* Data format fields */ 412 gn_sms_dcs dcs; 413 gn_sms_user_data user_data[GN_SMS_PART_MAX_NUMBER]; 414 gn_sms_udh udh; 415 416 /* Date fields */ 417 gn_timestamp smsc_time; /* SMSC Timestamp. Only for reading. */ 418 gn_timestamp time; /* Delivery timestamp. Only for reading. */ 419 420 /* Additional fields. Read only. Set by gn_sms_send(). *reference needs to be freed when not needed anymore. */ 421 unsigned int parts; /* Number of parts. For SMS send request, it is set to number of SMS the message was splitted. */ 422 unsigned int *reference; /* List of reference numbers of the message sent. */ 423 } gn_sms; 424 425 /* Define datatype for SMS messages, describes precisely GSM Spec 03.40 */ 426 typedef struct { 427 unsigned int type; /* Message Type Indicator - 2 bits (9.2.3.1) */ 428 int more_messages; /* More Messages to Send (9.2.3.2) */ 429 int reply_via_same_smsc; /* Reply Path (9.2.3.17) - `Reply via same centre' in the phone */ 430 int reject_duplicates; /* Reject Duplicates (9.2.3.25) */ 431 int report; /* Status Report (9.2.3.4, 9.2.3.5 & 9.2.3.26) - `Delivery reports' in the phone */ 432 433 unsigned int number; /* Message Number - 8 bits (9.2.3.18) */ 434 unsigned int reference; /* Message Reference - 8 bit (9.2.3.6) */ 435 unsigned int pid; /* Protocol Identifier - 8 bit (9.2.3.9) */ 436 unsigned int report_status; /* Status - 8 bit (9.2.3.15), Failure Cause (9.2.3.22) */ 437 438 unsigned char smsc_time[GN_SMS_DATETIME_MAX_LENGTH]; /* Service Centre Time Stamp (9.2.3.11) */ 439 unsigned char time[GN_SMS_DATETIME_MAX_LENGTH]; /* Discharge Time (9.2.3.13) */ 440 unsigned char message_center[GN_SMS_SMSC_NUMBER_MAX_LENGTH];/* SMSC Address (9.2.3.7, 9.2.3.8, 9.2.3.14) */ 441 unsigned char remote_number[GN_SMS_NUMBER_MAX_LENGTH]; /* Origination, destination, Recipient Address (9.2.3.7, 9.2.3.8, 9.2.3.14) */ 442 443 unsigned int dcs; /* Data Coding Scheme (9.2.3.10) */ 444 unsigned int length; /* User Data Length (9.2.3.16), Command Data Length (9.2.3.20) */ 445 int udh_indicator; 446 unsigned char user_data[GN_SMS_LONG_MAX_LENGTH]; /* User Data (9.2.3.24), Command Data (9.2.3.21), extended to Nokia Multipart Messages from Smart Messaging Specification 3.0.0 */ 447 int user_data_length; /* Length of just previous field */ 448 449 gn_sms_vp_format validity_indicator; 450 unsigned char validity[GN_SMS_VP_MAX_LENGTH]; /* Validity Period Format & Validity Period (9.2.3.3 & 9.2.3.12) - `Message validity' in the phone */ 451 452 /* Other fields */ 453 unsigned int memory_type; /* MemoryType (for 6210/7110): folder indicator */ 454 unsigned int status; /* Status of the message: sent/read or unsent/unread */ 455 } gn_sms_raw; 456 457 458 /*** FOLDERS ***/ 459 460 /*** Datatype for SMS folders ***/ 461 /* Max name length is 32 characters and trailing \0 */ 462 #define GN_SMS_FOLDER_NAME_MAX_LENGTH 33 463 typedef struct { 464 /* Name for SMS folder. */ 465 char name[GN_SMS_FOLDER_NAME_MAX_LENGTH]; 466 /* if folder contains sender, SMSC number and sending date */ 467 int sms_data; 468 /* locations of SMS messages in that folder (6210 specific) */ 469 unsigned int locations[GN_SMS_MESSAGE_MAX_NUMBER]; 470 /* number of SMS messages in that folder*/ 471 unsigned int number; 472 /* ID of the current folder */ 473 unsigned int folder_id; 474 } gn_sms_folder; 475 476 typedef struct { 477 gn_sms_folder folder[GN_SMS_FOLDER_MAX_NUMBER]; 478 /* ID specific for this folder and phone. Used in internal functions. 479 * Do not use it. */ 480 unsigned int folder_id[GN_SMS_FOLDER_MAX_NUMBER]; 481 /* number of SMS folders */ 482 unsigned int number; 483 } gn_sms_folder_list; 484 485 /*** CELL BROADCAST ***/ 486 487 #define GN_CM_MESSAGE_MAX_LENGTH 160 488 489 /* Define datatype for Cell Broadcast message */ 490 typedef struct { 491 int channel; 492 char message[GN_CM_MESSAGE_MAX_LENGTH + 1]; 493 int is_new; 494 } gn_cb_message; 495 496 GNOKII_API void gn_sms_default_submit(gn_sms *sms); 497 GNOKII_API void gn_sms_default_deliver(gn_sms *sms); 498 499 /* WAPPush */ 500 501 typedef struct { 502 unsigned char wsp_tid; 503 unsigned char wsp_pdu; 504 unsigned char wsp_hlen; 505 unsigned char wsp_content_type; 506 507 unsigned char version; /* wbxml version */ 508 unsigned char public_id; 509 unsigned char charset; /* default 106 = UTF-8 */ 510 unsigned char stl; 511 } gn_wap_push_header; 512 513 typedef struct { 514 gn_wap_push_header header; 515 char *url; 516 char *text; 517 char *data; 518 int data_len; 519 } gn_wap_push; 520 521 GNOKII_API void gn_wap_push_init(gn_wap_push *wp); 522 GNOKII_API gn_error gn_wap_push_encode(gn_wap_push *wp); 523 524 #endif /* _gnokii_sms_h */ 525