Gammu internals  1.38.0
n3650.c
Go to the documentation of this file.
1 /* (c) 2003 by Marcin Wiacek */
2 
3 #include "../../../gsmstate.h"
4 
5 #ifdef GSM_ENABLE_NOKIA3650
6 
7 #include <string.h>
8 #include <time.h>
9 
10 #include "../../../gsmcomon.h"
11 #include "../../../misc/coding/coding.h"
12 #include "../../../service/gsmlogo.h"
13 #include "../nfunc.h"
14 #include "../nfuncold.h"
15 #include "../../pfunc.h"
16 #include "../dct4s40/dct4func.h"
17 #include "n3650.h"
18 
19 static GSM_Error N3650_ReplyGetFilePart(GSM_Protocol_Message *msg, GSM_StateMachine *s)
20 {
21  int old;
22 
23  smprintf(s,"File part received\n");
24  old = s->Phone.Data.File->Used;
25 
26  if (msg->Length < 10) {
27  if (old == 0) return ERR_UNKNOWN;
28  return ERR_EMPTY;
29  }
30 
31  s->Phone.Data.File->Used += msg->Buffer[10]*256*256*256+
32  msg->Buffer[11]*256*256+
33  msg->Buffer[12]*256+
34  msg->Buffer[13];
35  smprintf(s,"Length: %i\n",
36  msg->Buffer[10]*256*256*256+
37  msg->Buffer[11]*256*256+
38  msg->Buffer[12]*256+
39  msg->Buffer[13]);
40  s->Phone.Data.File->Buffer = (unsigned char *)realloc(s->Phone.Data.File->Buffer,s->Phone.Data.File->Used);
41  memcpy(s->Phone.Data.File->Buffer+old,msg->Buffer+18,s->Phone.Data.File->Used-old);
42  if (s->Phone.Data.File->Used-old < 0x03 * 256 + 0xD4) return ERR_EMPTY;
43  return ERR_NONE;
44 }
45 
46 static GSM_Error N3650_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, size_t *Size)
47 {
48  unsigned int len=10,i;
49  GSM_Error error;
50  unsigned char StartReq[500] = {
51  N7110_FRAME_HEADER, 0x0D, 0x10, 0x01, 0x07,
52  0x24, /* len1 */
53  0x12, /* len2 */
54  0x0E, /* len3 */
55  0x00}; /* File name */
56  unsigned char ContinueReq[] = {
57  N7110_FRAME_HEADER, 0x0D, 0x20, 0x01, 0xF0,
58  0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
59 
60  if (File->Used == 0) {
61  (*Size) = 0;
62 
63  sprintf(StartReq+10,"%s",File->ID_FullName);
64  len+=strlen(File->ID_FullName)-1;
65  StartReq[7] = strlen(File->ID_FullName) + 3;
66 
67  StartReq[8] = strlen(File->ID_FullName);
68  StartReq[9] = 0;
69  while (File->ID_FullName[StartReq[8]] != '\\') {
70  StartReq[8]--;
71  StartReq[9]++;
72  }
73  for (i=StartReq[8];i<strlen(File->ID_FullName);i++) {
74  StartReq[i+10] = StartReq[i+1+10];
75  }
76  StartReq[9]--;
77 
78  EncodeUnicode(File->Name,File->ID_FullName+StartReq[8]+1,StartReq[9]);
79  File->Folder = FALSE;
80 
82  if (error != ERR_NONE) return error;
83 
84  s->Phone.Data.File = File;
85  return GSM_WaitFor (s, StartReq, len, 0x58, 4, ID_GetFile);
86  }
87 
88  s->Phone.Data.File = File;
89  error = GSM_WaitFor (s, ContinueReq, 14, 0x58, 4, ID_GetFile);
90 
91 #if 0
92  if (error == GE_EMPTY) {
94  if (error != ERR_NONE) return error;
95  return GE_EMPTY;
96  }
97 #endif
98 
99  return error;
100 }
101 
102 static GSM_Error N3650_ReplyGetFolderInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
103 {
104  GSM_File *File = s->Phone.Data.FileInfo;
105  GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
106  int i,pos = 6;
107 
108  i = Priv->FilesLocationsUsed-1;
109  while (1) {
110  if (i==Priv->FilesLocationsCurrent-1) break;
111  smprintf(s, "Copying %i to %i, max %i, current %i\n",
112  i,i+msg->Buffer[5],
114  memcpy(Priv->Files[i+msg->Buffer[5]],Priv->Files[i],sizeof(GSM_File));
115  i--;
116  }
117  Priv->FileEntries = msg->Buffer[5];
118  Priv->FilesLocationsUsed += msg->Buffer[5];
119  for (i=0;i<msg->Buffer[5];i++) {
120  Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = TRUE;
121  if (msg->Buffer[pos+2] == 0x01) {
122  Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = FALSE;
123  smprintf(s,"File ");
124  }
125  EncodeUnicode(Priv->Files[Priv->FilesLocationsCurrent+i]->Name,msg->Buffer+pos+9,msg->Buffer[pos+8]);
126  smprintf(s,"%s\n",DecodeUnicodeString(Priv->Files[Priv->FilesLocationsCurrent+i]->Name));
127  Priv->Files[Priv->FilesLocationsCurrent+i]->Level = File->Level+1;
128  sprintf(Priv->Files[Priv->FilesLocationsCurrent+i]->ID_FullName,"%s\\%s",File->ID_FullName,msg->Buffer+pos+9);
129  pos+=msg->Buffer[pos+1];
130  }
131  smprintf(s, "\n");
132  return ERR_NONE;
133 }
134 
135 static GSM_Error N3650_GetFolderInfo(GSM_StateMachine *s, GSM_File *File)
136 {
137  int len=10;
138  unsigned char req[500] = {
139  N7110_FRAME_HEADER, 0x0B, 0x00, 0x01, 0x07,
140  0x18, /* folder name length + 6 */
141  0x12, /* folder name length */
142  0x00,
143  0x00}; /* folder name */
144 
145  /* FIXME: I doubt this works */
146  sprintf(req+10,"%s", File->ID_FullName);
147  len +=strlen(File->ID_FullName);
148  req[7] = strlen(File->ID_FullName) + 6;
149  req[8] = strlen(File->ID_FullName);
150  req[len++] = 0x00;
151  req[len++] = 0x00;
152 
153  s->Phone.Data.FileInfo = File;
154  return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile);
155 }
156 
157 static GSM_Error N3650_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start)
158 {
159  GSM_Error error;
160  GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
161 
162  if (start) {
164  if (error != ERR_NONE) return error;
165 
166  Priv->Files[0]->Folder = TRUE;
167  Priv->Files[0]->Level = 1;
168  Priv->Files[0]->Name[0] = 0;
169  Priv->Files[0]->Name[1] = 0;
170  Priv->Files[0]->ID_FullName[0] = 'Z';
171  Priv->Files[0]->ID_FullName[1] = ':';
172  Priv->Files[0]->ID_FullName[2] = 0;
173 
174  Priv->Files[1]->Folder = TRUE;
175  Priv->Files[1]->Level = 1;
176  Priv->Files[1]->Name[0] = 0;
177  Priv->Files[1]->Name[1] = 0;
178  Priv->Files[1]->ID_FullName[0] = 'E';
179  Priv->Files[1]->ID_FullName[1] = ':';
180  Priv->Files[1]->ID_FullName[2] = 0;
181 
182  Priv->Files[2]->Folder = TRUE;
183  Priv->Files[2]->Level = 1;
184  Priv->Files[2]->Name[0] = 0;
185  Priv->Files[2]->Name[1] = 0;
186  Priv->Files[2]->ID_FullName[0] = 'C';
187  Priv->Files[2]->ID_FullName[1] = ':';
188  Priv->Files[2]->ID_FullName[2] = 0;
189 
190  Priv->FilesLocationsUsed = 3;
191  Priv->FilesLocationsCurrent = 0;
192  Priv->FileLev = 1;
193  }
194 
195  if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) {
196 #if 0
198  if (error != ERR_NONE) return error;
199 #endif
200 
201  return ERR_EMPTY;
202  }
203 
204  strcpy(File->ID_FullName,Priv->Files[Priv->FilesLocationsCurrent]->ID_FullName);
205  File->Level = Priv->Files[Priv->FilesLocationsCurrent]->Level;
206  File->Folder = Priv->Files[Priv->FilesLocationsCurrent]->Folder;
208  Priv->FilesLocationsCurrent++;
209 
210  if (!File->Folder) return ERR_NONE;
211 
212  if (Priv->FilesLocationsCurrent > 1) {
213  if (File->ID_FullName[0]!=Priv->Files[Priv->FilesLocationsCurrent-2]->ID_FullName[0]) {
214  if (File->ID_FullName[0] == 'E') {
215  error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
216  if (error != ERR_NONE) return error;
217  error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
218  if (error != ERR_NONE) return error;
219  }
220  if (File->ID_FullName[0] == 'C') {
222  if (error != ERR_NONE) return error;
224  if (error != ERR_NONE) return error;
225  }
226 #if 0
227  if (error != ERR_NONE) return error;
228 #endif
229  }
230  }
231 
232  File->ReadOnly = FALSE;
233  File->System = FALSE;
234  File->Protected = FALSE;
235  File->Hidden = FALSE;
236 
237  return N3650_GetFolderInfo(s, File);
238 }
239 
240 static GSM_Error N3650_Initialise (GSM_StateMachine *s)
241 {
242  GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
243  int i=0;
244 
245  for (i=0;i<10000;i++) {
246  Priv->Files[i] = (GSM_File *)malloc(sizeof(GSM_File));
247  if (Priv->Files[i] == NULL) return ERR_MOREMEMORY;
248  }
249  return ERR_NONE;
250 }
251 
252 static GSM_Error N3650_Terminate(GSM_StateMachine *s)
253 {
254  GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
255  int i;
256 
257  for (i=0;i<10000;i++) {
258  free(Priv->Files[i]);
259  Priv->Files[i]=NULL;
260  }
261  return ERR_NONE;
262 }
263 
264 static GSM_Reply_Function N3650ReplyFunctions[] = {
265  {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset },
266  {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset },
267  {NoneReply, "\x15",0x03,0x68,ID_Reset },
268 
269  {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI },
270  {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware },
271  {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode },
272 
273  {N3650_ReplyGetFolderInfo, "\x58",0x03,0x0C,ID_GetFile },
274  {N3650_ReplyGetFilePart, "\x58",0x03,0x0E,ID_GetFile },
275 
276  {NULL, "\x00",0x00,0x00,ID_None }
277 };
278 
279 GSM_Phone_Functions N3650Phone = {
280  "3650|NGAGE",
281  N3650ReplyFunctions,
282  NOTSUPPORTED, /* Install */
283  N3650_Initialise,
284  N3650_Terminate,
286  NOTSUPPORTED, /* ShowStartInfo */
290  DCT4_GetIMEI,
291  NOTSUPPORTED, /* GetOriginalIMEI */
292  NOTSUPPORTED, /* GetManufactureMonth */
295  NOTSUPPORTED, /* GetPPM */
296  NOTSUPPORTED, /* GetSIMIMSI */
297  NOTSUPPORTED, /* GetDateTime */
298  NOTSUPPORTED, /* SetDateTime */
299  NOTSUPPORTED, /* GetAlarm */
300  NOTSUPPORTED, /* SetAlarm */
301  NOTSUPPORTED, /* GetLocale */
302  NOTSUPPORTED, /* SetLocale */
303  NOTSUPPORTED, /* PressKey */
304  DCT4_Reset,
305  NOTSUPPORTED, /* ResetPhoneSettings */
306  NOTSUPPORTED, /* EnterSecurityCode */
307  NOTSUPPORTED, /* GetSecurityStatus */
308  NOTSUPPORTED, /* GetDisplayStatus */
309  NOTSUPPORTED, /* SetAutoNetworkLogin */
310  NOTSUPPORTED, /* GetBatteryCharge */
311  NOTSUPPORTED, /* GetSignalQuality */
312  NOTSUPPORTED, /* GetNetworkInfo */
313  NOTSUPPORTED, /* GetCategory */
314  NOTSUPPORTED, /* AddCategory */
315  NOTSUPPORTED, /* GetCategoryStatus */
316  NOTSUPPORTED, /* GetMemoryStatus */
317  NOTSUPPORTED, /* GetMemory */
318  NOTSUPPORTED, /* GetNextMemory */
319  NOTSUPPORTED, /* SetMemory */
320  NOTSUPPORTED, /* AddMemory */
321  NOTSUPPORTED, /* DeleteMemory */
322  NOTIMPLEMENTED, /* DeleteAllMemory */
323  NOTSUPPORTED, /* GetSpeedDial */
324  NOTSUPPORTED, /* SetSpeedDial */
325  NOTSUPPORTED, /* GetSMSC */
326  NOTSUPPORTED, /* SetSMSC */
327  NOTSUPPORTED, /* GetSMSStatus */
328  NOTSUPPORTED, /* GetSMS */
329  NOTSUPPORTED, /* GetNextSMS */
330  NOTSUPPORTED, /* SetSMS */
331  NOTSUPPORTED, /* AddSMS */
332  NOTSUPPORTED, /* DeleteSMS */
333  NOTSUPPORTED, /* SendSMS */
334  NOTSUPPORTED, /* SendSavedSMS */
335  NOTSUPPORTED, /* SetFastSMSSending */
336  NOTSUPPORTED, /* SetIncomingSMS */
337  NOTSUPPORTED, /* SetIncomingCB */
338  NOTSUPPORTED, /* GetSMSFolders */
339  NOTSUPPORTED, /* AddSMSFolder */
340  NOTSUPPORTED, /* DeleteSMSFolder */
341  NOTIMPLEMENTED, /* DialVoice */
342  NOTIMPLEMENTED, /* DialService */
343  NOTIMPLEMENTED, /* AnswerCall */
344  NOTIMPLEMENTED, /* CancelCall */
345  NOTIMPLEMENTED, /* HoldCall */
346  NOTIMPLEMENTED, /* UnholdCall */
347  NOTIMPLEMENTED, /* ConferenceCall */
348  NOTIMPLEMENTED, /* SplitCall */
349  NOTIMPLEMENTED, /* TransferCall */
350  NOTIMPLEMENTED, /* SwitchCall */
351  NOTSUPPORTED, /* GetCallDivert */
352  NOTSUPPORTED, /* SetCallDivert */
353  NOTSUPPORTED, /* CancelAllDiverts */
354  NOTIMPLEMENTED, /* SetIncomingCall */
355  NOTIMPLEMENTED, /* SetIncomingUSSD */
356  NOTSUPPORTED, /* SendDTMF */
357  NOTSUPPORTED, /* GetRingtone */
358  NOTSUPPORTED, /* SetRingtone */
359  NOTSUPPORTED, /* GetRingtonesInfo */
360  NOTIMPLEMENTED, /* DeleteUserRingtones */
361  NOTSUPPORTED, /* PlayTone */
362  NOTSUPPORTED, /* GetWAPBookmark */
363  NOTSUPPORTED, /* SetWAPBookmark */
364  NOTSUPPORTED, /* DeleteWAPBookmark */
365  NOTSUPPORTED, /* GetWAPSettings */
366  NOTSUPPORTED, /* SetWAPSettings */
367  NOTSUPPORTED, /* GetSyncMLSettings */
368  NOTSUPPORTED, /* SetSyncMLSettings */
369  NOTSUPPORTED, /* GetChatSettings */
370  NOTSUPPORTED, /* SetChatSettings */
371  NOTSUPPORTED, /* GetMMSSettings */
372  NOTSUPPORTED, /* SetMMSSettings */
373  NOTSUPPORTED, /* GetMMSFolders */
374  NOTSUPPORTED, /* GetNextMMSFile */
375  NOTSUPPORTED, /* GetBitmap */
376  NOTSUPPORTED, /* SetBitmap */
377  NOTSUPPORTED, /* GetToDoStatus */
378  NOTSUPPORTED, /* GetToDo */
379  NOTSUPPORTED, /* GetNextToDo */
380  NOTSUPPORTED, /* SetToDo */
381  NOTSUPPORTED, /* AddToDo */
382  NOTSUPPORTED, /* DeleteToDo */
383  NOTSUPPORTED, /* DeleteAllToDo */
384  NOTIMPLEMENTED, /* GetCalendarStatus */
385  NOTIMPLEMENTED, /* GetCalendar */
386  NOTSUPPORTED, /* GetNextCalendar */
387  NOTIMPLEMENTED, /* SetCalendar */
388  NOTSUPPORTED, /* AddCalendar */
389  NOTSUPPORTED, /* DeleteCalendar */
390  NOTIMPLEMENTED, /* DeleteAllCalendar */
391  NOTSUPPORTED, /* GetCalendarSettings */
392  NOTSUPPORTED, /* SetCalendarSettings */
393  NOTSUPPORTED, /* GetNoteStatus */
394  NOTSUPPORTED, /* GetNote */
395  NOTSUPPORTED, /* GetNextNote */
396  NOTSUPPORTED, /* SetNote */
397  NOTSUPPORTED, /* AddNote */
398  NOTSUPPORTED, /* DeleteNote */
399  NOTSUPPORTED, /* DeleteAllNotes */
400  NOTSUPPORTED, /* GetProfile */
401  NOTSUPPORTED, /* SetProfile */
402  NOTSUPPORTED, /* GetFMStation */
403  NOTSUPPORTED, /* SetFMStation */
404  NOTSUPPORTED, /* ClearFMStations */
405  N3650_GetNextFileFolder,
406  NOTSUPPORTED, /* GetFolderListing */
407  NOTSUPPORTED, /* GetNextRootFolder */
408  NOTSUPPORTED, /* SetFileAttributes */
409  N3650_GetFilePart,
410  NOTIMPLEMENTED, /* AddFilePart */
411  NOTSUPPORTED, /* SendFilePart */
412  NOTSUPPORTED, /* GetFileSystemStatus */
413  NOTIMPLEMENTED, /* DeleteFile */
414  NOTIMPLEMENTED, /* AddFolder */
415  NOTSUPPORTED, /* DeleteFolder */
416  NOTSUPPORTED, /* GetGPRSAccessPoint */
417  NOTSUPPORTED, /* SetGPRSAccessPoint */
418  NOTSUPPORTED, /* GetScreenshot */
419  NOTSUPPORTED, /* SetPower */
420  NOTSUPPORTED, /* PostConnect */
421  NONEFUNCTION /* PreAPICall */
422 };
423 
424 #endif
425 
426 /* How should editor hadle tabs in this file? Add editor commands here.
427  * vim: noexpandtab sw=8 ts=8 sts=8:
428  */
GSM_Error DCT4_SetPhoneMode(GSM_StateMachine *s, DCT4_PHONE_MODE mode)
unsigned char Name[2 *(GSM_MAX_FILENAME_LENGTH+1)]
Definition: gammu-file.h:74
GSM_Error DCT4_ReplySetPhoneMode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
unsigned char ID_FullName[2 *(GSM_MAX_FILENAME_ID_LENGTH+1)]
Definition: gammu-file.h:90
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
GSM_Error DCT3DCT4_GetModel(GSM_StateMachine *s)
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
Definition: coding.c:1192
int Level
Definition: gammu-file.h:82
#define NOTSUPPORTED
Definition: gsmcomon.h:14
GSM_Error DCT4_Reset(GSM_StateMachine *s, gboolean hard)
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
Definition: gsmstate.c:1131
#define NONEFUNCTION
Definition: gsmcomon.h:12
GSM_Error
Definition: gammu-error.h:23
GSM_Error NoneReply(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
Definition: pfunc.c:188
GSM_Error DCT4_GetHardware(GSM_StateMachine *s, char *value)
gboolean Folder
Definition: gammu-file.h:78
gboolean ReadOnly
Definition: gammu-file.h:111
unsigned char * Buffer
Definition: gammu-file.h:94
GSM_Error DCT4_GetIMEI(GSM_StateMachine *s)
GSM_File * File
Definition: gsmstate.h:642
GSM_Error DCT4_ReplyGetIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
gboolean Protected
Definition: gammu-file.h:107
size_t Used
Definition: gammu-file.h:70
gboolean System
Definition: gammu-file.h:119
GSM_Error DCT3DCT4_GetFirmware(GSM_StateMachine *s)
int gboolean
Definition: gammu-types.h:23
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
struct GSM_Phone_Data::@2 Priv
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
#define N7110_FRAME_HEADER
Definition: ncommon.h:9
#define NOTIMPLEMENTED
Definition: gsmcomon.h:13
GSM_Phone_Data Data
Definition: gsmstate.h:1369
GSM_Error NOKIA_ReplyGetPhoneString(GSM_Protocol_Message *msg, GSM_StateMachine *s)
GSM_Error DCT4_ReplyGetPhoneMode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
GSM_Error NOKIA_GetManufacturer(GSM_StateMachine *s)
#define TRUE
Definition: gammu-types.h:28
GSM_File * Files[10000]
Definition: n3650.h:20
GSM_File * FileInfo
Definition: gsmstate.h:638
int FilesLocationsUsed
Definition: n3650.h:18
unsigned char * Buffer
Definition: protocol.h:22
#define UNUSED
Definition: gammu-misc.h:105
GSM_Error DCT4_GetProductCode(GSM_StateMachine *s, char *value)
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
gboolean Hidden
Definition: gammu-file.h:115
int FilesLocationsCurrent
Definition: n3650.h:19