Gammu internals  1.38.0
gsmdata.c
Go to the documentation of this file.
1 /* (c) 2002-2004 by Marcin Wiacek */
2 
3 #include <string.h>
4 #include <stdio.h>
5 
6 #include <gammu-debug.h>
7 #include <gammu-datetime.h>
8 
9 #include "gsmdata.h"
10 #include "../misc/coding/coding.h"
11 #include "../debug.h"
12 
13 /* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */
14 static void AddWAPSMSParameterText(unsigned char *Buffer, size_t *Length, unsigned char ID, char *Text, int Len)
15 {
16  int i;
17 
18  Buffer[(*Length)++] = 0x87; /* PARM with attributes */
19  Buffer[(*Length)++] = ID;
20  Buffer[(*Length)++] = 0x11; /* VALUE */
21  Buffer[(*Length)++] = 0x03; /* Inline string */
22  for (i=0;i<Len;i++) {
23  Buffer[(*Length)++] = Text[i]; /* Text */
24  }
25  Buffer[(*Length)++] = 0x00; /* END Inline string */
26  Buffer[(*Length)++] = 0x01; /* END PARMeter */
27 }
28 
29 /* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */
30 static void AddWAPSMSParameterInt(unsigned char *Buffer, size_t *Length, unsigned char ID, unsigned char Value)
31 {
32  Buffer[(*Length)++] = 0x87; /* PARM with attributes */
33  Buffer[(*Length)++] = ID;
34  Buffer[(*Length)++] = Value;
35  Buffer[(*Length)++] = 0x01; /* END PARMeter */
36 }
37 
38 /* http://forum.nokia.com : OTA MMS Settings 1.0, OTA Settings 7.0
39  * http://www.wapforum.org : Wireless Datagram Protocol
40  */
41 void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, size_t *Length, GSM_WAPSettings *settings, gboolean MMS)
42 {
43  int i;
44  unsigned char buffer[400];
45 
46  Buffer[(*Length)++] = 0x01; /* Push ID */
47  Buffer[(*Length)++] = 0x06; /* PDU Type (push) */
48  Buffer[(*Length)++] = 0x2C; /* Headers length (content type + headers) */
49  strcpy(Buffer+(*Length),"\x1F\x2A");
50  (*Length)=(*Length)+2; /* Value length */
51  strcpy(Buffer+(*Length),"application/x-wap-prov.browser-settings");
52  (*Length)=(*Length)+39; /* MIME-Type */
53  Buffer[(*Length)++] = 0x00; /* end inline string */
54  strcpy(Buffer+(*Length),"\x81\xEA");
55  (*Length)=(*Length)+2; /* charset UTF-8 short int. */
56  strcpy(Buffer+(*Length),"\x01\x01");
57  (*Length)=(*Length)+2; /* version WBXML 1.1 */
58  Buffer[(*Length)++] = 0x6A; /* charset UTF-8 */
59  Buffer[(*Length)++] = 0x00; /* string table length */
60 
61  Buffer[(*Length)++] = 0x45; /* CHARACTERISTIC-LIST with content */
62  Buffer[(*Length)++] = 0xC6; /* CHARACTERISTIC with content and attributes */
63  Buffer[(*Length)++] = 0x06; /* TYPE=ADDRESS */
64  Buffer[(*Length)++] = 0x01; /* END PARMeter */
65  switch (settings->Bearer) {
67  /* Bearer */
68  AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x49);
69  /* PPP_LOGINTYPE (manual login or not) */
70  if (settings->ManualLogin) {
71  AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
72  } else {
73  AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
74  }
75  /* PPP_AUTHTYPE*/
76  if (settings->IsNormalAuthentication) {
77  /* OTA_CSD_AUTHTYPE_PAP */
78  AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
79  } else {
80  /* OTA_CSD_AUTHTYPE_CHAP */
81  AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
82  }
83  /* GPRS_ACCESSPOINTNAME */
84  AddWAPSMSParameterText(Buffer, Length, 0x1C, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
85  /* PROXY */
86  AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
87  /* PPP_AUTHNAME (user) */
88  AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
89  /* PPP_AUTHSECRET (password) */
90  AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
91  break;
93  /* Bearer */
94  AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x45);
95  /* CSD_DIALSTRING */
96  AddWAPSMSParameterText(Buffer, Length, 0x21, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
97  /* PROXY */
98  AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
99  /* PPP_LOGINTYPE (manual login or not) */
100  if (settings->ManualLogin) {
101  AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
102  } else {
103  AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
104  }
105  /* PPP_AUTHTYPE*/
106  if (settings->IsNormalAuthentication) {
107  /* OTA_CSD_AUTHTYPE_PAP */
108  AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
109  } else {
110  /* OTA_CSD_AUTHTYPE_CHAP */
111  AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
112  }
113  /* CSD_CALLTYPE (type of call) */
114  if (settings->IsISDNCall) {
115  /* ISDN */
116  AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x73);
117  } else {
118  /* analogue */
119  AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x72);
120  }
121  /* CSD_CALLSPEED (speed of call) */
122  switch (settings->Speed) {
124  AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6A);
125  break;
127  AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6B);
128  break;
130  AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6C);
131  }
132  /* PPP_AUTHNAME (user) */
133  AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
134  /* PPP_AUTHSECRET (password) */
135  AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
136  break;
139  break;
140  }
141  /* PORT */
142  if (settings->IsSecurity) {
143  if (settings->IsContinuous) {
144  /* Port = 9203. Continuous */
145  AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x63);
146  } else {
147  /* Port = 9202. Temporary */
148  AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x62);
149  }
150  } else {
151  if (settings->IsContinuous) {
152  /* Port = 9201. Continuous */
153  AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x61);
154  } else {
155  /* Port = 9200. Temporary */
156  AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x60);
157  }
158  }
159  Buffer[(*Length)++] = 0x01; /* END PARMeter */
160 
161  /* URL */
162  Buffer[(*Length)++] = 0x86; /* CHARACTERISTIC-LIST with attributes */
163  if (MMS) {
164  Buffer[(*Length)++] = 0x7C; /* TYPE = MMSURL */
165  } else {
166  Buffer[(*Length)++] = 0x07; /* TYPE = URL */
167  }
168  Buffer[(*Length)++] = 0x11; /* VALUE */
169  Buffer[(*Length)++] = 0x03; /* Inline string */
170  sprintf(buffer,"%s",DecodeUnicodeString(settings->HomePage));
171  for (i=0;i<(int)strlen(buffer);i++) {
172  Buffer[(*Length)++] = buffer[i];/* Text */
173  }
174  Buffer[(*Length)++] = 0x00; /* END Inline string */
175  Buffer[(*Length)++] = 0x01; /* END PARMeter */
176 
177  /* ISP_NAME (name) */
178  Buffer[(*Length)++] = 0xC6; /* CHARACTERISTIC with content and attributes */
179  Buffer[(*Length)++] = 0x08; /* TYPE=NAME */
180  Buffer[(*Length)++] = 0x01; /* END PARMeter */
181  /* Settings name */
182  AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(settings->Title), UnicodeLength(settings->Title));
183  Buffer[(*Length)++] = 0x01; /* END PARMeter */
184  Buffer[(*Length)++] = 0x01; /* END PARMeter */
185 }
186 
187 /* http://forum.nokia.com: OTA Settings 7.0 */
188 /* first it used default/ISO coding */
189 /* Joergen Thomsen changed to UTF8 */
190 void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, size_t *Length, GSM_WAPBookmark *bookmark)
191 {
192  unsigned char buffer[100];
193 
194  Buffer[(*Length)++] = 0x01; /* Push ID */
195  Buffer[(*Length)++] = 0x06; /* PDU Type (push) */
196  Buffer[(*Length)++] = 0x2D; /* Headers length (content type + headers) */
197  strcpy(Buffer+(*Length),"\x1F\x2B");
198  (*Length)=(*Length)+2; /* Value length */
199  strcpy(Buffer+(*Length),"application/x-wap-prov.browser-bookmarks");
200  (*Length)=(*Length)+40; /* MIME-Type */
201  Buffer[(*Length)++] = 0x00; /* end inline string */
202  strcpy(Buffer+(*Length),"\x81\xEA");
203  (*Length)=(*Length)+2; /* charset UTF-8 short int. */
204 
205  /* added by Joergen Thomsen */
206  Buffer[(*Length)++] = 0x01; /* Version WBXML 1.1 */
207  Buffer[(*Length)++] = 0x01; /* Unknown public identifier */
208  Buffer[(*Length)++] = 0x6A; /* charset UTF-8 */
209  Buffer[(*Length)++] = 0x00; /* string table length */
210 
211  Buffer[(*Length)++] = 0x45; /* CHARACTERISTIC-LIST with content */
212  /* URL */
213  Buffer[(*Length)++] = 0xC6; /* CHARACTERISTIC with content and attributes */
214  Buffer[(*Length)++] = 0x7F; /* TYPE = BOOKMARK */
215  Buffer[(*Length)++] = 0x01; /* END PARMeter */
216 
217  /* TITLE */
218  EncodeUTF8(buffer, bookmark->Title);
219  AddWAPSMSParameterText(Buffer, Length, 0x15, buffer, strlen(buffer));
220  /* URL */
221  EncodeUTF8(buffer, bookmark->Address);
222  AddWAPSMSParameterText(Buffer, Length, 0x17, buffer, strlen(buffer));
223 
224  Buffer[(*Length)++] = 0x01; /* END (CHARACTERISTIC) */
225  Buffer[(*Length)++] = 0x01; /* END (CHARACTERISTIC-LIST) */
226 }
227 
233 void GSM_EncodeWAPIndicatorSMSText(unsigned char *Buffer, size_t *Length, char *Text, char *URL)
234 {
235  size_t i, len;
236 
237  Buffer[(*Length)++] = 0x01; /* Push ID */
238  Buffer[(*Length)++] = 0x06; /* PDU Type (push) */
239  Buffer[(*Length)++] = 0x01; /* Headers length */
240  Buffer[(*Length)++] = 0xAE; /* MIME-Type: application/vnd.wap.sic */
241 
242  Buffer[(*Length)++] = 0x02; /* WBXML 1.2 */
243  Buffer[(*Length)++] = 0x05; /* SI 1.0 Public Identifier */
244  Buffer[(*Length)++] = 0x6A; /* charset UTF-8 */
245  Buffer[(*Length)++] = 0x00; /* string table length */
246  Buffer[(*Length)++] = 0x45; /* SI with content */
247  Buffer[(*Length)++] = 0xC6; /* indication with content and attributes */
248  Buffer[(*Length)++] = 0x0B; /* address */
249  Buffer[(*Length)++] = 0x03; /* Inline string */
250  len = strlen(URL);
251  for (i = 0; i < len; i++) {
252  Buffer[(*Length)++] = URL[i];/* Text */
253  }
254  Buffer[(*Length)++] = 0x00; /* END Inline string */
255 
256 #if 0
257  Buffer[(*Length)++] = 0x0A; /* created... */
258  Buffer[(*Length)++] = 0xC3; /* OPAQUE */
259  Buffer[(*Length)++] = 0x07; /* length */
260  Buffer[(*Length)++] = 0x20; /* year */
261  Buffer[(*Length)++] = 0x08; /* year */
262  Buffer[(*Length)++] = 0x12; /* month */
263  Buffer[(*Length)++] = 0x10; /* day */
264  Buffer[(*Length)++] = 0x00; /* hour */
265  Buffer[(*Length)++] = 0x00; /* minute */
266  Buffer[(*Length)++] = 0x00; /* second */
267 
268  Buffer[(*Length)++] = 0x10; /* expires */
269  Buffer[(*Length)++] = 0xC3; /* OPAQUE */
270  Buffer[(*Length)++] = 0x04; /* length */
271  Buffer[(*Length)++] = 0x20; /* year */
272  Buffer[(*Length)++] = 0x10; /* year */
273  Buffer[(*Length)++] = 0x06; /* month */
274  Buffer[(*Length)++] = 0x25; /* day */
275 #endif
276 
277  Buffer[(*Length)++] = 0x01; /* END (indication) */
278  Buffer[(*Length)++] = 0x03; /* Inline string */
279  len = strlen(Text);
280  for (i = 0; i < len; i++) {
281  Buffer[(*Length)++] = Text[i]; /* Text */
282  }
283  Buffer[(*Length)++] = 0x00; /* END Inline string */
284  Buffer[(*Length)++] = 0x01; /* END (indication) */
285  Buffer[(*Length)++] = 0x01; /* END (SI) */
286 }
287 
288 GSM_Error GSM_EncodeURLFile(unsigned char *Buffer, size_t *Length, GSM_WAPBookmark *bookmark)
289 {
290  *Length+=sprintf(Buffer+(*Length), "BEGIN:VBKM%c%c",13,10);
291  *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10);
292  *Length+=sprintf(Buffer+(*Length), "TITLE:%s%c%c",DecodeUnicodeString(bookmark->Title),13,10);
293  *Length+=sprintf(Buffer+(*Length), "URL:%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
294  *Length+=sprintf(Buffer+(*Length), "BEGIN:ENV%c%c",13,10);
295  *Length+=sprintf(Buffer+(*Length), "X-IRMC-URL;QUOTED-PRINTABLE:=%c%c",13,10);
296  *Length+=sprintf(Buffer+(*Length), "[InternetShortcut] =%c%c",13,10);
297  *Length+=sprintf(Buffer+(*Length), "URL=%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
298  *Length+=sprintf(Buffer+(*Length), "END:ENV%c%c",13,10);
299  *Length+=sprintf(Buffer+(*Length), "END:VBKM%c%c",13,10);
300 
301  return ERR_NONE;
302 }
303 
304 /* -------------------------------- MMS ------------------------------------ */
305 
306 /* SNIFFS, specs somewhere in http://www.wapforum.org */
307 void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, size_t *Length, GSM_MMSIndicator *Indicator)
308 {
309  unsigned char buffer[200];
310  int i;
311 
312 
313  /*
314  * WSP header
315  */
316 
317  /* Transaction ID (maybe this should be random?) */
318  Buffer[(*Length)++] = 0xe6;
319  /* PDU type push */
320  Buffer[(*Length)++] = 0x06;
321  /* Header length */
322  Buffer[(*Length)++] = 0x22;
323  /* MIME type (header) */
324  strcpy(Buffer+(*Length),"application/vnd.wap.mms-message");
325  (*Length)=(*Length)+31;
326  Buffer[(*Length)++] = 0x00;
327 
328  /* WAP push (x-wap-application.ua) */
329  Buffer[(*Length)++] = 0xaf;
330  Buffer[(*Length)++] = 0x84;
331 
332  /*
333  * MMS data
334  */
335 
336  /* Transaction type */
337  Buffer[(*Length)++] = 0x8c;
338  /* m-notification-ind */
339  Buffer[(*Length)++] = 0x82;
340 
341  /* Transaction ID, usually last part of address */
342  Buffer[(*Length)++] = 0x98;
343  i = strlen(Indicator->Address);
344  while (Indicator->Address[i] != '/' && i!=0) i--;
345  strcpy(Buffer+(*Length),Indicator->Address+i+1);
346  (*Length)=(*Length)+strlen(Indicator->Address+i+1);
347  Buffer[(*Length)++] = 0x00;
348 
349  /* MMS version */
350  Buffer[(*Length)++] = 0x8d;
351  /* 1.2 (0x90 is 1.0) */
352  Buffer[(*Length)++] = 0x92;
353 
354  /* Message class */
355  switch (Indicator->Class) {
356  case GSM_MMS_None:
357  case GSM_MMS_INVALID:
358  break;
359  case GSM_MMS_Personal:
360  Buffer[(*Length)++] = 0x8a;
361  Buffer[(*Length)++] = 0x80;
362  break;
364  Buffer[(*Length)++] = 0x8a;
365  Buffer[(*Length)++] = 0x81;
366  break;
367  case GSM_MMS_Info:
368  Buffer[(*Length)++] = 0x8a;
369  Buffer[(*Length)++] = 0x82;
370  break;
371  case GSM_MMS_Auto:
372  Buffer[(*Length)++] = 0x8a;
373  Buffer[(*Length)++] = 0x83;
374  break;
375  }
376 
377  if (Indicator->MessageSize > 0) {
378  /* Message size */
379  Buffer[(*Length)++] = 0x8e;
380  /* Length of size */
381  Buffer[(*Length)++] = 0x04;
382  Buffer[(*Length)++] = ((long)Indicator->MessageSize >> 24) & 0xff;
383  Buffer[(*Length)++] = ((long)Indicator->MessageSize >> 16) & 0xff;
384  Buffer[(*Length)++] = ((long)Indicator->MessageSize >> 8) & 0xff;
385  Buffer[(*Length)++] = ((long)Indicator->MessageSize >> 0) & 0xff;
386  }
387 
388  /* Sender address */
389  Buffer[(*Length)++] = 0x89;
390  sprintf(buffer,"%s/TYPE=PLMN",Indicator->Sender);
391  /* Field size */
392  Buffer[(*Length)++] = (unsigned char)(strlen(buffer) + 2);
393  /* Sender address is present */
394  Buffer[(*Length)++] = 0x80;
395  strcpy(Buffer+(*Length),buffer);
396  (*Length)=(*Length)+strlen(buffer);
397  /* Zero terminate */
398  Buffer[(*Length)++] = 0x00;
399 
400  /* Subject */
401  Buffer[(*Length)++] = 0x96;
402  strcpy(Buffer+(*Length),Indicator->Title);
403  (*Length)=(*Length)+strlen(Indicator->Title);
404  Buffer[(*Length)++] = 0x00;
405 
406  strcpy(Buffer+(*Length),"\x88\x05\x81\x03\x02\xA3\xA3");
407  (*Length)=(*Length)+7;
408 
409  /* Content location */
410  Buffer[(*Length)++] = 0x83;
411  strcpy(Buffer+(*Length),Indicator->Address);
412  (*Length)=(*Length)+strlen(Indicator->Address);
413  Buffer[(*Length)++] = 0x00;
414 }
415 
417 {
418  int i;
419 
420  for (i=0;i<GSM_MAX_MULTI_MMS;i++) {
421  if (info->Entries[i].File.Buffer != NULL) {
422  free(info->Entries[i].File.Buffer);
423  info->Entries[i].File.Buffer=NULL;
424  }
425  }
426 
427  memset(info,0,sizeof(GSM_EncodedMultiPartMMSInfo));
428 
429  for (i=0;i<GSM_MAX_MULTI_MMS;i++) {
430  info->Entries[i].File.Buffer = NULL;
431  }
432  info->DateTimeAvailable = FALSE;
433 
434  return ERR_NONE;
435 }
436 
437 void GSM_AddWAPMIMEType(int type, char *buffer)
438 {
439  char tmpbuf[100];
440  switch (type) {
441  case 3:
442  strcat(buffer, "text/plain");
443  break;
444  case 6:
445  strcat(buffer, "text/x-vCalendar");
446  break;
447  case 7:
448  strcat(buffer, "text/x-vCard");
449  break;
450  case 29:
451  strcat(buffer, "image/gif");
452  break;
453  case 30:
454  strcat(buffer, "image/jpeg");
455  break;
456  case 35:
457  strcat(buffer, "application/vnd.wap.multipart.mixed");
458  break;
459  case 51:
460  strcat(buffer, "application/vnd.wap.multipart.related");
461  break;
462  default:
463  sprintf(tmpbuf, "application/x-%d", type);
464  strcat(buffer, tmpbuf);
465  break;
466  }
467 }
468 
470 {
471  size_t pos = 0;
472  int type=0,parts,j;
473  int i,len2,len3,value2;
474  long value;
475  time_t timet;
476  GSM_DateTime Date;
477  char buff[200],buff2[200];
478 
479  /* header */
480  while(1) {
481  if (pos > file->Used) break;
482  if (!(file->Buffer[pos] & 0x80)) break;
483  switch (file->Buffer[pos++] & 0x7F) {
484  case 0x01:
485  smfprintf(di, " BCC : not done yet\n");
486  return ERR_FILENOTSUPPORTED;
487  case 0x02:
488  smfprintf(di, " CC : ");
489  i = 0;
490  while (file->Buffer[pos]!=0x00) {
491  buff[i++] = file->Buffer[pos++];
492  }
493  buff[i] = 0;
494  pos++;
495  if (strstr(buff,"/TYPE=PLMN")!=NULL) {
496  buff[strlen(buff)-10] = 0;
497  info->CCType = MMSADDRESS_PHONE;
498  smfprintf(di, "phone %s\n",buff);
499  } else {
500  info->CCType = MMSADDRESS_UNKNOWN;
501  smfprintf(di, "%s\n",buff);
502  }
503  EncodeUnicode(info->CC,buff,strlen(buff));
504  break;
505  case 0x03:
506  smfprintf(di, " Content location : not done yet\n");
507  return ERR_FILENOTSUPPORTED;
508  case 0x04:
509  smfprintf(di, " Content type : ");
510  buff[0] = 0;
511  if (file->Buffer[pos] <= 0x1E) {
512  len2 = file->Buffer[pos++];
513  type = file->Buffer[pos++] & 0x7f;
514  GSM_AddWAPMIMEType(type, buff);
515  i=0;
516  while (i<len2) {
517  switch (file->Buffer[pos+i]) {
518  case 0x89:
519  strcat(buff, "; type=");
520  i++;
521  while (file->Buffer[pos+i]!=0x00) {
522  buff[strlen(buff)+1] = 0;
523  buff[strlen(buff)] = file->Buffer[pos+i];
524  i++;
525  }
526  i++;
527  break;
528  case 0x8A:
529  strcat(buff, "; start=");
530  i++;
531  while (file->Buffer[pos+i]!=0x00) {
532  buff[strlen(buff)+1] = 0;
533  buff[strlen(buff)] = file->Buffer[pos+i];
534  i++;
535  }
536  i++;
537  break;
538  default:
539  i++;
540  break;
541  }
542  }
543  pos+=len2-1;
544  } else if (file->Buffer[pos] == 0x1F) {
545  /* hack from coded files */
546  len2 = file->Buffer[pos++];
547  type = file->Buffer[pos++] & 0x7f;
548  type +=2;
549  GSM_AddWAPMIMEType(type, buff);
550  i=0;
551  while (i<len2) {
552  switch (file->Buffer[pos+i]) {
553  case 0x89:
554  strcat(buff, "; type=");
555  i++;
556  while (file->Buffer[pos+i]!=0x00) {
557  buff[strlen(buff)+1] = 0;
558  buff[strlen(buff)] = file->Buffer[pos+i];
559  i++;
560  }
561  i++;
562  break;
563  case 0x8A:
564  strcat(buff, "; start=");
565  i++;
566  while (file->Buffer[pos+i]!=0x00) {
567  buff[strlen(buff)+1] = 0;
568  buff[strlen(buff)] = file->Buffer[pos+i];
569  i++;
570  }
571  i++;
572  break;
573  default:
574  i++;
575  break;
576  }
577  }
578  pos+=len2+2;
579  } else if (file->Buffer[pos] >= 0x20 && file->Buffer[pos] <= 0x7F) {
580  smfprintf(di, "not done yet 2\n");
581  return ERR_FILENOTSUPPORTED;
582  } else if (file->Buffer[pos] >= 0x80 && file->Buffer[pos] < 0xFF) {
583  type = file->Buffer[pos++] & 0x7f;
584  GSM_AddWAPMIMEType(type, buff);
585  }
586  smfprintf(di, "%s\n",buff);
587  EncodeUnicode(info->ContentType,buff,strlen(buff));
588  break;
589  case 0x05:
590  smfprintf(di, " Date : ");
591  value=0;
592  len2 = file->Buffer[pos++];
593  for (i=0;i<len2;i++) {
594  value=value<<8;
595  value |= file->Buffer[pos++];
596  }
597  timet = value;
598  Fill_GSM_DateTime(&Date, timet);
599  smfprintf(di, "%s\n",OSDateTime(Date,0));
600  info->DateTimeAvailable = TRUE;
601  memcpy(&info->DateTime,&Date,sizeof(GSM_DateTime));
602  break;
603  case 0x06:
604  smfprintf(di, " Delivery report : ");
605  info->MMSReportAvailable = TRUE;
606  switch(file->Buffer[pos++]) {
607  case 0x80:
608  smfprintf(di, "yes\n");
609  info->MMSReport = TRUE;
610  break;
611  case 0x81:
612  smfprintf(di, "no\n");
613  info->MMSReport = FALSE;
614  break;
615  default:
616  smfprintf(di, "unknown\n");
617  return ERR_FILENOTSUPPORTED;
618  }
619  break;
620  case 0x08:
621  smfprintf(di, " Expiry : ");
622  pos++; /* length? */
623  switch (file->Buffer[pos]) {
624  case 0x80: smfprintf(di, "date - ignored\n"); break;
625  case 0x81: smfprintf(di, "seconds - ignored\n"); break;
626  default : smfprintf(di, "unknown %02x\n",file->Buffer[pos]); break;
627  }
628  pos++;
629  pos++; /* expiry */
630  pos++; /* expiry */
631  pos++; /* expiry */
632  pos++; /* expiry */
633  break;
634  case 0x09:
635  pos++;
636  pos++;
637  if (file->Buffer[pos-1] == 128) {
638  smfprintf(di, " From : ");
639  len2=file->Buffer[pos-2]-1;
640  for (i=0;i<len2;i++) {
641  buff[i] = file->Buffer[pos++];
642  }
643  buff[i] = 0;
644  if (strstr(buff,"/TYPE=PLMN")!=NULL) {
645  buff[strlen(buff)-10] = 0;
647  smfprintf(di, "phone %s\n",buff);
648  } else {
650  smfprintf(di, "%s\n",buff);
651  }
652  EncodeUnicode(info->Source,buff,strlen(buff));
653  }
654  break;
655  case 0x0A:
656  smfprintf(di, " Message class : ");
657  switch (file->Buffer[pos++]) {
658  case 0x80: smfprintf(di, "personal\n"); break;
659  case 0x81: smfprintf(di, "advertisment\n"); break;
660  case 0x82: smfprintf(di, "informational\n"); break;
661  case 0x83: smfprintf(di, "auto\n"); break;
662  default : smfprintf(di, "unknown\n"); break;
663  }
664  break;
665  case 0x0B:
666  smfprintf(di, " Message ID : ");
667  while (file->Buffer[pos]!=0x00) {
668  smfprintf(di, "%c",file->Buffer[pos]);
669  pos++;
670  }
671  smfprintf(di, "\n");
672  pos++;
673  break;
674  case 0x0C:
675  smfprintf(di, " Message type : ");
676  switch (file->Buffer[pos++]) {
677  case 0x80: sprintf(info->MSGType,"m-send-req"); break;
678  case 0x81: sprintf(info->MSGType,"m-send-conf"); break;
679  case 0x82: sprintf(info->MSGType,"m-notification-ind"); break;
680  case 0x83: sprintf(info->MSGType,"m-notifyresp-ind"); break;
681  case 0x84: sprintf(info->MSGType,"m-retrieve-conf"); break;
682  case 0x85: sprintf(info->MSGType,"m-acknowledge-ind"); break;
683  case 0x86: sprintf(info->MSGType,"m-delivery-ind"); break;
684  default : smfprintf(di, "unknown\n"); return ERR_FILENOTSUPPORTED;
685  }
686  smfprintf(di, "%s\n",info->MSGType);
687  break;
688  case 0x0D:
689  value2 = file->Buffer[pos] & 0x7F;
690  smfprintf(di, " MMS version : %i.%i\n", (value2 & 0x70) >> 4, value2 & 0x0f);
691  pos++;
692  break;
693  case 0x0E:
694  smfprintf(di, " Message size : ignored for now\n");
695  pos += 2;
696  break;
697  case 0x0F:
698  smfprintf(di, " Priority : ");
699  switch (file->Buffer[pos++]) {
700  case 0x80: smfprintf(di, "low\n"); break;
701  case 0x81: smfprintf(di, "normal\n"); break;
702  case 0x82: smfprintf(di, "high\n"); break;
703  default : smfprintf(di, "unknown\n"); break;
704  }
705  break;
706  case 0x10:
707  smfprintf(di, " Read reply : ");
708  switch(file->Buffer[pos++]) {
709  case 0x80: smfprintf(di, "yes\n"); break;
710  case 0x81: smfprintf(di, "no\n"); break;
711  default : smfprintf(di, "unknown\n");
712  }
713  break;
714  case 0x11:
715  smfprintf(di, " Report allowed : not done yet\n");
716  return ERR_FILENOTSUPPORTED;
717  case 0x12:
718  smfprintf(di, " Response status : not done yet\n");
719  return ERR_FILENOTSUPPORTED;
720  case 0x13:
721  smfprintf(di, " Response text : not done yet\n");
722  return ERR_FILENOTSUPPORTED;
723  case 0x14:
724  smfprintf(di, " Sender visibility : not done yet\n");
725  return ERR_FILENOTSUPPORTED;
726  case 0x15:
727  smfprintf(di, " Status : ");
728  switch (file->Buffer[pos++]) {
729  case 0x80: smfprintf(di, "expired\n"); break;
730  case 0x81: smfprintf(di, "retrieved\n"); break;
731  case 0x82: smfprintf(di, "rejected\n"); break;
732  case 0x83: smfprintf(di, "deferred\n"); break;
733  case 0x84: smfprintf(di, "unrecognized\n"); break;
734  default : smfprintf(di, "unknown\n");
735  }
736  pos++;
737  pos++;
738  break;
739  case 0x16:
740  smfprintf(di, " Subject : ");
741  if (file->Buffer[pos+1]==0xEA) {
742  pos+=2;
743  }
744  i = 0;
745  while (file->Buffer[pos]!=0x00) {
746  buff[i++] = file->Buffer[pos++];
747  }
748  buff[i] = 0;
749  smfprintf(di, "%s\n",buff);
750  EncodeUnicode(info->Subject,buff,strlen(buff));
751  pos++;
752  break;
753  case 0x17:
754  smfprintf(di, " To : ");
755  i = 0;
756  while (file->Buffer[pos]!=0x00) {
757  buff[i++] = file->Buffer[pos++];
758  }
759  buff[i] = 0;
760  if (strstr(buff,"/TYPE=PLMN")!=NULL) {
761  buff[strlen(buff)-10] = 0;
763  smfprintf(di, "phone %s\n",buff);
764  } else {
766  smfprintf(di, "%s\n",buff);
767  }
768  EncodeUnicode(info->Destination,buff,strlen(buff));
769  pos++;
770  break;
771  case 0x18:
772  smfprintf(di, " Transaction ID : ");
773  while (file->Buffer[pos]!=0x00) {
774  smfprintf(di, "%c",file->Buffer[pos]);
775  pos++;
776  }
777  smfprintf(di, "\n");
778  pos++;
779  break;
780  default:
781  smfprintf(di, " unknown1\n");
782  break;
783  }
784  }
785 
786  /* if we don't have any parts, we exit */
787  if (type != 35 && type != 51) return ERR_NONE;
788 
789  value = 0;
790  while (TRUE) {
791  value = value << 7;
792  value |= file->Buffer[pos] & 0x7F;
793  pos++;
794  if (!(file->Buffer[pos-1] & 0x80)) break;
795  }
796  value2 = value;
797  smfprintf(di, " Parts : %i\n",value2);
798  parts = value;
799 
800  for (j=0;j<parts;j++) {
801  value = 0;
802  while (TRUE) {
803  value = value << 7;
804  value |= file->Buffer[pos] & 0x7F;
805  pos++;
806  if (!(file->Buffer[pos-1] & 0x80)) break;
807  }
808  smfprintf(di, " Header len: %li",value);
809  len2 = value;
810 
811  value = 0;
812  while (TRUE) {
813  value = value << 7;
814  value |= file->Buffer[pos] & 0x7F;
815  pos++;
816  if (!(file->Buffer[pos-1] & 0x80)) break;
817  }
818  smfprintf(di, ", data len: %li\n",value);
819  len3 = value;
820 
821  /* content type */
822  i = 0;
823  buff[0] = 0;
824  smfprintf(di, " Content type : ");
825  if (file->Buffer[pos] >= 0x80) {
826  type = file->Buffer[pos] & 0x7f;
827  GSM_AddWAPMIMEType(type, buff);
828  } else if (file->Buffer[pos+i] == 0x1F) {
829  i++;
830  buff[0] = 0;
831  /* len4 = file->Buffer[pos+i]; */
832  i++;
833  if (!(file->Buffer[pos+i] & 0x80)) {
834  while (file->Buffer[pos+i]!=0x00) {
835  buff[strlen(buff)+1] = 0;
836  buff[strlen(buff)] = file->Buffer[pos+i];
837  i++;
838  }
839  i++;
840  } else {
841  value = file->Buffer[pos+i] & 0x7F;
842  GSM_AddWAPMIMEType(value, buff);
843  i++;
844  }
845  } else if (file->Buffer[pos+i] < 0x1F) {
846  i++;
847  if (file->Buffer[pos+i] & 0x80) {
848  type = file->Buffer[pos+i] & 0x7f;
849  GSM_AddWAPMIMEType(type, buff);
850  i++;
851  } else {
852  while (file->Buffer[pos+i]!=0x00) {
853  buff[strlen(buff)+1] = 0;
854  buff[strlen(buff)] = file->Buffer[pos+i];
855  i++;
856  }
857  i++;
858  }
859  } else {
860  while (file->Buffer[pos+i]!=0x00) {
861  buff[strlen(buff)+1] = 0;
862  buff[strlen(buff)] = file->Buffer[pos+i];
863  i++;
864  }
865  }
866  smfprintf(di, "%s\n",buff);
867  EncodeUnicode(info->Entries[info->EntriesNum].ContentType,buff,strlen(buff));
868 
869  pos+=i;
870  len2-=i;
871 
872  i=0;
873  while (i<len2) {
874  switch (file->Buffer[pos+i]) {
875  case 0x81:
876  i++;
877  break;
878  case 0x83:
879  break;
880  case 0x85:
881  /* mms 1.0 file from GSM operator */
882  buff2[0] = 0;
883  i++;
884  while (file->Buffer[pos+i]!=0x00) {
885  buff2[strlen(buff2)+1] = 0;
886  buff2[strlen(buff2)] = file->Buffer[pos+i];
887  i++;
888  }
889  EncodeUnicode(info->Entries[info->EntriesNum].File.Name,buff2,strlen(buff2));
890  break;
891  case 0x86:
892  while (file->Buffer[pos+i]!=0x00) i++;
893  break;
894  case 0x89:
895  strcpy(buff, "; type=");
896  i++;
897  while (file->Buffer[pos+i]!=0x00) {
898  buff[strlen(buff)+1] = 0;
899  buff[strlen(buff)] = file->Buffer[pos+i];
900  i++;
901  }
902  i++;
903  break;
904  case 0x8A:
905  strcpy(buff, "; type=");
906  i++;
907  while (file->Buffer[pos+i]!=0x00) {
908  buff[strlen(buff)+1] = 0;
909  buff[strlen(buff)] = file->Buffer[pos+i];
910  i++;
911  }
912  i++;
913  break;
914  case 0x8E:
915  i++;
916  buff[0] = 0;
917  smfprintf(di, " Name : ");
918  while (file->Buffer[pos+i]!=0x00) {
919  buff[strlen(buff)+1] = 0;
920  buff[strlen(buff)] = file->Buffer[pos+i];
921  i++;
922  }
923  smfprintf(di, "%s\n",buff);
924  EncodeUnicode(info->Entries[info->EntriesNum].File.Name,buff,strlen(buff));
925  break;
926  case 0xAE:
927  while (file->Buffer[pos+i]!=0x00) i++;
928  break;
929  case 0xC0:
930  i++;
931  i++;
932  buff[0] = 0;
933  smfprintf(di, " SMIL CID : ");
934  while (file->Buffer[pos+i]!=0x00) {
935  buff[strlen(buff)+1] = 0;
936  buff[strlen(buff)] = file->Buffer[pos+i];
937  i++;
938  }
939  smfprintf(di, "%s\n",buff);
940  EncodeUnicode(info->Entries[info->EntriesNum].SMIL,buff,strlen(buff));
941  break;
942  default:
943  smfprintf(di, "unknown3 %02x\n",file->Buffer[pos+i]);
944  }
945  i++;
946  }
947  pos+=i;
948 
949  /* data */
950  info->Entries[info->EntriesNum].File.Buffer = (unsigned char *)realloc(info->Entries[info->EntriesNum].File.Buffer,len3);
951  info->Entries[info->EntriesNum].File.Used = len3;
952  memcpy(info->Entries[info->EntriesNum].File.Buffer,file->Buffer+pos,len3);
953 
954  info->EntriesNum++;
955  pos+=len3;
956  }
957  return ERR_NONE;
958 }
959 
960 /* How should editor hadle tabs in this file? Add editor commands here.
961  * vim: noexpandtab sw=8 ts=8 sts=8:
962  */
char IPAddress[(20+1) *2]
Definition: gammu-wap.h:128
gboolean IsNormalAuthentication
Definition: gammu-wap.h:104
unsigned char Name[2 *(GSM_MAX_FILENAME_LENGTH+1)]
Definition: gammu-file.h:74
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
char Title[(20+1) *2]
Definition: gammu-wap.h:79
void GSM_AddWAPMIMEType(int type, char *buffer)
Definition: gsmdata.c:437
gboolean IsSecurity
Definition: gammu-wap.h:91
char Address[500]
Definition: gammu-message.h:90
void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, size_t *Length, GSM_MMSIndicator *Indicator)
Definition: gsmdata.c:307
GSM_Error
Definition: gammu-error.h:23
void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, size_t *Length, GSM_WAPSettings *settings, gboolean MMS)
Definition: gsmdata.c:41
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
static void AddWAPSMSParameterInt(unsigned char *Buffer, size_t *Length, unsigned char ID, unsigned char Value)
Definition: gsmdata.c:30
GSM_MMS_Class Class
unsigned char Source[200]
void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, size_t *Length, GSM_WAPBookmark *bookmark)
Definition: gsmdata.c:190
unsigned char * Buffer
Definition: gammu-file.h:94
GSM_Error GSM_ClearMMSMultiPart(GSM_EncodedMultiPartMMSInfo *info)
Definition: gsmdata.c:416
unsigned char ContentType[400]
WAPSettings_Bearer Bearer
Definition: gammu-wap.h:87
static void AddWAPSMSParameterText(unsigned char *Buffer, size_t *Length, unsigned char ID, char *Text, int Len)
Definition: gsmdata.c:14
size_t Used
Definition: gammu-file.h:70
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
Definition: misc.c:170
int gboolean
Definition: gammu-types.h:23
char User[(50+1) *2]
Definition: gammu-wap.h:142
gboolean ManualLogin
Definition: gammu-wap.h:132
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
#define FALSE
Definition: gammu-types.h:25
GSM_Error GSM_EncodeURLFile(unsigned char *Buffer, size_t *Length, GSM_WAPBookmark *bookmark)
Definition: gsmdata.c:288
unsigned char ContentType[400]
WAPSettings_Speed Speed
Definition: gammu-wap.h:152
unsigned char Subject[200]
char Sender[200]
Definition: gammu-message.h:98
gboolean IsISDNCall
Definition: gammu-wap.h:100
char * OSDateTime(GSM_DateTime dt, gboolean TimeZone)
Definition: misc.c:264
void GSM_EncodeWAPIndicatorSMSText(unsigned char *Buffer, size_t *Length, char *Text, char *URL)
Definition: gsmdata.c:233
GSM_Error GSM_DecodeMMSFileToMultiPart(GSM_Debug_Info *di, GSM_File *file, GSM_EncodedMultiPartMMSInfo *info)
Definition: gsmdata.c:469
char Password[(50+1) *2]
Definition: gammu-wap.h:148
unsigned char Destination[200]
unsigned char Title[(50+1) *2]
Definition: gammu-wap.h:42
char DialUp[(20+1) *2]
Definition: gammu-wap.h:136
gboolean IsContinuous
Definition: gammu-wap.h:95
int smfprintf(GSM_Debug_Info *d, const char *format,...)
Definition: debug.c:240
gboolean EncodeUTF8(char *dest, const unsigned char *src)
Definition: coding.c:1835
char HomePage[(100+1) *2]
Definition: gammu-wap.h:83
unsigned char Address[(255+1) *2]
Definition: gammu-wap.h:38
#define TRUE
Definition: gammu-types.h:28
#define GSM_MAX_MULTI_MMS
Definition: gammu-limits.h:211
GSM_EncodedMultiPartMMSEntry Entries[GSM_MAX_MULTI_MMS]