1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
|
/* (c) 2002-2004 by Marcin Wiacek */
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "../../gsmcomon.h"
#include "../../misc/coding/coding.h"
#include "../gsmcal.h"
#include "../gsmpbk.h"
#include "../gsmlogo.h"
#include "../gsmring.h"
#include "../gsmdata.h"
#include "../gsmnet.h"
#include "gsmsms.h"
#include "gsmmulti.h"
/* EMS Developers' Guidelines from www.sonyericsson.com
* docs from Alcatel
*/
GSM_Error GSM_EncodeEMSMultiPartSMS(GSM_MultiPartSMSInfo *Info,
GSM_MultiSMSMessage *SMS,
GSM_UDH UDHType)
{
unsigned char Buffer[GSM_MAX_SMS_LENGTH*2*MAX_MULTI_SMS];
int i,UsedText,j,Length,Width,Height,z,x,y;
unsigned int Len;
int Used,FreeText,FreeBytes,Width2,CopiedText,CopiedSMSText;
unsigned char UDHID;
GSM_Bitmap Bitmap,Bitmap2;
GSM_Ringtone Ring;
GSM_Coding_Type Coding = SMS_Coding_Default;
GSM_Phone_Bitmap_Types BitmapType;
MultiPartSMSEntry *Entry;
bool start;
GSM_DateTime Date;
#ifdef DEBUG
if (UDHType != UDH_NoUDH) dbgprintf("linked EMS\n");
#endif
if (Info->UnicodeCoding) Coding = SMS_Coding_Unicode;
/* Cleaning on the start */
for (i=0;i<MAX_MULTI_SMS;i++) {
GSM_SetDefaultSMSData(&SMS->SMS[i]);
SMS->SMS[i].UDH.Type = UDHType;
GSM_EncodeUDHHeader(&SMS->SMS[i].UDH);
SMS->SMS[i].Coding = Coding;
}
/* Packing */
for (i=0;i<Info->EntriesNum;i++) {
Entry = &Info->Entries[i];
switch (Entry->ID) {
case SMS_ConcatenatedTextLong:
case SMS_ConcatenatedTextLong16bit:
Len = 0;
while(1) {
if (Entry->Left || Entry->Right ||
Entry->Center || Entry->Large ||
Entry->Small || Entry->Bold ||
Entry->Italic || Entry->Underlined ||
Entry->Strikethrough) {
Buffer[0] = 0x0A; /* ID for text format */
Buffer[1] = 0x03; /* length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
Buffer[3] = 0x00; /* how many chars */
Buffer[4] = 0x00; /* formatting bits */
if (Entry->Left) {
} else if (Entry->Right) { Buffer[4] |= 1;
} else if (Entry->Center) { Buffer[4] |= 2;
} else Buffer[4] |= 3;
if (Entry->Large) { Buffer[4] |= 4;
} else if (Entry->Small) { Buffer[4] |= 8;}
if (Entry->Bold) Buffer[4] |= 16;
if (Entry->Italic) Buffer[4] |= 32;
if (Entry->Underlined) Buffer[4] |= 64;
if (Entry->Strikethrough) Buffer[4] |= 128;
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,5,true,&UsedText,&CopiedText,&CopiedSMSText);
GSM_Find_Free_Used_SMS2(Coding,SMS->SMS[SMS->Number], &UsedText, &FreeText, &FreeBytes);
if (FreeText == 0) continue;
}
GSM_AddSMS_Text_UDH(SMS,Coding,Entry->Buffer+Len*2,UnicodeLength(Entry->Buffer) - Len,false,&UsedText,&CopiedText,&CopiedSMSText);
if (Entry->Left || Entry->Right ||
Entry->Center || Entry->Large ||
Entry->Small || Entry->Bold ||
Entry->Italic || Entry->Underlined ||
Entry->Strikethrough) {
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-3] = UsedText;
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-2] = CopiedSMSText;
}
Len += CopiedText;
if (Len == UnicodeLength(Entry->Buffer)) break;
dbgprintf("%i %i\n",Len,UnicodeLength(Entry->Buffer));
}
break;
case SMS_EMSPredefinedSound:
case SMS_EMSPredefinedAnimation:
if (Entry->ID == SMS_EMSPredefinedSound) {
Buffer[0] = 0x0B; /* ID for def.sound */
} else {
Buffer[0] = 0x0D; /* ID for def.animation */
}
Buffer[1] = 0x02; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
Buffer[3] = Entry->Number; /* Number of anim. */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-2] = UsedText;
break;
case SMS_EMSSonyEricssonSound:
case SMS_EMSSound10:
case SMS_EMSSound12:
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
Length = 128; /* 128 bytes is maximal length from specs */
switch (Entry->ID) {
case SMS_EMSSound10:
Entry->RingtoneNotes = GSM_EncodeEMSSound(*Entry->Ringtone, Buffer+3, &Length, 1.0, true);
break;
case SMS_EMSSound12:
Entry->RingtoneNotes = GSM_EncodeEMSSound(*Entry->Ringtone, Buffer+3, &Length, 1.2, true);
break;
case SMS_EMSSonyEricssonSound:
Entry->RingtoneNotes = GSM_EncodeEMSSound(*Entry->Ringtone, Buffer+3, &Length, 0, true);
break;
default:
break;
}
Buffer[0] = 0x0C; /* ID for EMS sound */
Buffer[1] = Length+1; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,Length+3,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-Length-1] = UsedText;
break;
case SMS_EMSSonyEricssonSoundLong:
case SMS_EMSSound10Long:
case SMS_EMSSound12Long:
Ring = *Entry->Ringtone;
/* First check if we can use classic format */
Length = 128; /* 128 bytes is maximal length from specs */
switch (Entry->ID) {
case SMS_EMSSound10Long:
Entry->RingtoneNotes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.0, true);
break;
case SMS_EMSSound12Long:
Entry->RingtoneNotes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.2, true);
break;
case SMS_EMSSonyEricssonSoundLong:
Entry->RingtoneNotes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 0, true);
break;
default:
break;
}
if (Entry->RingtoneNotes == Ring.NoteTone.NrCommands) {
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
Buffer[0] = 0x0C; /* ID for EMS sound */
Buffer[1] = Length+1; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,Length+3,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-Length-1] = UsedText;
break;
}
/* Find free place in first SMS */
GSM_Find_Free_Used_SMS2(Coding,SMS->SMS[SMS->Number], &UsedText, &FreeText, &FreeBytes);
Length = FreeBytes - 3;
if (Entry->Protected) Length = Length - 4;
if (Length < 0) Length = 128;
if (Length > 128) Length = 128;
Ring = *Entry->Ringtone;
/* Checking number of SMS */
Used = 0;
FreeBytes = 0;
start = true;
while (1) {
if (FreeBytes != 0) {
z = 0;
for (j=FreeBytes;j<Ring.NoteTone.NrCommands;j++) {
Ring.NoteTone.Commands[z] = Ring.NoteTone.Commands[j];
z++;
}
Ring.NoteTone.NrCommands -= FreeBytes;
if (Ring.NoteTone.NrCommands == 0) break;
Length = 128; /* 128 bytes is maximal length from specs */
}
switch (Entry->ID) {
case SMS_EMSSound10Long:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.0, start);
break;
case SMS_EMSSound12Long:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.2, start);
break;
case SMS_EMSSonyEricssonSoundLong:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 0, start);
break;
default:
break;
}
start = false;
Used++;
}
dbgprintf("Used SMS: %i\n",Used);
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = Used+1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
/* Save UPI UDH */
Buffer[0] = 0x13; /* ID for UPI */
Buffer[1] = 1; /* Length of rest */
Buffer[2] = Used; /* Number of used parts */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,3,true,&UsedText,&CopiedText,&CopiedSMSText);
/* Find free place in first SMS */
GSM_Find_Free_Used_SMS2(Coding,SMS->SMS[SMS->Number], &UsedText, &FreeText, &FreeBytes);
Length = FreeBytes - 3;
if (Length < 0) Length = 128;
if (Length > 128) Length = 128;
Ring = *Entry->Ringtone;
/* Saving */
FreeBytes = 0;
start = true;
while (1) {
if (FreeBytes != 0) {
z = 0;
for (j=FreeBytes;j<Ring.NoteTone.NrCommands;j++) {
Ring.NoteTone.Commands[z] = Ring.NoteTone.Commands[j];
z++;
}
Ring.NoteTone.NrCommands -= FreeBytes;
if (Ring.NoteTone.NrCommands == 0) break;
Length = 128; /* 128 bytes is maximal length from specs */
}
switch (Entry->ID) {
case SMS_EMSSound10Long:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.0, start);
break;
case SMS_EMSSound12Long:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 1.2, start);
break;
case SMS_EMSSonyEricssonSoundLong:
FreeBytes = GSM_EncodeEMSSound(Ring, Buffer+3, &Length, 0, start);
break;
default:
break;
}
Buffer[0] = 0x0C; /* ID for EMS sound */
Buffer[1] = Length+1; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,Length+3,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-Length-1] = UsedText;
start = false;
}
Entry->RingtoneNotes = Entry->Ringtone->NoteTone.NrCommands;
break;
case SMS_EMSAnimation:
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
if (Entry->Bitmap->Bitmap[0].BitmapWidth > 8 || Entry->Bitmap->Bitmap[0].BitmapHeight > 8) {
BitmapType = GSM_EMSMediumPicture; /* Bitmap 16x16 */
Buffer[0] = 0x0E; /* ID for 16x16 animation */
} else {
BitmapType = GSM_EMSSmallPicture; /* Bitmap 8x8 */
Buffer[0] = 0x0F; /* ID for 8x8 animation */
}
Length = PHONE_GetBitmapSize(BitmapType,0,0);
Buffer[1] = Length*Entry->Bitmap->Number + 1; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
for (j=0;j<Entry->Bitmap->Number;j++) {
PHONE_EncodeBitmap(BitmapType, Buffer+3+j*Length, &Entry->Bitmap->Bitmap[j]);
}
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,3+Length*Entry->Bitmap->Number,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-1-Length*Entry->Bitmap->Number] = UsedText;
break;
case SMS_EMSFixedBitmap:
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
if (Entry->Bitmap->Bitmap[0].BitmapWidth > 16 || Entry->Bitmap->Bitmap[0].BitmapHeight > 16) {
BitmapType = GSM_EMSBigPicture; /* Bitmap 32x32 */
Buffer[0] = 0x10; /* ID for EMS bitmap */
} else {
BitmapType = GSM_EMSMediumPicture; /* Bitmap 16x16 */
Buffer[0] = 0x11; /* ID for EMS bitmap */
}
Length = PHONE_GetBitmapSize(BitmapType,0,0);
PHONE_GetBitmapWidthHeight(BitmapType, &Width, &Height);
Buffer[1] = Length + 1; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
PHONE_EncodeBitmap(BitmapType,Buffer+3, &Entry->Bitmap->Bitmap[0]);
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,3+Length,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-1-Length] = UsedText;
break;
case SMS_EMSVariableBitmapLong:
BitmapType = GSM_EMSVariablePicture;
Width = Entry->Bitmap->Bitmap[0].BitmapWidth;
Height = Entry->Bitmap->Bitmap[0].BitmapHeight;
Bitmap = Entry->Bitmap->Bitmap[0];
/* First check if we can use classical format */
while (1) {
/* Width should be multiply of 8 */
while (Width % 8 != 0) Width--;
/* specs */
if (Width <= 96 && Height <= 128) break;
Height--;
}
Length = PHONE_GetBitmapSize(BitmapType,Width,Height);
if (Length <= 128) {
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
Buffer[0] = 0x12; /* ID for EMS bitmap */
Buffer[1] = Length + 3; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
Buffer[3] = Width/8; /* Bitmap width/8 */
Buffer[4] = Height; /* Bitmap height */
GSM_ResizeBitmap(&Bitmap, &Entry->Bitmap->Bitmap[0], Width, Height);
#ifdef DEBUG
if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,&Bitmap);
#endif
PHONE_EncodeBitmap(BitmapType,Buffer+5, &Bitmap);
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,5+Length,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-3-Length] = UsedText;
break;
}
/* Find free place in first SMS */
GSM_Find_Free_Used_SMS2(Coding,SMS->SMS[SMS->Number], &UsedText, &FreeText, &FreeBytes);
Used = 0;
Length = FreeBytes - 3;
if (Entry->Protected) Length = Length - 4;
if (Length < 0) Length = 128;
if (Length > 128) Length = 128;
/* Checking number of SMS */
FreeBytes = 0;
while (FreeBytes != Width) {
Width2 = 8;
while (FreeBytes + Width2 != Width) {
if (PHONE_GetBitmapSize(BitmapType,Width2+8,Height) > Length) break;
Width2 = Width2 + 8;
}
FreeBytes = FreeBytes + Width2;
Length = 128;
Used ++;
}
dbgprintf("Used SMS: %i\n",Used);
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = Used+1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
/* Save UPI UDH */
Buffer[0] = 0x13; /* ID for UPI */
Buffer[1] = 1; /* Length of rest */
Buffer[2] = Used; /* Number of used parts */
/* Find free place in first SMS */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,3,true,&UsedText,&CopiedText,&CopiedSMSText);
GSM_Find_Free_Used_SMS2(Coding,SMS->SMS[SMS->Number], &UsedText, &FreeText, &FreeBytes);
Length = FreeBytes - 3;
if (Length < 0) Length = 128;
if (Length > 128) Length = 128;
#ifdef DEBUG
if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,&Bitmap);
#endif
/* Saving SMS */
FreeBytes = 0;
while (FreeBytes != Width) {
Width2 = 8;
while (FreeBytes + Width2 != Width) {
if (PHONE_GetBitmapSize(BitmapType,Width2+8,Height) > Length) break;
Width2 = Width2 + 8;
}
/* Copying part of bitmap to new structure */
Bitmap2.BitmapWidth = Width2;
Bitmap2.BitmapHeight = Height;
GSM_ClearBitmap(&Bitmap2);
for (x=0;x<Width2;x++) {
for (y=0;y<Height;y++) {
if (GSM_IsPointBitmap(&Bitmap,x+FreeBytes,y)) {
GSM_SetPointBitmap(&Bitmap2, x, y);
}
}
}
#ifdef DEBUG
if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,&Bitmap2);
#endif
/* Adding new bitmap to SMS */
Length = PHONE_GetBitmapSize(BitmapType,Width2,Height);
Buffer[0] = 0x12; /* ID for EMS bitmap */
Buffer[1] = Length + 3; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
Buffer[3] = Width2/8; /* Bitmap width/8 */
Buffer[4] = Height; /* Bitmap height */
PHONE_EncodeBitmap(BitmapType,Buffer+5, &Bitmap2);
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,5+Length,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-3-Length] = UsedText;
FreeBytes = FreeBytes + Width2;
Length = 128;
}
break;
case SMS_EMSVariableBitmap:
if (Entry->Protected) {
Buffer[0] = 0x17; /* ID for ODI */
Buffer[1] = 2; /* Length of rest */
Buffer[2] = 1; /* Number of protected objects */
Buffer[3] = 1; /* 1=Protected,0=Not protected */
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,4,true,&UsedText,&CopiedText,&CopiedSMSText);
}
BitmapType = GSM_EMSVariablePicture;
Width = Entry->Bitmap->Bitmap[0].BitmapWidth;
Height = Entry->Bitmap->Bitmap[0].BitmapHeight;
while (1) {
/* Width should be multiply of 8 */
while (Width % 8 != 0) Width--;
/* specs */
if (PHONE_GetBitmapSize(BitmapType,Width,Height) <= 128) break;
Height--;
}
Length = PHONE_GetBitmapSize(BitmapType,Width,Height);
Buffer[0] = 0x12; /* ID for EMS bitmap */
Buffer[1] = Length + 3; /* Length of rest */
Buffer[2] = 0x00; /* Position in EMS msg */
Buffer[3] = Width/8; /* Bitmap width/8 */
Buffer[4] = Height; /* Bitmap height */
GSM_ResizeBitmap(&Bitmap, &Entry->Bitmap->Bitmap[0], Width, Height);
#ifdef DEBUG
if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,&Bitmap);
#endif
PHONE_EncodeBitmap(BitmapType,Buffer+5, &Bitmap);
GSM_AddSMS_Text_UDH(SMS,Coding,Buffer,5+Length,true,&UsedText,&CopiedText,&CopiedSMSText);
SMS->SMS[SMS->Number].UDH.Text[SMS->SMS[SMS->Number].UDH.Length-3-Length] = UsedText;
break;
default:
break;
}
}
SMS->Number++;
if (UDHType == UDH_ConcatenatedMessages) {
UDHID = GSM_MakeSMSIDFromTime();
for (i=0;i<SMS->Number;i++) {
SMS->SMS[i].UDH.Text[2+1] = UDHID;
SMS->SMS[i].UDH.Text[3+1] = SMS->Number;
SMS->SMS[i].UDH.Text[4+1] = i+1;
}
}
if (UDHType == UDH_ConcatenatedMessages16bit) {
UDHID = GSM_MakeSMSIDFromTime();
GSM_GetCurrentDateTime (&Date);
for (i=0;i<SMS->Number;i++) {
SMS->SMS[i].UDH.Text[2+1] = Date.Hour;
SMS->SMS[i].UDH.Text[3+1] = UDHID;
SMS->SMS[i].UDH.Text[4+1] = SMS->Number;
SMS->SMS[i].UDH.Text[5+1] = i+1;
}
}
#ifdef DEBUG
dbgprintf("SMS number is %i\n",SMS->Number);
for (i=0;i<SMS->Number;i++) {
dbgprintf("UDH length %i\n",SMS->SMS[i].UDH.Length);
DumpMessage(di.df, di.dl, SMS->SMS[i].UDH.Text, SMS->SMS[i].UDH.Length);
dbgprintf("SMS length %i\n",UnicodeLength(SMS->SMS[i].Text)*2);
DumpMessage(di.df, di.dl, SMS->SMS[i].Text, UnicodeLength(SMS->SMS[i].Text)*2);
}
#endif
return ERR_NONE;
}
static bool AddEMSText(GSM_SMSMessage *SMS, GSM_MultiPartSMSInfo *Info, int *Pos, int Len)
{
int BufferLen;
if (Len==0) return true;
if (Info->Entries[Info->EntriesNum].ID!=SMS_ConcatenatedTextLong &&
Info->Entries[Info->EntriesNum].ID!=0) {
(Info->EntriesNum)++;
}
BufferLen = UnicodeLength(Info->Entries[Info->EntriesNum].Buffer)*2;
switch (SMS->Coding) {
case SMS_Coding_8bit:
// memcpy(Info->Entries[Info->EntriesNum].Buffer+BufferLen,SMS->Text+(*Pos),Len);
// BufferLen+=Len;
// (*Pos)+=Len;
break;
case SMS_Coding_Unicode:
case SMS_Coding_Default:
Info->Entries[Info->EntriesNum].Buffer = realloc(Info->Entries[Info->EntriesNum].Buffer, BufferLen + (Len * 2) + 2);
if (Info->Entries[Info->EntriesNum].Buffer == NULL) return false;
memcpy(Info->Entries[Info->EntriesNum].Buffer + BufferLen, SMS->Text + (*Pos) *2, Len * 2);
BufferLen += Len * 2;
break;
}
(*Pos)+=Len;
Info->Entries[Info->EntriesNum].Buffer[BufferLen] = 0;
Info->Entries[Info->EntriesNum].Buffer[BufferLen+1] = 0;
Info->Entries[Info->EntriesNum].ID = SMS_ConcatenatedTextLong;
return true;
}
bool GSM_DecodeEMSMultiPartSMS(GSM_MultiPartSMSInfo *Info,
GSM_MultiSMSMessage *SMS)
{
int i, w, Pos, z, UPI = 1, width, height;
bool RetVal = false, NewPicture = true;
GSM_Phone_Bitmap_Types BitmapType;
GSM_Bitmap Bitmap,Bitmap2;
for (i=0;i<MAX_MULTI_SMS;i++) {
Info->Entries[i].ID = 0;
}
for (i=0;i<SMS->Number;i++) {
Pos = 0;
w = 1;
while (w < SMS->SMS[i].UDH.Length) {
if (Info->EntriesNum + 1 == MAX_MULTI_SMS) {
dbgprintf("Couldn't parse SMS, contains too many EMS parts!\n");
return false;
}
switch(SMS->SMS[i].UDH.Text[w]) {
case 0x00:
dbgprintf("UDH part - linked SMS with 8 bit ID\n");
break;
case 0x08:
dbgprintf("UDH part - linked SMS with 16 bit ID\n");
break;
// case 0x0A:
// dbgprintf("UDH part - EMS text formatting\n");
// break;
case 0x0B:
dbgprintf("UDH part - default EMS sound\n");
if (SMS->SMS[i].UDH.Text[w+2] > Pos) {
z = Pos;
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].UDH.Text[w+2]-z)) return false;
}
if (Info->Entries[Info->EntriesNum].ID != 0) (Info->EntriesNum)++;
Info->Entries[Info->EntriesNum].Number = SMS->SMS[i].UDH.Text[w+3];
Info->Entries[Info->EntriesNum].ID = SMS_EMSPredefinedSound;
RetVal = true;
break;
// case 0x0C:
// dbgprintf("UDH part - EMS sound\n");
// break;
case 0x0D:
dbgprintf("UDH part - default EMS animation\n");
if (SMS->SMS[i].UDH.Text[w+2] > Pos) {
z = Pos;
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].UDH.Text[w+2]-z)) return false;
}
if (Info->Entries[Info->EntriesNum].ID != 0) (Info->EntriesNum)++;
Info->Entries[Info->EntriesNum].Number = SMS->SMS[i].UDH.Text[w+3];
Info->Entries[Info->EntriesNum].ID = SMS_EMSPredefinedAnimation;
RetVal = true;
break;
case 0x0E:
case 0x0F:
if (SMS->SMS[i].UDH.Text[w] == 0x0E) {
dbgprintf("UDH part - EMS 16x16 animation\n");
BitmapType = GSM_EMSMediumPicture;
} else {
dbgprintf("UDH part - EMS 8x8 animation\n");
BitmapType = GSM_EMSSmallPicture;
}
dbgprintf("Position - %i\n",SMS->SMS[i].UDH.Text[w+2]);
if (SMS->SMS[i].UDH.Text[w+2] > Pos) {
z = Pos;
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].UDH.Text[w+2]-z)) return false;
}
(Info->EntriesNum)++;
Info->Entries[Info->EntriesNum].ID = SMS_EMSAnimation;
Info->Entries[Info->EntriesNum].Bitmap = (GSM_MultiBitmap *)malloc(sizeof(GSM_MultiBitmap));
if (Info->Entries[Info->EntriesNum].Bitmap == NULL) return false;
Info->Entries[Info->EntriesNum].Bitmap->Number = 0;
for (z=0;z<((SMS->SMS[i].UDH.Text[w+1]-1)/PHONE_GetBitmapSize(BitmapType,0,0));z++) {
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[z].Type = GSM_PictureImage;
PHONE_DecodeBitmap(BitmapType,
SMS->SMS[i].UDH.Text + w + 3 + PHONE_GetBitmapSize(BitmapType,0,0) * z,
&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[z]);
Info->Entries[Info->EntriesNum].Bitmap->Number++;
}
RetVal = true;
break;
case 0x10:
case 0x11:
if (SMS->SMS[i].UDH.Text[w] == 0x10) {
dbgprintf("UDH part - EMS 32x32 picture\n");
BitmapType = GSM_EMSBigPicture;
} else {
dbgprintf("UDH part - EMS 16x16 picture\n");
BitmapType = GSM_EMSMediumPicture;
}
dbgprintf("Position - %i\n",SMS->SMS[i].UDH.Text[w+2]);
if (SMS->SMS[i].UDH.Text[w+2] > Pos) {
z = Pos;
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].UDH.Text[w+2]-z)) return false;
}
if (Info->Entries[Info->EntriesNum].ID != 0) (Info->EntriesNum)++;
Info->Entries[Info->EntriesNum].Bitmap = (GSM_MultiBitmap *)malloc(sizeof(GSM_MultiBitmap));
if (Info->Entries[Info->EntriesNum].Bitmap == NULL) return false;
PHONE_DecodeBitmap(BitmapType,
SMS->SMS[i].UDH.Text + w + 3,
&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0]);
Info->Entries[Info->EntriesNum].Bitmap->Number = 1;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].Text[0] = 0;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].Text[1] = 0;
Info->Entries[Info->EntriesNum].ID = SMS_EMSFixedBitmap;
RetVal = true;
break;
case 0x12:
dbgprintf("UDH part - EMS variable width bitmap\n");
if (SMS->SMS[i].UDH.Text[w+2] > Pos) {
z = Pos;
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].UDH.Text[w+2]-z)) return false;
}
if (NewPicture) {
(Info->EntriesNum)++;
Info->Entries[Info->EntriesNum].Bitmap->Number = 0;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapWidth = 0;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapHeight = 0;
}
Bitmap.BitmapWidth = SMS->SMS[i].UDH.Text[w+3]*8;
Bitmap.BitmapHeight = SMS->SMS[i].UDH.Text[w+4];
Info->Entries[Info->EntriesNum].Bitmap = (GSM_MultiBitmap *)malloc(sizeof(GSM_MultiBitmap));
if (Info->Entries[Info->EntriesNum].Bitmap == NULL) return false;
if (NewPicture) {
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapWidth = Bitmap.BitmapWidth;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapHeight = Bitmap.BitmapHeight;
PHONE_DecodeBitmap(GSM_EMSVariablePicture,
SMS->SMS[i].UDH.Text + w + 5,
&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0]);
} else {
PHONE_DecodeBitmap(GSM_EMSVariablePicture,
SMS->SMS[i].UDH.Text + w + 5,
&Bitmap);
Bitmap2 = Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0];
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapWidth = Bitmap.BitmapWidth+Bitmap2.BitmapWidth;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].BitmapHeight = Bitmap2.BitmapHeight;
for (width=0;width<Bitmap2.BitmapWidth;width++) {
for (height=0;height<Bitmap2.BitmapHeight;height++) {
if (GSM_IsPointBitmap(&Bitmap2, width, height)) {
GSM_SetPointBitmap(&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0],width,height);
} else {
GSM_ClearPointBitmap(&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0],width,height);
}
}
}
for (width=0;width<Bitmap.BitmapWidth;width++) {
for (height=0;height<Bitmap2.BitmapHeight;height++) {
if (GSM_IsPointBitmap(&Bitmap, width, height)) {
GSM_SetPointBitmap(&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0],width+Bitmap2.BitmapWidth,height);
} else {
GSM_ClearPointBitmap(&Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0],width+Bitmap2.BitmapWidth,height);
}
}
}
}
if (UPI == 1) {
Info->Entries[Info->EntriesNum].Bitmap->Number = 1;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].Text[0] = 0;
Info->Entries[Info->EntriesNum].Bitmap->Bitmap[0].Text[1] = 0;
Info->Entries[Info->EntriesNum].ID = SMS_EMSVariableBitmap;
RetVal = true;
NewPicture = true;
dbgprintf("New variable picture\n");
} else {
NewPicture = false;
UPI--;
}
break;
case 0x13:
dbgprintf("UDH part - UPI\n");
dbgprintf("Value %i\n",SMS->SMS[i].UDH.Text[w+2]);
UPI = SMS->SMS[i].UDH.Text[w+2];
break;
case 0x17:
dbgprintf("UDH part - Object Distribution Indicator (Media Rights Protecting) ignored now\n");
break;
default:
dbgprintf("UDH part - block %02x\n",SMS->SMS[i].UDH.Text[w]);
Info->Unknown = true;
} /* switch */
w=w+SMS->SMS[i].UDH.Text[w+1]+2;
} /* while */
if (!AddEMSText(&SMS->SMS[i], Info, &Pos, SMS->SMS[i].Length-Pos)) return false;
RetVal = true;
}
if (RetVal) (Info->EntriesNum)++;
return RetVal;
}
/* How should editor hadle tabs in this file? Add editor commands here.
* vim: noexpandtab sw=8 ts=8 sts=8:
*/
|