Gammu internals  1.38.0
gnapgen.c
Go to the documentation of this file.
1 /* (c) 2006 by Marcin Wiacek
2  * (C) 2007 Matthias Lechner <[email protected]> */
3 
4 #include <string.h>
5 #include <time.h>
6 
7 #include <gammu-config.h>
8 
9 #include "../../gsmcomon.h"
10 #include "../../gsmphones.h"
11 #include "../../misc/coding/coding.h"
12 #include "../../service/gsmmisc.h"
13 #include "../../service/gsmcal.h"
14 #include "../nokia/nfunc.h"
15 #include "../pfunc.h"
16 
17 #ifdef GSM_ENABLE_GNAPGEN
18 
19 unsigned char GNAPGEN_MEMORY_TYPES[] = {
20  MEM_SM, 0x01,
21  MEM_ON, 0x03,
22  MEM_DC, 0x05,
23  MEM_RC, 0x06,
24  MEM_MC, 0x07,
25  0x00, 0x00
26 };
27 
28 GSM_Error GNAPGEN_Install(GSM_StateMachine *s, const char *ExtraPath, gboolean Minimal)
29 {
30  GSM_StateMachine *gsm;
31  GSM_Debug_Info *debug_info;
32  GSM_Config *cfg;
33  GSM_Error error;
34  GSM_File INIFile, AppletFile;
35 
36  AppletFile.Buffer = NULL;
37  AppletFile.Used = 0;
38  INIFile.Buffer = NULL;
39  INIFile.Used = 0;
40 
41  error = PHONE_FindDataFile(s, &AppletFile, ExtraPath, "gnapplet.sis");
42  if (error != ERR_NONE) {
43  smprintf(s, "Failed to load applet data!\n");
44  return ERR_INSTALL_NOT_FOUND;
45  }
46 
47  error = PHONE_FindDataFile(s, &INIFile, ExtraPath, "gnapplet.ini");
48  if (error != ERR_NONE) {
49  smprintf(s, "Failed to load applet configuration!\n");
50  return ERR_INSTALL_NOT_FOUND;
51  }
52 
53  gsm = GSM_AllocStateMachine();
54  if (gsm == NULL) {
55  return ERR_MOREMEMORY;
56  }
57 
58  /* Copy debug configuration */
59  debug_info = GSM_GetDebug(gsm);
60  *debug_info = *GSM_GetDebug(s);
61  debug_info->closable = FALSE;
62  GSM_SetDebugFileDescriptor(GSM_GetDebug(s)->df, FALSE, debug_info);
64 
65  /* Generate configuration */
66  cfg = GSM_GetConfig(gsm, 0);
67  cfg->Device = strdup(s->CurrentConfig->Device);
68  cfg->Connection = strdup("blueobex");
69  strcpy(cfg->Model, "obexnone");
70  strcpy(cfg->DebugLevel, s->CurrentConfig->DebugLevel);
72 
73  /* We have one configuration */
74  GSM_SetConfigNum(gsm, 1);
75 
76  error = GSM_InitConnection(gsm, 1);
77  if (error != ERR_NONE) {
78  return error;
79  }
80 
81  error = PHONE_UploadFile(gsm, &AppletFile);
82  free(AppletFile.Buffer);
83  if (error != ERR_NONE) {
84  return error;
85  }
86 
87  error = PHONE_UploadFile(gsm, &INIFile);
88  if (error != ERR_NONE) {
89  return error;
90  }
91 
92  error = GSM_TerminateConnection(gsm);
93  if (error != ERR_NONE) {
94  return error;
95  }
96 
97  /* Free up used memory */
99 
100  return ERR_NONE;
101 }
102 GSM_Error GNAPGEN_ReplyGetSMSFolderStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s) {
103  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
104  int i;
105  int pos = 10;
106 
107  if( msg->Buffer[3] == 17){
108  smprintf(s, "Invalid memory type");
109  return ERR_UNKNOWN;
110  }
111 
112  Priv->SMSCount = msg->Buffer[8] * 256 + msg->Buffer[9];
113  smprintf(s, "SMS count: %d\n", Priv->SMSCount );
114 
115  for( i=0; i<Priv->SMSCount; i++ ) {
116  smprintf(s, "Entry id %d: %d\n", i, msg->Buffer[pos+1] * 256 * 256 + msg->Buffer[pos+2]*256+msg->Buffer[pos+3]);
117  Priv->SMSIDs[i].byte1 = msg->Buffer[pos];
118  Priv->SMSIDs[i].byte2 = msg->Buffer[pos+1];
119  Priv->SMSIDs[i].byte3 = msg->Buffer[pos+2];
120  Priv->SMSIDs[i].byte4 = msg->Buffer[pos+3];
121  pos += 4;
122  }
123 
124  return ERR_NONE;
125 }
126 
127 static GSM_Error GNAPGEN_PrivGetSMSFolderStatus(GSM_StateMachine *s, int folderid)
128 {
129  unsigned char req[] = {0, 3,
130  0,0x0c}; /* folderID c,d,e,f...*/
131 
132  req[3] = folderid;
133 
134  return GSM_WaitFor(s, req, 4, 6, 4, ID_GetSMSFolderStatus);
135 }
136 
137 static GSM_Error GNAPGEN_DecodeSMSDateTime(GSM_StateMachine *s, GSM_DateTime *DT, unsigned char *req)
138 {
139  DT->Year = DecodeWithBCDAlphabet(req[0]);
140  if (DT->Year<90) DT->Year=DT->Year+2000; else DT->Year=DT->Year+1990;
141  DT->Month = DecodeWithBCDAlphabet(req[1]);
142  DT->Day = DecodeWithBCDAlphabet(req[2]);
143  DT->Hour = DecodeWithBCDAlphabet(req[3]);
144  DT->Minute = DecodeWithBCDAlphabet(req[4]);
145  DT->Second = DecodeWithBCDAlphabet(req[5]);
146 
147  /* Base for timezone is GMT. It's in quarters */
148  DT->Timezone=(10*(req[6]&0x07)+(req[6]>>4))*3600/4;
149 
150  if (req[6]&0x08) DT->Timezone = -DT->Timezone;
151 
152  smprintf(s, "Decoding date & time: ");
153  smprintf(s, "%s %4d/%02d/%02d ", DayOfWeek(DT->Year, DT->Month, DT->Day),
154  DT->Year, DT->Month, DT->Day);
155  smprintf(s, "%02d:%02d:%02d%+03i%02i\n", DT->Hour, DT->Minute, DT->Second,
156  DT->Timezone / 3600, abs((DT->Timezone % 3600) / 60));
157 
158  return ERR_NONE;
159 }
160 
161 GSM_Error GNAPGEN_PrivSetSMSLayout(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *buffer, GSM_SMSMessageLayout *Layout ) {
162  int position = 0;
163  /* setting sms layout */
164  *Layout = PHONE_SMSDeliver;
165  Layout->SMSCNumber = 0;
166 
167  /* the pdu type is always behind the smsc number */
168  if( (buffer[0] % 2) == 0 )
169  position = (buffer[0] / 2) + 1;
170  else
171  position = ((buffer[0] +1 ) / 2) + 1;
172 
173  position++;
174  Layout->firstbyte = position;
175 
176  /* determine whether the sms was received or sent */
177  switch( buffer[position] & 1 ) {
178  /* SMS-DELIVER (incoming message, received) */
179  case 0:
180  smprintf(s, "Message type: SMS-DELIVER\n");
181  sms->PDU = SMS_Deliver;
182 
183  position++;
184  Layout->Number = position;
185 
186  if( (buffer[position] % 2) == 0 )
187  position += (buffer[position] / 2) + 1;
188  else
189  position += ((buffer[position] + 1 ) / 2) + 1;
190 
191  position++;
192  Layout->TPPID = position;
193 
194  position++;
195  Layout->TPDCS = position;
196 
197  position++;
198  Layout->DateTime = position;
199  Layout->SMSCTime = position;
200 
201  position += 7;
202  Layout->TPUDL = position;
203 
204  position++;
205  Layout->Text = position;
206 
207  Layout->TPStatus = 255;
208  Layout->TPVP = 255;
209  Layout->TPMR = 255;
210 
211  break;
212 
213  /* SMS-SUBMIT (outgoing message, to be sent) */
214  case 1:
215  smprintf(s, "Message type: SMS-SUBMIT\n");
216  sms->PDU = SMS_Submit;
217 
218  position++;
219  Layout->TPMR = position;
220 
221  position++;
222  Layout->Number = position;
223 
224  if( (buffer[position] % 2) == 0 )
225  position += (buffer[position] / 2) + 1;
226  else
227  position += ((buffer[position] + 1 ) / 2) + 1;
228 
229  position++;
230  Layout->TPPID = position;
231 
232  position++;
233  Layout->TPDCS = position;
234 
235  position++;
236  /* the validity period field length depends on the VP flag set in the pdu-type */
237  if( buffer[position] & 0x16 ) {
238  /* VP is integer represented */
239  Layout->TPVP = position;
240  } else if ( buffer[position] & 0x08 ) {
241  position += 6;
242  Layout->TPVP = position;
243  /* VP is semi-octet represented */
244  }
245 
246  position++;
247  Layout->TPUDL = position;
248 
249  position++;
250  Layout->Text = position;
251 
252  Layout->TPStatus = 255;
253  Layout->DateTime = 255;
254  Layout->SMSCTime = 255;
255 
256  break;
257 
258  default:
259  smprintf(s, "Unknown message type: (PDU) %d\n", buffer[Layout->firstbyte] );
260  return ERR_UNKNOWN;
261  }
262 
263  return ERR_NONE;
264 }
265 
266 GSM_Error GNAPGEN_DecodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, size_t length, GSM_SMSMessageLayout *Layout)
267 {
268  GSM_DateTime zerodt = {0,0,0,0,0,0,0};
269  size_t pos;
270  GSM_Error error;
271 
272 #ifdef DEBUG
273  if (Layout->firstbyte == 255) {
274  smprintf(s, "ERROR: firstbyte in SMS layout not set\n");
275  return ERR_UNKNOWN;
276  }
277 
278  if (Layout->TPDCS != 255) smprintf(s, "TPDCS : %02x %i\n",buffer[Layout->TPDCS] ,buffer[Layout->TPDCS]);
279  if (Layout->TPMR != 255) smprintf(s, "TPMR : %02x %i\n",buffer[Layout->TPMR] ,buffer[Layout->TPMR]);
280  if (Layout->TPPID != 255) smprintf(s, "TPPID : %02x %i\n",buffer[Layout->TPPID] ,buffer[Layout->TPPID]);
281  if (Layout->TPUDL != 255) smprintf(s, "TPUDL : %02x %i\n",buffer[Layout->TPUDL] ,buffer[Layout->TPUDL]);
282  if (Layout->firstbyte != 255) smprintf(s, "FirstByte : %02x %i\n",buffer[Layout->firstbyte],buffer[Layout->firstbyte]);
283  if (Layout->Text != 255) smprintf(s, "Text : %02x %i\n",buffer[Layout->Text] ,buffer[Layout->Text]);
284 #endif
285 
286  SMS->UDH.Type = UDH_NoUDH;
287  SMS->Coding = SMS_Coding_8bit;
288  SMS->Length = 0;
289  SMS->SMSC.Location = 0;
290  SMS->SMSC.DefaultNumber[0] = 0;
291  SMS->SMSC.DefaultNumber[1] = 0;
292  SMS->SMSC.Number[0] = 0;
293  SMS->SMSC.Number[1] = 0;
294  SMS->SMSC.Name[0] = 0;
295  SMS->SMSC.Name[1] = 0;
297  SMS->SMSC.Format = SMS_FORMAT_Text;
298  SMS->Number[0] = 0;
299  SMS->Number[1] = 0;
300  SMS->OtherNumbersNum = 0;
301  SMS->Name[0] = 0;
302  SMS->Name[1] = 0;
303  SMS->ReplyViaSameSMSC = FALSE;
304  if (Layout->SMSCNumber!=255) {
305  pos = Layout->SMSCNumber;
306  error = GSM_UnpackSemiOctetNumber(&(s->di), SMS->SMSC.Number, buffer, &pos, length, TRUE);
307  if (error != ERR_NONE) {
308  return error;
309  }
310  smprintf(s, "SMS center number : \"%s\"\n",DecodeUnicodeString(SMS->SMSC.Number));
311  }
312  if ((buffer[Layout->firstbyte] & 0x80)!=0) SMS->ReplyViaSameSMSC=TRUE;
313 #ifdef DEBUG
314  if (SMS->ReplyViaSameSMSC) smprintf(s, "SMS centre set for reply\n");
315 #endif
316  if (Layout->Number!=255) {
317  pos = Layout->Number;
318  error = GSM_UnpackSemiOctetNumber(&(s->di), SMS->Number,buffer, &pos, length, TRUE);
319  if (error != ERR_NONE) {
320  return error;
321  }
322  smprintf(s, "Remote number : \"%s\"\n",DecodeUnicodeString(SMS->Number));
323  }
324  if (Layout->Text != 255 && Layout->TPDCS!=255 && Layout->TPUDL!=255) {
325  SMS->Coding = GSM_GetMessageCoding(&(s->di), buffer[Layout->TPDCS]);
326  GSM_DecodeSMSFrameText(&(s->di), SMS, buffer, *Layout);
327  }
328  if (Layout->DateTime != 255) {
329  GNAPGEN_DecodeSMSDateTime(s, &SMS->DateTime,buffer+(Layout->DateTime));
330  } else {
331  SMS->DateTime = zerodt;
332  }
333 
334 
335  if (Layout->SMSCTime != 255 && Layout->TPStatus != 255) {
336  /* GSM 03.40 section 9.2.3.11 (TP-Service-Centre-Time-Stamp) */
337  smprintf(s, "SMSC response date: ");
338  GNAPGEN_DecodeSMSDateTime(s, &SMS->SMSCTime, buffer+(Layout->SMSCTime));
339  GSM_DecodeSMSFrameStatusReportData(&(s->di), SMS,buffer,*Layout);
340  GNAPGEN_DecodeSMSDateTime(s, &SMS->DateTime, buffer+(Layout->SMSCTime));
341  } else {
342  SMS->SMSCTime = zerodt;
343  }
344  SMS->Class = -1;
345  if (Layout->TPDCS != 255) {
346  /* GSM 03.40 section 9.2.3.10 (TP-Data-Coding-Scheme) and GSM 03.38 section 4 */
347  if ((buffer[Layout->TPDCS] & 0xD0) == 0x10) {
348  /* bits 7..4 set to 00x1 */
349  if ((buffer[Layout->TPDCS] & 0xC) == 0xC) {
350  smprintf(s, "WARNING: reserved alphabet value in TPDCS\n");
351  } else {
352  SMS->Class = (buffer[Layout->TPDCS] & 3);
353  }
354  } else if ((buffer[Layout->TPDCS] & 0xF0) == 0xF0) {
355  /* bits 7..4 set to 1111 */
356  if ((buffer[Layout->TPDCS] & 8) == 8) {
357  smprintf(s, "WARNING: set reserved bit 3 in TPDCS\n");
358  } else {
359  SMS->Class = (buffer[Layout->TPDCS] & 3);
360  }
361  }
362  smprintf(s, "SMS class: %i\n",SMS->Class);
363  }
364 
365  SMS->MessageReference = 0;
366  if (Layout->TPMR != 255) SMS->MessageReference = buffer[Layout->TPMR];
367 
368  SMS->ReplaceMessage = 0;
369  if (Layout->TPPID != 255) {
370  if (buffer[Layout->TPPID] > 0x40 && buffer[Layout->TPPID] < 0x48) {
371  SMS->ReplaceMessage = buffer[Layout->TPPID] - 0x40;
372  }
373  }
374  SMS->RejectDuplicates = FALSE;
375  if ((buffer[Layout->firstbyte] & 0x04)==0x04) SMS->RejectDuplicates = TRUE;
376 
377  return ERR_NONE;
378 }
379 
380 static GSM_Error GNAPGEN_ReplyGetSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s) {
381  GSM_SMSMessage *sms = 0;
382  unsigned char buffer[800];
383  int numberOfMessages = 0;
384  int messageLen = 0;
385  int state = 0;
386  int i;
387  int current=6;
388  GSM_SMSMessageLayout layout;
389 
390  numberOfMessages = msg->Buffer[4] * 256 + msg->Buffer[5];
391  s->Phone.Data.GetSMSMessage->Number = numberOfMessages;
392 
393  switch( msg->Buffer[msg->Length-1] ) {
394  case 0x01:
395  state = SMS_Read;
396  break;
397  case 0x03:
398  state = SMS_UnRead;
399  break;
400  case 0x05:
401  state = SMS_Sent;
402  break;
403  case 0x07:
404  state = SMS_UnSent;
405  break;
406  }
407 
408  for( i=0; i<numberOfMessages; i++ ) {
409  messageLen = msg->Buffer[current] * 256 + msg->Buffer[current+1];
410  memset( buffer, 0, 800 );
411  memcpy( buffer, msg->Buffer + current + 2, messageLen );
412  current += messageLen + 2;
413  sms = &s->Phone.Data.GetSMSMessage->SMS[i];
414 
415  sms->State = state;
416  s->Phone.Data.GetSMSMessage->SMS[i].Name[0] = 0;
417  s->Phone.Data.GetSMSMessage->SMS[i].Name[1] = 0;
418 
419  GNAPGEN_PrivSetSMSLayout(s, sms, buffer, &layout );
420  GNAPGEN_DecodeSMSFrame(s, sms,buffer,messageLen,&layout);
421  }
422 
423  return ERR_NONE;
424 }
425 
426 static GSM_Error GNAPGEN_GetNextSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start)
427 {
428  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
429  GSM_Phone_Data *Data = &s->Phone.Data;
430 
431  /* @todo remove the folder attribute from the request header since it's not used on the phone */
432 
433  unsigned char req [8] = {0,11,
434  0x00,0x0c, /* folder */
435  0x00,0x10,0x00,0x3F}; /* location */
436  int i;
437  gboolean skipfolder;
438  GSM_Error error;
439 
440  if( start ) {
441  Priv->CurrentFolderNumber = 0;
442  Priv->CurrentSMSNumber = 0;
443  }
444 
445  /* retrieve the sms IDs for the given folder */
446  if( Priv->CurrentSMSNumber == 0 )
447  GNAPGEN_PrivGetSMSFolderStatus(s,Priv->SMSFolderID[Priv->CurrentFolderNumber]);
448 
449  for( i=0; i<5; i++ )
450  GSM_SetDefaultSMSData(&sms->SMS[i]);
451 
452  /* if there are no SMS in current folder, just skip it */
453  do {
454  if( Priv->SMSCount == 0 ) {
455  if( (Data->SMSFolders->Number - 1) == Priv->CurrentFolderNumber )
456  return ERR_EMPTY;
457  else {
458  Priv->CurrentSMSNumber = 0;
459  Priv->CurrentFolderNumber++;
460  }
461  GNAPGEN_PrivGetSMSFolderStatus(s,Priv->SMSFolderID[Priv->CurrentFolderNumber]);
462  skipfolder = TRUE;
463  } else
464  skipfolder = FALSE;
465  } while( skipfolder );
466 
467  /* set location */
468  req[4] = Priv->SMSIDs[Priv->CurrentSMSNumber].byte1;
469  req[5] = Priv->SMSIDs[Priv->CurrentSMSNumber].byte2;
470  req[6] = Priv->SMSIDs[Priv->CurrentSMSNumber].byte3;
471  req[7] = Priv->SMSIDs[Priv->CurrentSMSNumber].byte4;
472 
473  sms->SMS[0].Folder = Priv->SMSFolderID[Priv->CurrentFolderNumber];
474  if( Priv->CurrentFolderNumber == 0 )
475  sms->SMS[0].InboxFolder = TRUE;
476 
477  sms->SMS[0].Location = ( req[4] * (256*256*256) ) + req[5] * 256 * 256 + req[6] * 256 + req[7];
478 
479  sms->SMS[0].Memory = MEM_ME;
480 
481  s->Phone.Data.GetSMSMessage=sms;
482 
483  error = GSM_WaitFor(s, req, 8, 0x6, 500, ID_GetSMSMessage);
484  if( error != ERR_NONE )
485  return error;
486 
487  if( Priv->CurrentSMSNumber == ( Priv->SMSCount - 1 ) ) {
488  /* last sms in current folder reached, check if there are folders left to checkout */
489  if( Priv->CurrentFolderNumber == (Data->SMSFolders->Number - 1) )
490  return ERR_UNKNOWN;
491  else {
492  Priv->CurrentSMSNumber = 0;
493  Priv->CurrentFolderNumber++;
494  }
495  } else
496  Priv->CurrentSMSNumber++;
497 
498  return error;
499 }
500 
501 static GSM_Error GNAPGEN_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *req, GSM_SMSMessageLayout *Layout, int *length)
502 {
503  int count = 0;
504  GSM_Error error;
505 
506  memset(Layout,255,sizeof(GSM_SMSMessageLayout));
507 
508  sms->Class = -1;
509 
510  *Layout = PHONE_SMSSubmit;
511 
512  /* smsc number is semi-octet */
513  Layout->SMSCNumber = count;
514  smprintf(s, "SMSCNumber: %d\n", count );
515  if( UnicodeLength(sms->SMSC.Number) == 0 )
516  count += (UnicodeLength(sms->SMSC.Number) / 2) + 1;
517  else
518  count += ((UnicodeLength(sms->SMSC.Number) + 1 ) / 2) + 1;
519 
520  /* firstbyte set in SMS Layout */
521  Layout->firstbyte = count;
522  smprintf(s, "firstbyte: %d\n", count);
523  count++;
524 
525  if (sms->PDU != SMS_Deliver) {
526  Layout->TPMR = count;
527  smprintf(s, "TPMR: %d\n", Layout->TPMR);
528  count++;
529  }
530 
531  /* Phone number */
532  Layout->Number = count;
533  smprintf(s, "Number: %d\n", count);
534 
535  if( UnicodeLength(sms->Number) == 0 )
536  count += (UnicodeLength(sms->Number) / 2) + 1;
537  else
538  count += ((UnicodeLength(sms->Number) + 1 ) / 2) + 1;
539 
540 
541  Layout->TPPID = count;
542  smprintf(s, "TPPID: %d\n", count);
543  count++;
544 
545 
546  Layout->TPDCS = count;
547  smprintf(s, "TPDCS: %d\n", count);
548  count++;
549 
550  if (sms->PDU == SMS_Deliver) {
551  Layout->DateTime = count;
552  smprintf(s, "DateTime: %d\n", count);
553  count += 7;
554  } else {
555  Layout->TPVP = count;
556  smprintf(s, "TPVP: %d\n", count);
557  count++;
558  }
559 
560  Layout->TPUDL = count;
561  smprintf(s, "TPUDL: %d\n", count);
562  count++;
563 
564  Layout->Text = count;
565  smprintf(s, "Text: %d\n", count);
566 
567  error = PHONE_EncodeSMSFrame(s,sms,req,*Layout,length,FALSE);
568  if (error != ERR_NONE) return error;
569 
570 
571 
572 
573  req[0] = 0x0b;
574  req[10] = 0x07;
575 
576  return ERR_NONE;
577 }
578 
579 static GSM_Error GNAPGEN_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
580 {
581  int length = 11;
582  GSM_Error error;
583  GSM_SMSMessageLayout Layout;
584  unsigned char req [300] = {0,15};
585 
586  if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit;
587  memset(req+2,0x00,sizeof(req) - 2);
588  error=GNAPGEN_EncodeSMSFrame(s, sms, req + 2, &Layout, &length);
589  if (error != ERR_NONE) return error;
590  DumpMessage(&s->di, req, length+1);
591  /* return ERR_NONE; */
592  smprintf(s, "Sending sms\n");
593  return s->Protocol.Functions->WriteMessage(s, req, length + 2, 0x06);
594 }
595 
596 GSM_Error GNAPGEN_ReplySetSMS (GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s) {
597  /* @todo do something useful here ;) */
598  smprintf(s, "SetSMS: got reply\n");
599  return ERR_NONE;
600 }
601 
602 static GSM_Error GNAPGEN_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
603 {
604  int length = 0;
605  GSM_SMSMessageLayout Layout;
606  GSM_Error error;
607 
608 
609  unsigned char req [300] = {0,13,
610  0x00,0x0c, /* folder */
611  0x00,0x10,0x00,0x3F}; /* location */
612 
613 
614  req[3] = sms->Folder;
615 
616  /* @todo allow existing messages to be edited (not implemented in gnapplet) */
617 
618  if (sms->PDU == SMS_Deliver)
619  sms->PDU = SMS_Submit;
620 
621  memset(req+8,0x00,300-8);
622 
623  error = GNAPGEN_EncodeSMSFrame( s, sms, req + 10, &Layout, &length );
624  if (error != ERR_NONE) return error;
625  req[9] = length;
626 
627  s->Phone.Data.SaveSMSMessage=sms;
628  return GSM_WaitFor(s, req, length+10, 0x6, 4, ID_SaveSMSMessage);
629 }
630 
631 static GSM_Error GNAPGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
632 {
633 /* N6510_GetSMSLocation(s, sms, &folderid, &location); */
634 /* location = 0; */
635 /* N6510_SetSMSLocation(s, sms, folderid, location); */
636  return GNAPGEN_PrivSetSMSMessage(s, sms);
637 }
638 
639 /* ----------------------------------------------------------------------------- */
640 
641 static GSM_Error GNAPGEN_ReplyGetSignalQuality(GSM_Protocol_Message *msg, GSM_StateMachine *s)
642 {
643  GSM_Phone_Data *Data = &s->Phone.Data;
644 
645  smprintf(s, "Network level received: %i\n",msg->Buffer[4]);
646  Data->SignalQuality->SignalStrength = -1;
647  Data->SignalQuality->SignalPercent = ((int)msg->Buffer[4]);
648  Data->SignalQuality->BitErrorRate = -1;
649  return ERR_NONE;
650 }
651 
652 static GSM_Error GNAPGEN_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
653 {
654  unsigned char req[] = {0x00,0x03};
655 
656  s->Phone.Data.SignalQuality = sig;
657  smprintf(s, "Getting network level\n");
658  return GSM_WaitFor(s, req, 2, 0x03, 4, ID_GetSignalQuality);
659 }
660 
661 static GSM_Error GNAPGEN_ReplyGetBatteryCharge(GSM_Protocol_Message *msg, GSM_StateMachine *s)
662 {
663  GSM_Phone_Data *Data = &s->Phone.Data;
664 
665  smprintf(s, "Battery level received: %i\n",msg->Buffer[4]);
666  Data->BatteryCharge->BatteryPercent = ((int)(msg->Buffer[4]));
667  Data->BatteryCharge->ChargeState = 0;
668  return ERR_NONE;
669 }
670 
671 static GSM_Error GNAPGEN_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
672 {
673  unsigned char req[] = {0x00, 0x01};
674 
676  s->Phone.Data.BatteryCharge = bat;
677  smprintf(s, "Getting battery level\n");
678  return GSM_WaitFor(s, req, 2, 0x04, 4, ID_GetBatteryCharge);
679 }
680 
681 static GSM_Error GNAPGEN_ReplyGetNetworkInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
682 {
683  GSM_Phone_Data *Data = &s->Phone.Data;
684  char buf[100];
685 #ifdef DEBUG
686  GSM_NetworkInfo NetInfo;
687 
688  smprintf(s, "Network status : ");
689  switch (msg->Buffer[9]) {
690  case 0x00 : smprintf(s, "home network ?\n"); break;
691  default : smprintf(s, "unknown %i!\n",msg->Buffer[9]); break;
692  }
693  if (msg->Buffer[9]==0x00) {
694  sprintf(NetInfo.CID, "%02X%02X", msg->Buffer[4], msg->Buffer[5]);
695  smprintf(s, "CID : %s\n", NetInfo.CID);
696  sprintf(NetInfo.LAC, "%02X%02X", msg->Buffer[6], msg->Buffer[7]);
697  smprintf(s, "LAC : %s\n", NetInfo.LAC);
698 
699  memset(buf,0,sizeof(buf));
700  memcpy(buf,msg->Buffer+11,msg->Buffer[10]*2);
701  sprintf(NetInfo.NetworkCode,"%s",DecodeUnicodeString(buf));
702  smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
703  smprintf(s, "Network name for Gammu : %s ",
706  }
707 #endif
708  Data->NetworkInfo->NetworkName[0] = 0x00;
709  Data->NetworkInfo->NetworkName[1] = 0x00;
710  Data->NetworkInfo->State = 0;
711  switch (msg->Buffer[8]) {
712  case 0x00: Data->NetworkInfo->State = GSM_HomeNetwork; break;
713  }
714  if (Data->NetworkInfo->State == GSM_HomeNetwork) {
715  sprintf(Data->NetworkInfo->CID, "%02X%02X", msg->Buffer[4], msg->Buffer[5]);
716  sprintf(Data->NetworkInfo->LAC, "%02X%02X", msg->Buffer[6], msg->Buffer[7]);
717 
718  memset(buf,0,sizeof(buf));
719  memcpy(buf,msg->Buffer+11,msg->Buffer[10]*2);
720  sprintf(Data->NetworkInfo->NetworkCode,"%s",DecodeUnicodeString(buf));
721  }
722  return ERR_NONE;
723 }
724 
725 static GSM_Error GNAPGEN_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
726 {
727  unsigned char req[] = {0x00, 0x01};
728 
729  netinfo->GPRS = 0;
730  s->Phone.Data.NetworkInfo=netinfo;
731  smprintf(s, "Getting network info\n");
732  return GSM_WaitFor(s, req, 2, 0x03, 4, ID_GetNetworkInfo);
733 }
734 
735 static GSM_Error GNAPGEN_ReplyGetMemoryStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
736 {
737  GSM_Phone_Data *Data = &s->Phone.Data;
738 
739  smprintf(s, "Memory status received\n");
740  if (msg->Length == 4) return ERR_EMPTY;
741 
742  Data->MemoryStatus->MemoryUsed = msg->Buffer[8]*256 + msg->Buffer[9];
743  Data->MemoryStatus->MemoryFree = msg->Buffer[12]*256 + msg->Buffer[13];
744  smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree);
745  smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed);
746 
747  return ERR_NONE;
748 }
749 
750 static GSM_Error GNAPGEN_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
751 {
752  unsigned char req[] = {0x00,0x07,0x00,
753  0x00}; /* memory type */
754 
755  if (Status->MemoryType != MEM_ME) {
756  req[3] = NOKIA_GetMemoryType(s, Status->MemoryType,GNAPGEN_MEMORY_TYPES);
757  if (req[3]==0xff) return ERR_NOTSUPPORTED;
758  }
759 
760  s->Phone.Data.MemoryStatus=Status;
761  smprintf(s, "Getting memory status\n");
762  return GSM_WaitFor(s, req, 4, 0x02, 4, ID_GetMemoryStatus);
763 }
764 
765 GSM_Error GNAPGEN_ReplyGetNextMemory( GSM_Protocol_Message *msg, GSM_StateMachine *s ) {
766  int i,pos=8,type,subtype,len;
767  GSM_MemoryEntry *entry = s->Phone.Data.Memory;
768  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
769 
770  /* 17 == GN_ERR_INVALIDMEMORYTYPE */
771  if( msg->Buffer[3] == 17 ) {
772  smprintf(s, "unknown memory type\n");
773  return ERR_UNKNOWN;
774  }
775 
776  entry->Location=msg->Buffer[5];
777  entry->EntriesNum=0;
778 
779  for (i=0;i<msg->Buffer[7];i++) {
780  type = msg->Buffer[pos]*256+msg->Buffer[pos+1];
781  subtype = msg->Buffer[pos+2]*256+msg->Buffer[pos+3];
782  pos+=4;
783  switch (type) {
784  /* name */
785  case 0x07:
786  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
787  if (len!=0) {
788  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_Name;
790  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
791  entry->Entries[entry->EntriesNum].Text[len*2]=0;
792  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
793  entry->EntriesNum++;
794  }
795  pos+=2+len*2;
796  break;
797  /* email */
798  case 0x08:
799  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
802  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
803  entry->Entries[entry->EntriesNum].Text[len*2]=0;
804  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
805  entry->EntriesNum++;
806  pos+=2+len*2;
807  break;
808  /* 0x0b is a general identifier for a number */
809  case 0x0B:
810  switch(subtype) {
811  /* fax */
812  case 0x04:
815  break;
816  /* work */
817  case 0x06:
819  entry->Entries[entry->EntriesNum].Location = PBK_Location_Work;
820  break;
821  /* mobile */
822  case 0x03:
825  break;
826  /* home */
827  case 0x02:
829  entry->Entries[entry->EntriesNum].Location = PBK_Location_Home;
830  break;
831  /* general */
832  case 0x0a: default:
835  break;
836  }
837  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
838  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
839  entry->Entries[entry->EntriesNum].Text[len*2]=0;
840  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
841  entry->EntriesNum++;
842  pos+=2+len*2;
843  break;
844  /* date */
845  case 0x13:
846  entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
848  NOKIA_DecodeDateTime(s, msg->Buffer+pos, &entry->Entries[entry->EntriesNum].Date, TRUE, FALSE);
849  entry->EntriesNum++;
850  pos+=2+7;
851  break;
852  /* note */
853  case 0x0a:
854  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
855  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_Note;
857  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
858  entry->Entries[entry->EntriesNum].Text[len*2]=0;
859  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
860  entry->EntriesNum++;
861  pos+=2+len*2;
862  break;
863  /* url */
864  case 0x2c:
865  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
866  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_URL;
868  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
869  entry->Entries[entry->EntriesNum].Text[len*2]=0;
870  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
871  entry->EntriesNum++;
872  pos+=2+len*2;
873  break;
874  default:
875  Priv->LastContactArrived = TRUE;
876  return ERR_UNKNOWN;
877  }
878  }
879 
880  return ERR_NONE;
881 
882 }
883 
884 
885 static GSM_Error GNAPGEN_GetNextMemory( GSM_StateMachine *s, GSM_MemoryEntry *entry, gboolean start ) {
886  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
887 
888  unsigned char req[] = {0x00, 11,
889  0x00, 0x00, /* memory type */
890  0x00, 0x00}; /* start (gboolean) */
891 
892  if( start ) {
893  Priv->LastContactArrived = FALSE;
894  req[5] = 0x01;
895  } else
896  req[5] = 0x00;
897 
898  if( Priv->LastContactArrived )
899  return ERR_EMPTY;
900 
901  if (entry->MemoryType != MEM_ME) {
902  req[3] = NOKIA_GetMemoryType(s, entry->MemoryType,GNAPGEN_MEMORY_TYPES);
903  if (req[3]==0xff) return ERR_NOTSUPPORTED;
904  }
905 
906  s->Phone.Data.Memory=entry;
907  return GSM_WaitFor(s, req, 6, 0x02, 6, ID_GetMemory);
908 }
909 
910 static GSM_Error GNAPGEN_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
911 {
912  int i,pos=6,type,subtype,len;
913  GSM_MemoryEntry *entry = s->Phone.Data.Memory;
914 
915  entry->EntriesNum=0;
916 
917  smprintf(s, "Phonebook entry received\n");
918  for (i=0;i<msg->Buffer[5];i++) {
919  type = msg->Buffer[pos]*256+msg->Buffer[pos+1];
920  subtype = msg->Buffer[pos+2]*256+msg->Buffer[pos+3];
921  pos+=4;
922  switch (type) {
923  /* name */
924  case 0x07:
925  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
926  if (len!=0) {
927  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_Name;
929  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
930  entry->Entries[entry->EntriesNum].Text[len*2]=0;
931  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
932  entry->EntriesNum++;
933  }
934  pos+=2+len*2;
935  break;
936  /* email */
937  case 0x08:
938  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
941  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
942  entry->Entries[entry->EntriesNum].Text[len*2]=0;
943  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
944  entry->EntriesNum++;
945  pos+=2+len*2;
946  break;
947  /* 0x0b is a general identifier for a number */
948  case 0x0B:
949  switch(subtype) {
950  /* fax */
951  case 0x04:
954  break;
955  /* work */
956  case 0x06:
958  entry->Entries[entry->EntriesNum].Location = PBK_Location_Work;
959  break;
960  /* mobile */
961  case 0x03:
964  break;
965  /* home */
966  case 0x02:
968  entry->Entries[entry->EntriesNum].Location = PBK_Location_Home;
969  break;
970  /* general */
971  case 0x0a: default:
974  break;
975  }
976  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
977  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
978  entry->Entries[entry->EntriesNum].Text[len*2]=0;
979  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
980  entry->EntriesNum++;
981  pos+=2+len*2;
982  break;
983  /* date */
984  case 0x13:
985  entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
987  NOKIA_DecodeDateTime(s, msg->Buffer+pos, &entry->Entries[entry->EntriesNum].Date, TRUE, FALSE);
988  entry->EntriesNum++;
989  pos+=2+7;
990  break;
991  /* note */
992  case 0x0a:
993  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
994  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_Note;
996  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
997  entry->Entries[entry->EntriesNum].Text[len*2]=0;
998  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
999  entry->EntriesNum++;
1000  pos+=2+len*2;
1001  break;
1002  /* url */
1003  case 0x2c:
1004  len = msg->Buffer[pos]*256+msg->Buffer[pos+1];
1005  entry->Entries[entry->EntriesNum].EntryType=PBK_Text_URL;
1007  memcpy(entry->Entries[entry->EntriesNum].Text,msg->Buffer+pos+2,len*2);
1008  entry->Entries[entry->EntriesNum].Text[len*2]=0;
1009  entry->Entries[entry->EntriesNum].Text[len*2+1]=0;
1010  entry->EntriesNum++;
1011  pos+=2+len*2;
1012  break;
1013  default:
1014  smprintf(s, "unknown %i\n",type);
1015  return ERR_UNKNOWN;
1016  }
1017  }
1018 
1019  return ERR_NONE;
1020 }
1021 
1022 static GSM_Error GNAPGEN_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
1023 {
1024  unsigned char req[] = {0x00, 0x01,
1025  0x00, 0x00, /* memory type */
1026  0x00, 0x00, 0x00, 0x00}; /* location */
1027 
1028  if (entry->MemoryType != MEM_ME) {
1029  req[3] = NOKIA_GetMemoryType(s, entry->MemoryType,GNAPGEN_MEMORY_TYPES);
1030  if (req[3]==0xff) return ERR_NOTSUPPORTED;
1031  }
1032 
1033  if (entry->Location==0x00) return ERR_INVALIDLOCATION;
1034 
1035  req[6] = entry->Location / 256;
1036  req[7] = entry->Location % 256;
1037 
1038  s->Phone.Data.Memory=entry;
1039  smprintf(s, "Getting phonebook entry\n");
1040  return GSM_WaitFor(s, req, 8, 0x02, 6, ID_GetMemory);
1041 }
1042 
1043 static GSM_Error GNAPGEN_ReplySetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s) {
1044  smprintf(s, "Got reply: SetMemory()\n");
1045  if( msg->Buffer[4] == 0 )
1046  return ERR_NONE;
1047  else
1048  return ERR_UNKNOWN;
1049 }
1050 
1051 static GSM_Error GNAPGEN_SetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
1052 {
1053  unsigned char req[1000] = {0x00, 0x03,
1054  0x00, 0x00, /* memory type */
1055  0x00, 0x00, 0x00, 0x00, /* location */
1056  0x00, 0x00 }; /* number of entries to read */
1057  /* for each entry, 2 bytes are reserved for the entry type, */
1058  /* 2 bytes for the entry sub-type if available and 64 byte for the actual entry */
1059  int currentByte = 10;
1060  int i = 0;
1061  int entryCount = 0;
1062  GSM_SubMemoryEntry *subMemoryEntry;
1063 
1064  memset( req + 3,0x00,sizeof(req) - 3 );
1065 
1066  if (entry->MemoryType != MEM_ME) {
1067  req[3] = NOKIA_GetMemoryType(s, entry->MemoryType,GNAPGEN_MEMORY_TYPES);
1068  if (req[3]==0xff) return ERR_NOTSUPPORTED;
1069  }
1070 
1071  if (entry->Location==0x00) return ERR_INVALIDLOCATION;
1072 
1073  req[6] = entry->Location / 256;
1074  req[7] = entry->Location % 256;
1075 
1076  for( i=0; i< entry->EntriesNum; i++ ) {
1077  subMemoryEntry = &entry->Entries[i];
1078  switch( subMemoryEntry->EntryType ) {
1079  break;
1080 
1081  case PBK_Number_General:
1082  case PBK_Number_Mobile:
1083  if (subMemoryEntry->Location == PBK_Location_Home) {
1084  req[currentByte++] = 0x00;
1085  req[currentByte++] = 0x0b;
1086  req[currentByte++] = 0x00;
1087  req[currentByte++] = 0x02;
1088  } else if (subMemoryEntry->Location == PBK_Location_Home) {
1089  req[currentByte++] = 0x00;
1090  req[currentByte++] = 0x0b;
1091  req[currentByte++] = 0x00;
1092  req[currentByte++] = 0x06;
1093  } else {
1094  req[currentByte++] = 0x00;
1095  req[currentByte++] = 0x0b;
1096  req[currentByte++] = 0x00;
1097  req[currentByte++] = 0x03;
1098  }
1099  break;
1100 
1101  case PBK_Number_Fax:
1102  req[currentByte++] = 0x00;
1103  req[currentByte++] = 0x0b;
1104  req[currentByte++] = 0x00;
1105  req[currentByte++] = 0x04;
1106  break;
1107 
1108  case PBK_Text_Email:
1109  req[currentByte++] = 0x00;
1110  req[currentByte++] = 0x08;
1111  req[currentByte++] = 0x00;
1112  req[currentByte++] = 0x00;
1113  break;
1114 
1115  case PBK_Text_Name:
1116  req[currentByte++] = 0x00;
1117  req[currentByte++] = 0x07;
1118  req[currentByte++] = 0x00;
1119  req[currentByte++] = 0x00;
1120  break;
1121  default:
1122  continue;
1123  }
1124 
1125  entryCount++;
1126 
1127  req[currentByte++] = 0x00;
1128  req[currentByte++] = UnicodeLength( subMemoryEntry->Text );
1129 
1130  memcpy( req + currentByte, subMemoryEntry->Text, UnicodeLength( subMemoryEntry->Text ) * 2 );
1131  currentByte += UnicodeLength( subMemoryEntry->Text ) * 2;
1132  }
1133 
1134  req[9] = entryCount;
1135 
1136  return GSM_WaitFor(s, req, currentByte, 0x02, 4, ID_SetMemory);
1137 }
1138 
1139 GSM_Error GNAPGEN_ReplyDeleteMemory ( GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s ) {
1140  /* @todo implement error handling */
1141  smprintf(s, "Deleted\n");
1142  return ERR_NONE;
1143 }
1144 
1145 static GSM_Error GNAPGEN_DeleteMemory ( GSM_StateMachine *s, GSM_MemoryEntry *entry ) {
1146  unsigned char req[] = {0x00, 0x05,
1147  0x00, 0x00, /* memory type */
1148  0x00, 0x00, 0x00, 0x00 }; /* location */
1149 
1150  if (entry->MemoryType != MEM_ME) {
1151  req[3] = NOKIA_GetMemoryType(s, entry->MemoryType,GNAPGEN_MEMORY_TYPES);
1152  if (req[3]==0xff) return ERR_NOTSUPPORTED;
1153  }
1154 
1155  if (entry->Location==0x00) return ERR_INVALIDLOCATION;
1156 
1157  req[6] = entry->Location / 256;
1158  req[7] = entry->Location % 256;
1159 
1160  return GSM_WaitFor(s, req, 8, 0x02, 6, ID_DeleteMemory);
1161 }
1162 
1163 static GSM_Error GNAPGEN_AddMemory ( GSM_StateMachine *s, GSM_MemoryEntry *entry ) {
1164  entry->Location = -1;
1165  return GNAPGEN_SetMemory( s, entry );
1166 }
1167 
1168 static GSM_Error GNAPGEN_ReplyDeleteSMSMessage ( GSM_Protocol_Message *msg, GSM_StateMachine *s ) {
1169  /* 17 == GN_ERR_INVALIDMEMORYTYPE */
1170  switch( msg->Buffer[3] ) {
1171  case 16:
1172  smprintf(s, "invalid location\n");
1173  return ERR_UNKNOWN;
1174  case 17:
1175  smprintf(s, "unknown memory type\n");
1176  return ERR_UNKNOWN;
1177  case 0:
1178  smprintf(s, "deleted");
1179  }
1180 
1181 
1182  return ERR_NONE;
1183 }
1184 
1185 static GSM_Error GNAPGEN_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) {
1186  unsigned char req[] = {0x00, 17,
1187  0x00, 0x00, /* folder */
1188  0x00, 0x00, 0x00, 0x00 }; /* location */
1189 
1190  req[3] = sms->Folder;
1191 
1192  req[4] = (sms->Location / (256*256*256)) % 256;
1193  req[5] = (sms->Location / (256*256)) % 256;
1194  req[6] = (sms->Location / 256) % 256 ;
1195  req[7] = sms->Location % 256;
1196 
1197  return GSM_WaitFor(s, req, 8, 0x06, 6, ID_DeleteSMSMessage );
1198 }
1199 
1200 GSM_Error GNAPGEN_ReplyGetToDo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1201 {
1202  GSM_ToDoEntry *Last = s->Phone.Data.ToDo;
1203  int pos = 8;
1204 
1205  smprintf(s, "TODO received\n");
1206 
1207  memcpy(Last->Entries[0].Text,msg->Buffer+pos+2,(msg->Buffer[pos]*256+msg->Buffer[pos+1])*2);
1208  Last->Entries[0].Text[(msg->Buffer[pos]*256+msg->Buffer[pos+1])*2] = 0;
1209  Last->Entries[0].Text[(msg->Buffer[pos]*256+msg->Buffer[pos+1])*2+1] = 0;
1210  smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text));
1211  pos+=(msg->Buffer[pos]*256+msg->Buffer[pos+1])*2+2;
1212 
1216  Last->Type = GSM_CAL_MEMO;
1217 
1218  switch (msg->Buffer[pos]) {
1219  case 1 : Last->Priority = GSM_Priority_High; break;
1220  case 2 : Last->Priority = GSM_Priority_Medium; break;
1221  case 3 : Last->Priority = GSM_Priority_Low; break;
1222  default : return ERR_UNKNOWN;
1223  }
1224  smprintf(s, "Priority: %i\n",msg->Buffer[4]);
1225 
1226  Last->Entries[0].EntryType = TODO_TEXT;
1227  Last->EntriesNum = 1;
1228 
1229  return ERR_NONE;
1230 }
1231 
1232 static GSM_Error GNAPGEN_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, gboolean refresh)
1233 {
1234  GSM_Error error;
1235  unsigned char req[] = {0x00, 0x07,
1236  0x00, 0x00, 0x00, 0x00}; /* Location */
1237 
1238  if (refresh) {
1239  ToDo->Location = 1;
1240  } else {
1241  ToDo->Location++;
1242  }
1243 
1244  req[4] = ToDo->Location / 256;
1245  req[5] = ToDo->Location % 256;
1246 
1247  s->Phone.Data.ToDo = ToDo;
1248  smprintf(s, "Getting todo\n");
1249  error = GSM_WaitFor(s, req, 6, 7, 4, ID_GetToDo);
1250  if (error == ERR_INVALIDLOCATION) error = ERR_EMPTY;
1251  return error;
1252 }
1253 
1254 GSM_Error GNAPGEN_DeleteCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
1255 {
1256  unsigned char req[] = {0x00, 0x05,
1257  0x00, 0x00, 0x00, 0x00}; /* Location */
1258 
1259  req[4] = Note->Location / 256;
1260  req[5] = Note->Location % 256;
1261 
1262  smprintf(s, "Deleting calendar note\n");
1263  return GSM_WaitFor(s, req, 6, 7, 4, ID_DeleteCalendarNote);
1264 }
1265 
1266 GSM_Error GNAPGEN_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
1267 {
1268  GSM_DateTime DT;
1269  int Text, Time, Alarm, Phone, EndTime, Location, current=7;
1270  unsigned char req[5000] = {
1271  0x00, 0x03,0x00,0x00,
1272  0x00, 0x00, 0x00, 0x00, /* location ? */
1273  0x00}; /* type */
1274 
1275  switch(Note->Type) {
1276  case GSM_CAL_MEETING : req[6] = 0x01; break;
1277  case GSM_CAL_REMINDER : req[6] = 0x04; break;
1278  case GSM_CAL_MEMO :
1279  default : req[6] = 0x08; break;
1280  }
1281 
1282  GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
1283 
1284  if (Time == -1) return ERR_UNKNOWN;
1285  memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
1286  req[current++] = DT.Year / 256;
1287  req[current++] = DT.Year % 256;
1288  req[current++] = DT.Month;
1289  req[current++] = DT.Day;
1290  req[current++] = DT.Hour;
1291  req[current++] = DT.Minute;
1292  req[current++] = DT.Second;
1293 
1294  if (EndTime == -1) {
1295  memset(&DT,0,sizeof(GSM_DateTime));
1296  DT.Month = 1;
1297  DT.Day = 1;
1298 
1299  } else {
1300  memcpy(&DT,&Note->Entries[EndTime].Date,sizeof(GSM_DateTime));
1301  }
1302  req[current++] = DT.Year / 256;
1303  req[current++] = DT.Year % 256;
1304  req[current++] = DT.Month;
1305  req[current++] = DT.Day;
1306  req[current++] = DT.Hour;
1307  req[current++] = DT.Minute;
1308  req[current++] = DT.Second;
1309 
1310  if (Alarm == -1) {
1311  memset(&DT,0,sizeof(GSM_DateTime));
1312  DT.Month = 1;
1313  DT.Day = 1;
1314  } else {
1315  memcpy(&DT,&Note->Entries[Alarm].Date,sizeof(GSM_DateTime));
1316  }
1317  req[current++] = DT.Year / 256;
1318  req[current++] = DT.Year % 256;
1319  req[current++] = DT.Month;
1320  req[current++] = DT.Day;
1321  req[current++] = DT.Hour;
1322  req[current++] = DT.Minute;
1323  req[current++] = DT.Second;
1324 
1325  if (Text == -1) return ERR_UNKNOWN;
1326  req[current++] = UnicodeLength(Note->Entries[Text].Text) / 256;
1327  req[current++] = UnicodeLength(Note->Entries[Text].Text) % 256;
1328  memcpy(req+current,Note->Entries[Text].Text,UnicodeLength(Note->Entries[Text].Text)*2);
1329  current+=UnicodeLength(Note->Entries[Text].Text)*2;
1330 
1331  req[current++] = 0;
1332  req[current++] = 0;
1333 
1334  if (Location==-1) {
1335  req[current++] = 0;
1336  req[current++] = 0;
1337  } else {
1338  req[current++] = UnicodeLength(Note->Entries[Location].Text) / 256;
1339  req[current++] = UnicodeLength(Note->Entries[Location].Text) % 256;
1340  memcpy(req+current,Note->Entries[Location].Text,UnicodeLength(Note->Entries[Location].Text)*2);
1341  current+=UnicodeLength(Note->Entries[Location].Text)*2;
1342  }
1343 
1344  if (Note->Type == GSM_CAL_MEETING) {
1345  GSM_GetCalendarRecurranceRepeat(&(s->di), req+current, NULL, Note);
1346  current+=2;
1347  } else {
1348  req[current++] = 0xff;
1349  req[current++] = 0xff;
1350  }
1351 
1352  smprintf(s, "Writing calendar note\n");
1353  return GSM_WaitFor(s, req, current, 7, 4, ID_SetCalendarNote);
1354 }
1355 
1356 static GSM_Error GNAPGEN_ReplyGetNextCalendar(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1357 {
1358  int pos;
1359  GSM_CalendarEntry *Entry = s->Phone.Data.Cal;
1360 
1361  switch (msg->Buffer[3]) {
1362  case 0x00:
1363  smprintf(s, "Calendar note received\n");
1364  switch (msg->Buffer[8]) {
1365  case 0x01: Entry->Type = GSM_CAL_MEETING; break;
1366  case 0x04: Entry->Type = GSM_CAL_REMINDER; break;
1367  case 0x08: Entry->Type = GSM_CAL_MEMO; break;
1368  default :
1369  smprintf(s, "Unknown note type %i\n",msg->Buffer[8]);
1370  return ERR_UNKNOWNRESPONSE;
1371  }
1372 
1373  pos = 9;
1374  Entry->EntriesNum = 0;
1375 
1376  NOKIA_DecodeDateTime(s, msg->Buffer+pos, &Entry->Entries[Entry->EntriesNum].Date, TRUE, FALSE);
1377  smprintf(s, "Time : %02i-%02i-%04i %02i:%02i:%02i\n",
1378  Entry->Entries[Entry->EntriesNum].Date.Day,Entry->Entries[Entry->EntriesNum].Date.Month,Entry->Entries[Entry->EntriesNum].Date.Year,
1379  Entry->Entries[Entry->EntriesNum].Date.Hour,Entry->Entries[Entry->EntriesNum].Date.Minute,Entry->Entries[Entry->EntriesNum].Date.Second);
1381  Entry->EntriesNum++;
1382  pos+=7;
1383 
1384  NOKIA_DecodeDateTime(s, msg->Buffer+pos, &Entry->Entries[Entry->EntriesNum].Date, TRUE, FALSE);
1385  smprintf(s, "Time : %02i-%02i-%04i %02i:%02i:%02i\n",
1386  Entry->Entries[Entry->EntriesNum].Date.Day,Entry->Entries[Entry->EntriesNum].Date.Month,Entry->Entries[Entry->EntriesNum].Date.Year,
1387  Entry->Entries[Entry->EntriesNum].Date.Hour,Entry->Entries[Entry->EntriesNum].Date.Minute,Entry->Entries[Entry->EntriesNum].Date.Second);
1388  Entry->Entries[Entry->EntriesNum].EntryType = CAL_END_DATETIME;
1389  Entry->EntriesNum++;
1390  pos+=7;
1391 
1392  NOKIA_DecodeDateTime(s, msg->Buffer+pos, &Entry->Entries[Entry->EntriesNum].Date, TRUE, FALSE);
1393  if (Entry->Entries[Entry->EntriesNum].Date.Year!=0) {
1394  smprintf(s, "Alarm : %02i-%02i-%04i %02i:%02i:%02i\n",
1395  Entry->Entries[Entry->EntriesNum].Date.Day,Entry->Entries[Entry->EntriesNum].Date.Month,Entry->Entries[Entry->EntriesNum].Date.Year,
1396  Entry->Entries[Entry->EntriesNum].Date.Hour,Entry->Entries[Entry->EntriesNum].Date.Minute,Entry->Entries[Entry->EntriesNum].Date.Second);
1398  Entry->EntriesNum++;
1399  } else {
1400  smprintf(s, "No alarm\n");
1401  }
1402  pos+=7;
1403 
1404  memcpy(Entry->Entries[Entry->EntriesNum].Text,msg->Buffer+pos+2,msg->Buffer[pos+1]*2);
1405  Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[pos+1]*2 ]=0;
1406  Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[pos+1]*2+1]=0;
1407  smprintf(s, "Text \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
1408  if (msg->Buffer[pos+1] != 0x00) {
1409  Entry->Entries[Entry->EntriesNum].EntryType = CAL_TEXT;
1410  Entry->EntriesNum++;
1411  }
1412  pos+=msg->Buffer[pos+1]*2+4;
1413 
1414  memcpy(Entry->Entries[Entry->EntriesNum].Text,msg->Buffer+pos+2,msg->Buffer[pos+1]*2);
1415  Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[pos+1]*2 ]=0;
1416  Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[pos+1]*2+1]=0;
1417  smprintf(s, "Text \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
1418  if (msg->Buffer[pos+1] != 0x00) {
1419  Entry->Entries[Entry->EntriesNum].EntryType = CAL_LOCATION;
1420  Entry->EntriesNum++;
1421  }
1422  pos+=msg->Buffer[pos+1]*2+2;
1423 
1424  if (Entry->Type == GSM_CAL_MEETING) {
1425  GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+pos, NULL, Entry);
1426  }
1427 
1428  return ERR_NONE;
1429  case 0x10:
1430  smprintf(s, "Can't get calendar note - too high location?\n");
1431  return ERR_INVALIDLOCATION;
1432  }
1433  return ERR_UNKNOWNRESPONSE;
1434 }
1435 
1436 static GSM_Error GNAPGEN_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start)
1437 {
1438  GSM_Error error;
1439  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
1440  unsigned char req[] = {0x00, 0x01,
1441  0x00, 0x00, 0x00, 0x00}; /* Location */
1442 
1443  if (start) {
1444  Priv->LastCalendarPos = 1;
1445  } else {
1446  Priv->LastCalendarPos++;
1447  }
1448 
1449  Note->Location = Priv->LastCalendarPos;
1450  req[4] = Priv->LastCalendarPos / 256;
1451  req[5] = Priv->LastCalendarPos % 256;
1452 
1453  s->Phone.Data.Cal=Note;
1454  smprintf(s, "Getting calendar note\n");
1455  error = GSM_WaitFor(s, req, 6, 7, 4, ID_GetCalendarNote);
1456  if (error == ERR_INVALIDLOCATION) error = ERR_EMPTY;
1457  return error;
1458 }
1459 
1460 static GSM_Error GNAPGEN_ReplyGetSMSStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1461 {
1462  GSM_Phone_Data *Data = &s->Phone.Data;
1463 
1464  smprintf(s, "Used in phone memory : %i\n",msg->Buffer[6]*256+msg->Buffer[7]);
1465  smprintf(s, "Unread in phone memory : %i\n",msg->Buffer[10]*256+msg->Buffer[11]);
1466  Data->SMSStatus->PhoneSize = 0xff*256+0xff;
1467  Data->SMSStatus->PhoneUsed = msg->Buffer[6]*256+msg->Buffer[7];
1468  Data->SMSStatus->PhoneUnRead = msg->Buffer[10]*256+msg->Buffer[11];
1469  Data->SMSStatus->TemplatesUsed = 0;
1470  return ERR_NONE;
1471 }
1472 
1473 static GSM_Error GNAPGEN_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
1474 {
1475  unsigned char req[] = {0x00, 0x09};
1476 
1477  s->Phone.Data.SMSStatus=status;
1478  smprintf(s, "Getting SMS status\n");
1479  return GSM_WaitFor(s, req, 2, 0x6, 2, ID_GetSMSStatus);
1480 }
1481 
1482 static GSM_Error GNAPGEN_ReplyGetSMSFolders(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1483 {
1484  int j, pos;
1485  GSM_Phone_Data *Data = &s->Phone.Data;
1486  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
1487 
1488  smprintf(s, "SMS folders names received\n");
1489  Data->SMSFolders->Number = msg->Buffer[5];
1490 
1491  pos = 6;
1492  for (j=0;j<msg->Buffer[5];j++) {
1493  if (msg->Buffer[pos+3]>GSM_MAX_SMS_FOLDER_NAME_LEN) {
1494  smprintf(s, "Too long text\n");
1495  return ERR_UNKNOWNRESPONSE;
1496  }
1497  Priv->SMSFolderID[j] = msg->Buffer[pos+1];
1498 
1499  memcpy(Data->SMSFolders->Folder[j].Name,msg->Buffer + pos+4,msg->Buffer[pos+3]*2);
1500  Data->SMSFolders->Folder[j].Name[msg->Buffer[pos+3]*2]=0;
1501  Data->SMSFolders->Folder[j].Name[msg->Buffer[pos+3]*2+1]=0;
1502  smprintf(s, "id: %d, folder name: \"%s\"\n",msg->Buffer[pos+1], DecodeUnicodeString(Data->SMSFolders->Folder[j].Name));
1503 
1504  if( msg->Buffer[pos+1] == 12 )
1505  Data->SMSFolders->Folder[j].InboxFolder = TRUE;
1506  else
1507  Data->SMSFolders->Folder[j].InboxFolder = FALSE;
1508  Data->SMSFolders->Folder[j].OutboxFolder = FALSE;
1512  Data->SMSFolders->Folder[j].Memory = MEM_ME;
1513  pos+=msg->Buffer[pos+3]*2+4;
1514  }
1515  return ERR_NONE;
1516 }
1517 
1518 static GSM_Error GNAPGEN_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
1519 {
1520  unsigned char req[] = {0x00,0x01};
1521 
1522  s->Phone.Data.SMSFolders=folders;
1523  smprintf(s, "Getting SMS folders\n");
1524  return GSM_WaitFor(s, req, 2, 0x06, 4, ID_GetSMSFolders);
1525 }
1526 
1527 static GSM_Error GNAPGEN_ReplyGetSMSC(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1528 {
1529  int pos=7;
1530  GSM_Phone_Data *Data = &s->Phone.Data;
1531 
1532  if (msg->Buffer[7]*2>GSM_MAX_SMSC_NAME_LENGTH) {
1533  smprintf(s, "Too long name\n");
1534  return ERR_UNKNOWNRESPONSE;
1535  }
1536  memcpy(Data->SMSC->Name,msg->Buffer+8,msg->Buffer[7]*2);
1537  Data->SMSC->Name[msg->Buffer[7]*2] = 0;
1538  Data->SMSC->Name[msg->Buffer[7]*2+1] = 0;
1539  smprintf(s, " Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
1540  pos+=msg->Buffer[7]*2;
1541 
1542  pos+=4;
1543 
1544  Data->SMSC->Format = SMS_FORMAT_Text;
1547 
1548  Data->SMSC->DefaultNumber[0] = 0;
1549  Data->SMSC->DefaultNumber[1] = 0;
1550 
1551  memcpy(Data->SMSC->Number,msg->Buffer+pos+4,msg->Buffer[pos+3]*2);
1552  Data->SMSC->Number[msg->Buffer[pos+3]*2] = 0;
1553  Data->SMSC->Number[msg->Buffer[pos+3]*2+1] = 0;
1554  smprintf(s, " Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
1555 
1556  return ERR_NONE;
1557 }
1558 
1559 static GSM_Error GNAPGEN_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
1560 {
1561  unsigned char req[] = {0x00,21,
1562  0x00,0x01}; /* location */
1563 
1564  if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
1565 
1566  req[3]=smsc->Location-1;
1567 
1568  s->Phone.Data.SMSC=smsc;
1569  smprintf(s, "Getting SMSC\n");
1570  return GSM_WaitFor(s, req, 4, 0x06, 4, ID_GetSMSC);
1571 }
1572 
1573 static GSM_Error GNAPGEN_ReplyGetAlarm(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1574 {
1575  GSM_Phone_Data *Data = &s->Phone.Data;
1576 
1577  smprintf(s, "Alarm received\n");
1578  if (msg->Buffer[4] == 0x00) return ERR_EMPTY;
1579  Data->Alarm->Repeating = FALSE;
1580  Data->Alarm->Text[0] = 0;
1581  Data->Alarm->Text[1] = 0;
1582  NOKIA_DecodeDateTime(s, msg->Buffer+5, &Data->Alarm->DateTime, TRUE, FALSE);
1583  return ERR_NONE;
1584 }
1585 
1586 static GSM_Error GNAPGEN_GetAlarm(GSM_StateMachine *s, GSM_Alarm *timedelta)
1587 {
1588  unsigned char req[] = {0x00, 0x05};
1589 
1590  if (timedelta->Location != 1) return ERR_NOTSUPPORTED;
1591 
1592  s->Phone.Data.Alarm=timedelta;
1593  smprintf(s, "Getting alarm\n");
1594  return GSM_WaitFor(s, req, 2, 0x8, 4, ID_GetAlarm);
1595 }
1596 
1597 static GSM_Error GNAPGEN_ReplyGetDateTime(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1598 {
1599  smprintf(s, "Date & time received\n");
1601  return ERR_NONE;
1602 }
1603 
1604 static GSM_Error GNAPGEN_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1605 {
1606  unsigned char req[2] = {0x00,0x01};
1607 
1608  s->Phone.Data.DateTime=date_time;
1609  smprintf(s, "Getting date & time\n");
1610  return GSM_WaitFor(s, req, 2, 0x08, 4, ID_GetDateTime);
1611 }
1612 
1613 GSM_Error GNAPGEN_ReplyDialVoice( GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s ) {
1614  smprintf(s, "Dialed voice number\n");
1615  return ERR_NONE;
1616 }
1617 
1618 static GSM_Error GNAPGEN_DialVoice ( GSM_StateMachine *s, char *Number, GSM_CallShowNumber ShowNumber UNUSED) {
1619  /* @todo implement ShowNumber */
1620  unsigned char req[100] = {0x00,0x09};
1621 
1622  int currentByte = 2;
1623 
1624  unsigned char unicodeNumber[200];
1625 
1626  memset( req + 2,0x00,sizeof(req) - 2 );
1627 
1628  EncodeUnicode( unicodeNumber, Number, strlen(Number) );
1629 
1630  req[currentByte++] = 0x00;
1631  req[currentByte++] = UnicodeLength( unicodeNumber );
1632 
1633  memcpy( req + currentByte, unicodeNumber, UnicodeLength( unicodeNumber ) * 2 );
1634  currentByte += UnicodeLength( unicodeNumber ) * 2;
1635 
1636  return GSM_WaitFor(s, req, currentByte, 0x02, 8, ID_DialVoice);
1637 }
1638 
1639 GSM_Error GNAPGEN_ReplyGetHW(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1640 {
1641  unsigned char buff[200];
1642  int pos=8,len,i;
1643 
1644  for (i=0;i<5;i++) {
1645  len=msg->Buffer[pos]*256+msg->Buffer[pos+1];
1646  memset(buff,0,sizeof(buff));
1647  memcpy(buff,msg->Buffer+pos+2,len*2);
1648  pos+=2+len*2;
1649  }
1650 
1651  strcpy(s->Phone.Data.HardwareCache,DecodeUnicodeString(buff));
1652  smprintf(s, "Received HW %s\n",s->Phone.Data.HardwareCache);
1653 
1654  return ERR_NONE;
1655 }
1656 
1657 GSM_Error GNAPGEN_GetHW(GSM_StateMachine *s, char *value)
1658 {
1659  GSM_Error error;
1660  unsigned char req[2] = {0x00,0x01};
1661 
1662  if (strlen(s->Phone.Data.HardwareCache)!=0) {
1663  strcpy(value,s->Phone.Data.HardwareCache);
1664  return ERR_NONE;
1665  }
1666 
1667  smprintf(s, "Getting HW\n");
1668  error = GSM_WaitFor(s, req, 2, 0x01, 2, ID_GetHardware);
1669  if (error == ERR_NONE) strcpy(value,s->Phone.Data.HardwareCache);
1670  return error;
1671 }
1672 
1673 GSM_Error GNAPGEN_ReplyGetManufacturer(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1674 {
1675  unsigned char buff[200];
1676  int pos=8,len;
1677  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
1678 
1679  smprintf(s, "gnapplet %i. %i\n",msg->Buffer[4]*256+msg->Buffer[5],msg->Buffer[6]*256+msg->Buffer[7]);
1680  Priv->GNAPPLETVer = msg->Buffer[4]*256+msg->Buffer[5] * 100 + msg->Buffer[6]*256+msg->Buffer[7];
1681 
1682  len=msg->Buffer[pos]*256+msg->Buffer[pos+1];
1683  memset(buff,0,sizeof(buff));
1684  memcpy(buff,msg->Buffer+pos+2,len*2);
1685 
1686  strcpy(s->Phone.Data.Manufacturer,DecodeUnicodeString(buff));
1687 
1688  return ERR_NONE;
1689 }
1690 
1691 GSM_Error GNAPGEN_GetManufacturer(GSM_StateMachine *s)
1692 {
1693  unsigned char req[2] = {0x00,0x01};
1694 
1695  smprintf(s, "Getting manufacturer\n");
1696  return GSM_WaitFor(s, req, 2, 0x01, 2, ID_GetManufacturer);
1697 }
1698 
1699 GSM_Error GNAPGEN_ReplyGetIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1700 {
1701  unsigned char buff[200];
1702  int pos=8,len,i;
1703 
1704  for (i=0;i<3;i++) {
1705  len=msg->Buffer[pos]*256+msg->Buffer[pos+1];
1706  memset(buff,0,sizeof(buff));
1707  memcpy(buff,msg->Buffer+pos+2,len*2);
1708  pos+=2+len*2;
1709  }
1710 
1711  strcpy(s->Phone.Data.IMEI,DecodeUnicodeString(buff));
1712  smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
1713 
1714  return ERR_NONE;
1715 }
1716 
1717 GSM_Error GNAPGEN_GetIMEI(GSM_StateMachine *s)
1718 {
1719  unsigned char req[2] = {0x00,0x01};
1720 
1721  smprintf(s, "Getting IMEI\n");
1722  return GSM_WaitFor(s, req, 2, 0x01, 2, ID_GetIMEI);
1723 }
1724 
1725 GSM_Error GNAPGEN_ReplyGetID(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s UNUSED)
1726 {
1727  return ERR_NONE;
1728 }
1729 
1730 GSM_Error GNAPGEN_ReplyGetModelFirmware(GSM_Protocol_Message *msg, GSM_StateMachine *s)
1731 {
1732  GSM_CutLines lines;
1733  GSM_Phone_Data *Data = &s->Phone.Data;
1734 
1735  if (Data->RequestID!=ID_GetManufacturer && Data->RequestID!=ID_GetModel) return ERR_NONE;
1736 
1737  InitLines(&lines);
1738  SplitLines(DecodeUnicodeString(msg->Buffer+6), msg->Length-6, &lines, "\x0A", 1, "", 0, FALSE);
1739 
1740  strcpy(Data->Model,GetLineString(DecodeUnicodeString(msg->Buffer+6), &lines, 4));
1741  smprintf(s, "Received model %s\n",Data->Model);
1742  Data->ModelInfo = GetModelData(s, NULL, Data->Model, NULL);
1743 
1744  strcpy(Data->VerDate,GetLineString(DecodeUnicodeString(msg->Buffer+6), &lines, 3));
1745  smprintf(s, "Received firmware date %s\n",Data->VerDate);
1746 
1747  strcpy(Data->Version,GetLineString(DecodeUnicodeString(msg->Buffer+6), &lines, 2));
1748  smprintf(s, "Received firmware version %s\n",Data->Version);
1750 
1751  FreeLines(&lines);
1752 
1753  return ERR_NONE;
1754 }
1755 
1756 GSM_Error GNAPGEN_GetModel (GSM_StateMachine *s)
1757 {
1758  unsigned char req[2] = {0x00,0x01};
1759  GSM_Error error;
1760 
1761  if (strlen(s->Phone.Data.Model)>0) return ERR_NONE;
1762 
1763  smprintf(s, "Getting model\n");
1764  error = GSM_WaitFor(s, req, 2, 0x01, 2, ID_GetModel);
1765  if (error == ERR_NONE) {
1766  smprintf_level(s, D_TEXT, "[Connected model - \"%s\"]\n",
1767  s->Phone.Data.Model);
1768  }
1769  return error;
1770 }
1771 
1772 GSM_Error GNAPGEN_GetFirmware (GSM_StateMachine *s)
1773 {
1774  unsigned char req[2] = {0x00,0x01};
1775  GSM_Error error;
1776 
1777  if (strlen(s->Phone.Data.Version)>0) return ERR_NONE;
1778 
1779  smprintf(s, "Getting firmware version\n");
1780  error = GSM_WaitFor(s, req, 2, 0x01, 2, ID_GetFirmware);
1781  if (error==ERR_NONE) {
1782  smprintf_level(s, D_TEXT, "[Firmware version - \"%s\"]\n",
1783  s->Phone.Data.Version);
1784  smprintf_level(s, D_TEXT, "[Firmware date - \"%s\"]\n",
1785  s->Phone.Data.VerDate);
1786  }
1787  return error;
1788 }
1789 
1790 static GSM_Error GNAPGEN_Initialise (GSM_StateMachine *s)
1791 {
1792  GSM_Phone_GNAPGENData *Priv = &s->Phone.Data.Priv.GNAPGEN;
1793  GSM_Error error;
1794 
1795  error = GNAPGEN_GetManufacturer(s);
1796  if (error != ERR_NONE) return error;
1797 
1798  if (Priv->GNAPPLETVer == 18) return ERR_NONE;
1799  return ERR_GNAPPLETWRONG;
1800 }
1801 
1802 static GSM_Reply_Function GNAPGENReplyFunctions[] = {
1803  /* informations */
1804  {GNAPGEN_ReplyGetIMEI, "\x01",0x01,0x02,ID_GetIMEI },
1805  {GNAPGEN_ReplyGetHW, "\x01",0x01,0x02,ID_GetHardware },
1806  {GNAPGEN_ReplyGetManufacturer, "\x01",0x01,0x02,ID_GetManufacturer },
1807  {GNAPGEN_ReplyGetID, "\x01",0x01,0x02,ID_GetModel },
1808  {GNAPGEN_ReplyGetID, "\x01",0x01,0x02,ID_GetFirmware },
1809 
1810  {GNAPGEN_ReplyGetMemory, "\x02",0x01,0x02,ID_GetMemory },
1811  {GNAPGEN_ReplyGetMemoryStatus, "\x02",0x01,0x08,ID_GetMemoryStatus },
1812  {GNAPGEN_ReplyDeleteMemory, "\x02",0x01,0x06,ID_DeleteMemory },
1813  {GNAPGEN_ReplySetMemory, "\x02",0x01,0x04,ID_SetMemory },
1814  {GNAPGEN_ReplyDialVoice, "\x02",0x01,10 ,ID_DialVoice },
1815  {GNAPGEN_ReplyGetNextMemory, "\x02",0x01,12 ,ID_GetMemory },
1816 
1817  {GNAPGEN_ReplyGetNetworkInfo, "\x03",0x01,0x02,ID_GetNetworkInfo },
1818  {GNAPGEN_ReplyGetSignalQuality, "\x03",0x01,0x04,ID_GetSignalQuality },
1819 
1820  {GNAPGEN_ReplyGetBatteryCharge, "\x04",0x01,0x02,ID_GetBatteryCharge },
1821 
1822  /* type 5 is DEBUG */
1823  {GNAPGEN_ReplyGetModelFirmware, "\x05",0x01,0x02,ID_IncomingFrame },
1824 
1825  /* type 6 is SMS */
1826  {GNAPGEN_ReplyGetSMSFolders, "\x06",0x01,0x02,ID_GetSMSFolders },
1827  {GNAPGEN_ReplyGetSMSStatus, "\x06",0x01,0x0A,ID_GetSMSStatus },
1828  {GNAPGEN_ReplyGetSMSC, "\x06",0x01,0x16,ID_GetSMSC },
1829  {GNAPGEN_ReplyGetSMSFolderStatus,"\x06",0x01,0x04,ID_GetSMSFolderStatus },
1830  {GNAPGEN_ReplyDeleteSMSMessage, "\x06",0x01,18,ID_DeleteSMSMessage },
1831  {GNAPGEN_ReplyGetSMS, "\x06",0x01,12,ID_GetSMSMessage },
1832  {GNAPGEN_ReplySetSMS, "\x06",0x01,14,ID_SaveSMSMessage },
1833 
1834  /* calendar */
1835  {GNAPGEN_ReplyGetNextCalendar, "\x07",0x01,0x02,ID_GetCalendarNote },
1836  {NONEFUNCTION, "\x07",0x01,0x06,ID_DeleteCalendarNote },
1837  {GNAPGEN_ReplyGetToDo, "\x07",0x01,0x08,ID_GetToDo },
1838 
1839  /* time */
1840  {GNAPGEN_ReplyGetDateTime, "\x08",0x01,0x02,ID_GetDateTime },
1841  {GNAPGEN_ReplyGetAlarm, "\x08",0x01,0x06,ID_GetAlarm },
1842 
1843  {NULL, "\x00",0x00,0x00,ID_None }
1844 };
1845 
1846 GSM_Phone_Functions GNAPGENPhone = {
1847  "gnap",
1848  GNAPGENReplyFunctions,
1849  NOTIMPLEMENTED, /* Install */
1850  GNAPGEN_Initialise,
1851  NONEFUNCTION, /* Terminate */
1853  NOTSUPPORTED, /* ShowStartInfo */
1854  GNAPGEN_GetManufacturer,
1855  GNAPGEN_GetModel,
1856  GNAPGEN_GetFirmware,
1857  GNAPGEN_GetIMEI,
1858  NOTSUPPORTED, /* GetOriginalIMEI */
1859  NOTSUPPORTED, /* GetManufactureMonth */
1860  NOTSUPPORTED, /* GetProductCode */
1861  GNAPGEN_GetHW,
1862  NOTSUPPORTED, /* GetPPM */
1863  NOTSUPPORTED, /* GetSIMIMSI */
1864  GNAPGEN_GetDateTime,
1865  NOTSUPPORTED, /* SetDateTime */
1866  GNAPGEN_GetAlarm,
1867  NOTSUPPORTED, /* SetAlarm */
1868  NOTSUPPORTED, /* GetLocale */
1869  NOTSUPPORTED, /* SetLocale */
1870  NOTSUPPORTED, /* PressKey */
1871  NOTSUPPORTED, /* Reset */
1872  NOTSUPPORTED, /* ResetPhoneSettings */
1873  NOTSUPPORTED, /* EnterSecurityCode */
1874  NOTSUPPORTED, /* GetSecurityStatus */
1875  NOTSUPPORTED, /* GetDisplayStatus */
1876  NOTSUPPORTED, /* SetAutoNetworkLogin */
1877  GNAPGEN_GetBatteryCharge,
1878  GNAPGEN_GetSignalQuality,
1879  GNAPGEN_GetNetworkInfo,
1880  NOTSUPPORTED, /* GetCategory */
1881  NOTSUPPORTED, /* AddCategory */
1882  NOTSUPPORTED, /* GetCategoryStatus */
1883  GNAPGEN_GetMemoryStatus,
1884  GNAPGEN_GetMemory,
1885  GNAPGEN_GetNextMemory,
1886  GNAPGEN_SetMemory,
1887  GNAPGEN_AddMemory,
1888  GNAPGEN_DeleteMemory,
1889  NOTIMPLEMENTED, /* DeleteAllMemory */
1890  NOTSUPPORTED, /* GetSpeedDial */
1891  NOTSUPPORTED, /* SetSpeedDial */
1892  GNAPGEN_GetSMSC,
1893  NOTSUPPORTED, /* SetSMSC */
1894  GNAPGEN_GetSMSStatus,
1895  NOTSUPPORTED, /* GetSMS */
1896  GNAPGEN_GetNextSMS,
1897  NOTSUPPORTED, /* SetSMS */
1898  GNAPGEN_AddSMS,
1899  GNAPGEN_DeleteSMSMessage,
1900  GNAPGEN_SendSMSMessage,
1901  NOTSUPPORTED, /* SendSavedSMS */
1902  NOTSUPPORTED, /* SetFastSMSSending */
1903  NOTSUPPORTED, /* SetIncomingSMS */
1904  NOTSUPPORTED, /* SetIncomingCB */
1905  GNAPGEN_GetSMSFolders,
1906  NOTSUPPORTED, /* AddSMSFolder */
1907  NOTSUPPORTED, /* DeleteSMSFolder */
1908  GNAPGEN_DialVoice, /* DialVoice */
1909  NOTIMPLEMENTED, /* DialService */
1910  NOTSUPPORTED, /* AnswerCall */
1911  NOTSUPPORTED, /* CancelCall */
1912  NOTSUPPORTED, /* HoldCall */
1913  NOTSUPPORTED, /* UnholdCall */
1914  NOTSUPPORTED, /* ConferenceCall */
1915  NOTSUPPORTED, /* SplitCall */
1916  NOTSUPPORTED, /* TransferCall */
1917  NOTSUPPORTED, /* SwitchCall */
1918  NOTSUPPORTED, /* GetCallDivert */
1919  NOTSUPPORTED, /* SetCallDivert */
1920  NOTSUPPORTED, /* CancelAllDiverts */
1921  NOTSUPPORTED, /* SetIncomingCall */
1922  NOTSUPPORTED, /* SetIncomingUSSD */
1923  NOTSUPPORTED, /* SendDTMF */
1924  NOTSUPPORTED, /* GetRingtone */
1925  NOTSUPPORTED, /* SetRingtone */
1926  NOTSUPPORTED, /* GetRingtonesInfo */
1927  NOTSUPPORTED, /* DeleteUserRingtones */
1928  NOTSUPPORTED, /* PlayTone */
1929  NOTSUPPORTED, /* GetWAPBookmark */
1930  NOTSUPPORTED, /* SetWAPBookmark */
1931  NOTSUPPORTED, /* DeleteWAPBookmark */
1932  NOTSUPPORTED, /* GetWAPSettings */
1933  NOTSUPPORTED, /* SetWAPSettings */
1934  NOTSUPPORTED, /* GetSyncMLSettings */
1935  NOTSUPPORTED, /* SetSyncMLSettings */
1936  NOTSUPPORTED, /* GetChatSettings */
1937  NOTSUPPORTED, /* SetChatSettings */
1938  NOTSUPPORTED, /* GetMMSSettings */
1939  NOTSUPPORTED, /* SetMMSSettings */
1940  NOTSUPPORTED, /* GetMMSFolders */
1941  NOTSUPPORTED, /* GetNextMMSFileInfo */
1942  NOTSUPPORTED, /* GetBitmap */
1943  NOTSUPPORTED, /* SetBitmap */
1944  NOTSUPPORTED, /* GetToDoStatus */
1945  NOTSUPPORTED, /* GetToDo */
1946  GNAPGEN_GetNextToDo,
1947  NOTSUPPORTED, /* SetToDo */
1948  NOTSUPPORTED, /* AddToDo */
1949  NOTSUPPORTED, /* DeleteToDo */
1950  NOTSUPPORTED, /* DeleteAllToDo */
1951  NOTSUPPORTED, /* GetCalendarStatus */
1952  NOTSUPPORTED, /* GetCalendar */
1953  GNAPGEN_GetNextCalendar,
1954  NOTSUPPORTED, /* SetCalendar */
1955  GNAPGEN_AddCalendar,
1956  GNAPGEN_DeleteCalendar,
1957  NOTSUPPORTED, /* DeleteAllCalendar */
1958  NOTSUPPORTED, /* GetCalendarSettings */
1959  NOTSUPPORTED, /* SetCalendarSettings */
1960  NOTSUPPORTED, /* GetNoteStatus */
1961  NOTSUPPORTED, /* GetNote */
1962  NOTSUPPORTED, /* GetNextNote */
1963  NOTSUPPORTED, /* SetNote */
1964  NOTSUPPORTED, /* AddNote */
1965  NOTSUPPORTED, /* DeleteNote */
1966  NOTSUPPORTED, /* DeleteAllNotes */
1967  NOTSUPPORTED, /* GetProfile */
1968  NOTSUPPORTED, /* SetProfile */
1969  NOTSUPPORTED, /* GetFMStation */
1970  NOTSUPPORTED, /* SetFMStation */
1971  NOTSUPPORTED, /* ClearFMStations */
1972  NOTSUPPORTED, /* GetNextFileFolder */
1973  NOTSUPPORTED, /* GetFolderListing */
1974  NOTSUPPORTED, /* GetNextRootFolder */
1975  NOTSUPPORTED, /* SetFileAttributes */
1976  NOTSUPPORTED, /* GetFilePart */
1977  NOTSUPPORTED, /* AddFilePart */
1978  NOTSUPPORTED, /* SendFilePart */
1979  NOTSUPPORTED, /* GetFileSystemStatus */
1980  NOTSUPPORTED, /* DeleteFile */
1981  NOTSUPPORTED, /* AddFolder */
1982  NOTSUPPORTED, /* DeleteFolder */
1983  NOTSUPPORTED, /* GetGPRSAccessPoint */
1984  NOTSUPPORTED, /* SetGPRSAccessPoint */
1985  NOTSUPPORTED, /* GetScreenshot */
1986  NOTSUPPORTED, /* SetPower */
1987  NOTSUPPORTED, /* PostConnect */
1988  NONEFUNCTION /* PreAPICall */
1989 };
1990 
1991 #endif
1992 
1993 /* How should editor hadle tabs in this file? Add editor commands here.
1994  * vim: noexpandtab sw=8 ts=8 sts=8:
1995  */
unsigned char Text
GSM_SMSMessageType PDU
GSM_DateTime DateTime
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
gboolean LastContactArrived
Definition: gnapgen.h:33
unsigned char TPUDL
gboolean UseGlobalDebugFile
GSM_ChargeState ChargeState
Definition: gammu-info.h:244
char HardwareCache[50]
Definition: gsmstate.h:466
const unsigned char * GSM_GetNetworkName(const char *NetworkCode)
Definition: gsmnet.c:2420
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
Definition: gsmstate.c:914
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
unsigned char TPDCS
GSM_StateMachine * GSM_AllocStateMachine(void)
Definition: gsmstate.c:1677
GSM_Alarm * Alarm
Definition: gsmstate.h:493
GSM_ToDo_Priority Priority
void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
Definition: gsmstate.c:1317
unsigned char ReplaceMessage
GSM_SMS_State State
GSM_MemoryType MemoryType
Definition: gammu-memory.h:415
void FreeLines(GSM_CutLines *lines)
Definition: misc.c:392
unsigned char SMSCTime
GSM_CalendarNoteType Type
#define NOTSUPPORTED
Definition: gsmcomon.h:14
GSM_MemoryEntry * Memory
Definition: gsmstate.h:497
unsigned char NetworkName[15 *2]
Definition: gammu-info.h:135
GSM_MemoryType NOKIA_GetMemoryType(GSM_StateMachine *s, GSM_MemoryType memory_type, unsigned char *ID)
GSM_SMSMemoryStatus * SMSStatus
Definition: gsmstate.h:517
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
Definition: gsmstate.h:458
GSM_DateTime DateTime
GSM_MultiSMSMessage * GetSMSMessage
Definition: gsmstate.h:509
GSM_ToDoEntry * ToDo
Definition: gsmstate.h:585
int SMSFolderID[100]
Definition: gnapgen.h:36
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
Definition: gsmstate.c:1131
#define NONEFUNCTION
Definition: gsmcomon.h:12
GSM_Error
Definition: gammu-error.h:23
gboolean RejectDuplicates
const char * GetLineString(const char *message, GSM_CutLines *lines, int start)
Definition: misc.c:492
GSM_Debug_Info di
Definition: gsmstate.h:1412
GSM_CallShowNumber
Definition: gammu-call.h:192
GSM_NetworkInfo * NetworkInfo
Definition: gsmstate.h:541
signed char Class
GSM_OneSMSFolder Folder[GSM_MAX_SMS_FOLDERS]
char LAC[10]
Definition: gammu-info.h:131
void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS)
Definition: gsmsms.c:1129
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
GSM_SMSMessageLayout PHONE_SMSDeliver
Definition: pfunc.c:16
GSM_UDHHeader UDH
char * DayOfWeek(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:129
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
Definition: debug.c:127
GSM_Error(* WriteMessage)(GSM_StateMachine *s, unsigned const char *buffer, int length, int type)
Definition: gsmstate.h:347
TUint32 SMSIDs[5000]
Definition: gnapgen.h:39
char IMEI[GSM_MAX_IMEI_LENGTH+1]
Definition: gsmstate.h:437
unsigned char * Buffer
Definition: gammu-file.h:94
char Version[GSM_MAX_VERSION_LENGTH+1]
Definition: gsmstate.h:454
GSM_Coding_Type Coding
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
Definition: gsmstate.h:441
unsigned char SMSCNumber
GSM_SMSFormat Format
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
char NetworkCode[10]
Definition: gammu-info.h:122
char CID[10]
Definition: gammu-info.h:118
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
Definition: debug.c:278
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
GSM_EntryType EntryType
Definition: gammu-memory.h:372
GSM_SignalQuality * SignalQuality
Definition: gsmstate.h:533
char DebugLevel[50]
size_t Used
Definition: gammu-file.h:70
GSM_ToDoType EntryType
void GSM_GetCalendarRecurranceRepeat(GSM_Debug_Info *di, unsigned char *rec, unsigned char *endday, GSM_CalendarEntry *entry)
Definition: gsmcal.c:137
int byte2
Definition: gnapgen.h:19
void GSM_CalendarFindDefaultTextTimeAlarmPhone(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *EndTime, int *Location)
Definition: gsmcal.c:279
void GSM_ClearBatteryCharge(GSM_BatteryCharge *bat)
Definition: gsmmisc.c:784
unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1) *2]
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
Definition: gammu-memory.h:399
int gboolean
Definition: gammu-types.h:23
GSM_ValidityPeriodFormat Format
GSM_DateTime * DateTime
Definition: gsmstate.h:489
#define GSM_MAX_SMS_FOLDER_NAME_LEN
Definition: gammu-limits.h:155
GSM_CalendarNoteType Type
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
Definition: gsmphones.c:1002
void InitLines(GSM_CutLines *lines)
Definition: misc.c:385
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
unsigned char Name[(GSM_MAX_SMS_NAME_LENGTH+1) *2]
gboolean InboxFolder
GSM_Phone Phone
Definition: gsmstate.h:1431
GSM_Error GSM_DecodeSMSFrameText(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
Definition: gsmsms.c:316
#define FALSE
Definition: gammu-types.h:25
GSM_SMSValidity Validity
struct GSM_Phone_Data::@2 Priv
int byte1
Definition: gnapgen.h:18
GSM_SubToDoEntry Entries[GSM_TODO_ENTRIES]
GSM_Error GSM_WaitFor(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
Definition: gsmstate.c:1029
GSM_GPRS_State GPRS
Definition: gammu-info.h:139
unsigned char TPVP
GSM_Error PHONE_FindDataFile(GSM_StateMachine *s, GSM_File *File, const char *ExtraPath, const char *filename)
Definition: pfunc.c:141
GSM_Coding_Type GSM_GetMessageCoding(GSM_Debug_Info *di, const char TPDCS)
Definition: gsmsms.c:261
GSM_Phone_RequestID RequestID
Definition: gsmstate.h:685
unsigned char Name[(GSM_MAX_SMS_FOLDER_NAME_LEN+1) *2]
int DecodeWithBCDAlphabet(unsigned char value)
Definition: coding.c:323
GSM_MemoryType Memory
gboolean OutboxFolder
GSM_SMSMessage SMS[GSM_MAX_MULTI_SMS]
GSM_CalendarType EntryType
GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
Definition: gsmstate.c:949
#define NOTIMPLEMENTED
Definition: gsmcomon.h:13
GSM_Protocol Protocol
Definition: gsmstate.h:1430
gboolean InboxFolder
GSM_BatteryCharge * BatteryCharge
Definition: gsmstate.h:537
GSM_Config * GSM_GetConfig(GSM_StateMachine *s, int num)
Definition: gsmstate.c:1301
GSM_NetworkInfo_State State
Definition: gammu-info.h:127
GSM_DateTime Date
Definition: gammu-memory.h:380
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
unsigned char firstbyte
int byte4
Definition: gnapgen.h:21
gboolean closable
Definition: debug.h:40
int byte3
Definition: gnapgen.h:20
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Error GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet)
Definition: coding.c:1028
GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES]
GSM_MemoryType MemoryType
Definition: gammu-memory.h:131
unsigned char TPStatus
GSM_SMSFolders * SMSFolders
Definition: gsmstate.h:521
gboolean GSM_SetDebugLevel(const char *info, GSM_Debug_Info *privdi)
Definition: debug.c:186
Definition: debug.h:87
GSM_SMSMessageLayout PHONE_SMSSubmit
Definition: pfunc.c:23
GSM_EntryLocation Location
Definition: gammu-memory.h:376
void GSM_CreateFirmwareNumber(GSM_StateMachine *s)
Definition: pfunc.c:52
GSM_SMSC * SMSC
Definition: gsmstate.h:505
GSM_Protocol_Functions * Functions
Definition: gsmstate.h:424
GSM_Error PHONE_UploadFile(GSM_StateMachine *s, GSM_File *File)
Definition: pfunc.c:173
#define TRUE
Definition: gammu-types.h:28
GSM_MemoryStatus * MemoryStatus
Definition: gsmstate.h:501
GSM_SMSMessage * SaveSMSMessage
Definition: gsmstate.h:513
void NOKIA_DecodeDateTime(GSM_StateMachine *s, unsigned char *buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse)
Definition: nfunc.c:976
unsigned char MessageReference
gboolean ReplyViaSameSMSC
GSM_DateTime SMSCTime
GSM_Error PHONE_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
Definition: pfunc.c:58
unsigned char * Buffer
Definition: protocol.h:22
unsigned char DateTime
unsigned char Text[(GSM_MAX_TODO_TEXT_LENGTH+1) *2]
void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines, const char *whitespaces, const size_t spaceslen, const char *quotes, const size_t quoteslen, const gboolean eot)
Definition: misc.c:401
#define UNUSED
Definition: gammu-misc.h:105
unsigned char Number
void GSM_FreeStateMachine(GSM_StateMachine *s)
Definition: gsmstate.c:1689
unsigned char TPMR
GSM_ValidityPeriod Relative
char Model[GSM_MAX_MODEL_LENGTH+1]
Definition: gsmstate.h:445
gboolean Repeating
GSM_MemoryType Memory
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
GSM_Error GSM_DecodeSMSFrameStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
Definition: gsmsms.c:503
const unsigned char * GSM_GetCountryName(const char *CountryCode)
Definition: gsmnet.c:2452
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
#define GSM_MAX_SMSC_NAME_LENGTH
Definition: gammu-limits.h:218
GSM_Debug_Info * GSM_GetDebug(GSM_StateMachine *s)
Definition: gsmstate.c:1719
unsigned char TPPID
GSM_CalendarEntry * Cal
Definition: gsmstate.h:549
unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1) *2]
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427