Diffstat (limited to 'gammu/emb/common/phone/nokia/dct4/n3650.c') (more/less context) (show whitespace changes)
-rw-r--r-- | gammu/emb/common/phone/nokia/dct4/n3650.c | 392 |
1 files changed, 392 insertions, 0 deletions
diff --git a/gammu/emb/common/phone/nokia/dct4/n3650.c b/gammu/emb/common/phone/nokia/dct4/n3650.c new file mode 100644 index 0000000..2da55bf --- a/dev/null +++ b/gammu/emb/common/phone/nokia/dct4/n3650.c | |||
@@ -0,0 +1,392 @@ | |||
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 "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) | ||
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 | sprintf(StartReq+10,"%s",File->ID_FullName); | ||
62 | len+=strlen(File->ID_FullName)-1; | ||
63 | StartReq[7] = strlen(File->ID_FullName) + 3; | ||
64 | |||
65 | StartReq[8] = strlen(File->ID_FullName); | ||
66 | StartReq[9] = 0; | ||
67 | while (File->ID_FullName[StartReq[8]] != '\\') { | ||
68 | StartReq[8]--; | ||
69 | StartReq[9]++; | ||
70 | } | ||
71 | for (i=StartReq[8];i<strlen(File->ID_FullName);i++) { | ||
72 | StartReq[i+10] = StartReq[i+1+10]; | ||
73 | } | ||
74 | StartReq[9]--; | ||
75 | |||
76 | EncodeUnicode(File->Name,File->ID_FullName+StartReq[8]+1,StartReq[9]); | ||
77 | File->Folder = false; | ||
78 | |||
79 | error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); | ||
80 | if (error != ERR_NONE) return error; | ||
81 | |||
82 | s->Phone.Data.File = File; | ||
83 | return GSM_WaitFor (s, StartReq, len, 0x58, 4, ID_GetFile); | ||
84 | } | ||
85 | |||
86 | s->Phone.Data.File = File; | ||
87 | error = GSM_WaitFor (s, ContinueReq, 14, 0x58, 4, ID_GetFile); | ||
88 | |||
89 | //if (error == GE_EMPTY) { | ||
90 | // error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL); | ||
91 | // if (error != ERR_NONE) return error; | ||
92 | // return GE_EMPTY; | ||
93 | //} | ||
94 | |||
95 | return error; | ||
96 | } | ||
97 | |||
98 | static GSM_Error N3650_ReplyGetFolderInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
99 | { | ||
100 | GSM_File *File = s->Phone.Data.FileInfo; | ||
101 | GSM_Phone_N3650Data*Priv = &s->Phone.Data.Priv.N3650; | ||
102 | int i,pos = 6; | ||
103 | |||
104 | i = Priv->FilesLocationsUsed-1; | ||
105 | while (1) { | ||
106 | if (i==Priv->FilesLocationsCurrent-1) break; | ||
107 | dbgprintf("Copying %i to %i, max %i, current %i\n", | ||
108 | i,i+msg.Buffer[5], | ||
109 | Priv->FilesLocationsUsed,Priv->FilesLocationsCurrent); | ||
110 | memcpy(Priv->Files[i+msg.Buffer[5]],Priv->Files[i],sizeof(GSM_File)); | ||
111 | i--; | ||
112 | } | ||
113 | Priv->FileEntries = msg.Buffer[5]; | ||
114 | Priv->FilesLocationsUsed += msg.Buffer[5]; | ||
115 | for (i=0;i<msg.Buffer[5];i++) { | ||
116 | Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = true; | ||
117 | if (msg.Buffer[pos+2] == 0x01) { | ||
118 | Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = false; | ||
119 | smprintf(s,"File "); | ||
120 | } | ||
121 | EncodeUnicode(Priv->Files[Priv->FilesLocationsCurrent+i]->Name,msg.Buffer+pos+9,msg.Buffer[pos+8]); | ||
122 | smprintf(s,"%s\n",DecodeUnicodeString(Priv->Files[Priv->FilesLocationsCurrent+i]->Name)); | ||
123 | Priv->Files[Priv->FilesLocationsCurrent+i]->Level = File->Level+1; | ||
124 | sprintf(Priv->Files[Priv->FilesLocationsCurrent+i]->ID_FullName,"%s\\%s",File->ID_FullName,msg.Buffer+pos+9); | ||
125 | pos+=msg.Buffer[pos+1]; | ||
126 | } | ||
127 | dbgprintf("\n"); | ||
128 | return ERR_NONE; | ||
129 | } | ||
130 | |||
131 | static GSM_Error N3650_GetFolderInfo(GSM_StateMachine *s, GSM_File *File) | ||
132 | { | ||
133 | int len=10; | ||
134 | unsigned char req[500] = { | ||
135 | N7110_FRAME_HEADER, 0x0B, 0x00, 0x01, 0x07, | ||
136 | 0x18, /* folder name length + 6 */ | ||
137 | 0x12, /* folder name length */ | ||
138 | 0x00, | ||
139 | 0x00}; /* folder name */ | ||
140 | |||
141 | sprintf(req+10,File->ID_FullName); | ||
142 | len +=strlen(File->ID_FullName); | ||
143 | req[7] = strlen(File->ID_FullName) + 6; | ||
144 | req[8] = strlen(File->ID_FullName); | ||
145 | req[len++] = 0x00; | ||
146 | req[len++] = 0x00; | ||
147 | |||
148 | s->Phone.Data.FileInfo = File; | ||
149 | return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile); | ||
150 | } | ||
151 | |||
152 | static GSM_Error N3650_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, bool start) | ||
153 | { | ||
154 | GSM_Error error; | ||
155 | GSM_Phone_N3650Data*Priv = &s->Phone.Data.Priv.N3650; | ||
156 | |||
157 | if (start) { | ||
158 | error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); | ||
159 | if (error != ERR_NONE) return error; | ||
160 | |||
161 | Priv->Files[0]->Folder = true; | ||
162 | Priv->Files[0]->Level = 1; | ||
163 | Priv->Files[0]->Name[0] = 0; | ||
164 | Priv->Files[0]->Name[1] = 0; | ||
165 | Priv->Files[0]->ID_FullName[0]= 'Z'; | ||
166 | Priv->Files[0]->ID_FullName[1]= ':'; | ||
167 | Priv->Files[0]->ID_FullName[2]= 0; | ||
168 | |||
169 | Priv->Files[1]->Folder = true; | ||
170 | Priv->Files[1]->Level = 1; | ||
171 | Priv->Files[1]->Name[0] = 0; | ||
172 | Priv->Files[1]->Name[1] = 0; | ||
173 | Priv->Files[1]->ID_FullName[0]= 'E'; | ||
174 | Priv->Files[1]->ID_FullName[1]= ':'; | ||
175 | Priv->Files[1]->ID_FullName[2]= 0; | ||
176 | |||
177 | Priv->Files[2]->Folder = true; | ||
178 | Priv->Files[2]->Level = 1; | ||
179 | Priv->Files[2]->Name[0] = 0; | ||
180 | Priv->Files[2]->Name[1] = 0; | ||
181 | Priv->Files[2]->ID_FullName[0]= 'C'; | ||
182 | Priv->Files[2]->ID_FullName[1]= ':'; | ||
183 | Priv->Files[2]->ID_FullName[2]= 0; | ||
184 | |||
185 | Priv->FilesLocationsUsed = 3; | ||
186 | Priv->FilesLocationsCurrent = 0; | ||
187 | Priv->FileLev = 1; | ||
188 | } | ||
189 | |||
190 | if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) { | ||
191 | // error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL); | ||
192 | // if (error != ERR_NONE) return error; | ||
193 | |||
194 | return ERR_EMPTY; | ||
195 | } | ||
196 | |||
197 | strcpy(File->ID_FullName,Priv->Files[Priv->FilesLocationsCurrent]->ID_FullName); | ||
198 | File->Level= Priv->Files[Priv->FilesLocationsCurrent]->Level; | ||
199 | File->Folder= Priv->Files[Priv->FilesLocationsCurrent]->Folder; | ||
200 | CopyUnicodeString(File->Name,Priv->Files[Priv->FilesLocationsCurrent]->Name); | ||
201 | Priv->FilesLocationsCurrent++; | ||
202 | |||
203 | if (!File->Folder) return ERR_NONE; | ||
204 | |||
205 | if (Priv->FilesLocationsCurrent > 1) { | ||
206 | if (File->ID_FullName[0]!=Priv->Files[Priv->FilesLocationsCurrent-2]->ID_FullName[0]) { | ||
207 | if (File->ID_FullName[0] == 'E') { | ||
208 | error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); | ||
209 | error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); | ||
210 | } | ||
211 | if (File->ID_FullName[0] == 'C') { | ||
212 | error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); | ||
213 | error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); | ||
214 | } | ||
215 | // if (error != ERR_NONE) return error; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | File->ReadOnly = false; | ||
220 | File->System = false; | ||
221 | File->Protected = false; | ||
222 | File->Hidden = false; | ||
223 | |||
224 | return N3650_GetFolderInfo(s, File); | ||
225 | } | ||
226 | |||
227 | static GSM_Error N3650_Initialise (GSM_StateMachine *s) | ||
228 | { | ||
229 | GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650; | ||
230 | int i; | ||
231 | |||
232 | for (i=0;i<10000;i++) { | ||
233 | Priv->Files[i] = malloc(sizeof(GSM_File)); | ||
234 | if (Priv->Files[i] == NULL) return ERR_MOREMEMORY; | ||
235 | } | ||
236 | return ERR_NONE; | ||
237 | } | ||
238 | |||
239 | static GSM_Error N3650_Terminate(GSM_StateMachine *s) | ||
240 | { | ||
241 | GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650; | ||
242 | int i; | ||
243 | |||
244 | for (i=0;i<10000;i++) free(Priv->Files[i]); | ||
245 | return ERR_NONE; | ||
246 | } | ||
247 | |||
248 | static GSM_Reply_Function N3650ReplyFunctions[] = { | ||
249 | {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset }, | ||
250 | {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset }, | ||
251 | {NoneReply, "\x15",0x03,0x68,ID_Reset }, | ||
252 | |||
253 | {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI }, | ||
254 | {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware }, | ||
255 | {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode }, | ||
256 | |||
257 | {N3650_ReplyGetFolderInfo, "\x58",0x03,0x0C,ID_GetFile }, | ||
258 | {N3650_ReplyGetFilePart, "\x58",0x03,0x0E,ID_GetFile }, | ||
259 | |||
260 | {NULL, "\x00",0x00,0x00,ID_None } | ||
261 | }; | ||
262 | |||
263 | GSM_Phone_Functions N3650Phone = { | ||
264 | "3650|NGAGE", | ||
265 | N3650ReplyFunctions, | ||
266 | N3650_Initialise, | ||
267 | N3650_Terminate, | ||
268 | GSM_DispatchMessage, | ||
269 | NOTSUPPORTED, /* ShowStartInfo */ | ||
270 | NOKIA_GetManufacturer, | ||
271 | DCT3DCT4_GetModel, | ||
272 | DCT3DCT4_GetFirmware, | ||
273 | DCT4_GetIMEI, | ||
274 | NOTSUPPORTED, /* GetOriginalIMEI */ | ||
275 | NOTSUPPORTED, /* GetManufactureMonth*/ | ||
276 | DCT4_GetProductCode, | ||
277 | DCT4_GetHardware, | ||
278 | NOTSUPPORTED, /* GetPPM */ | ||
279 | NOTSUPPORTED, /* GetSIMIMSI */ | ||
280 | NOTSUPPORTED, /* GetDateTime */ | ||
281 | NOTSUPPORTED, /* SetDateTime */ | ||
282 | NOTSUPPORTED, /* GetAlarm */ | ||
283 | NOTSUPPORTED, /* SetAlarm */ | ||
284 | NOTSUPPORTED, /* GetLocale */ | ||
285 | NOTSUPPORTED, /* SetLocale */ | ||
286 | NOTSUPPORTED, /* PressKey */ | ||
287 | DCT4_Reset, | ||
288 | NOTSUPPORTED, /* ResetPhoneSettings*/ | ||
289 | NOTSUPPORTED, /* EnterSecurityCode*/ | ||
290 | NOTSUPPORTED, /* GetSecurityStatus*/ | ||
291 | NOTSUPPORTED, /* GetDisplayStatus*/ | ||
292 | NOTSUPPORTED, /* SetAutoNetworkLogin*/ | ||
293 | NOTSUPPORTED, /* GetBatteryCharge*/ | ||
294 | NOTSUPPORTED, /* GetSignalQuality*/ | ||
295 | NOTSUPPORTED, /* GetNetworkInfo */ | ||
296 | NOTSUPPORTED, /* GetCategory */ | ||
297 | NOTSUPPORTED, /* AddCategory */ | ||
298 | NOTSUPPORTED, /* GetCategoryStatus */ | ||
299 | NOTSUPPORTED, /* GetMemoryStatus */ | ||
300 | NOTSUPPORTED, /* GetMemory */ | ||
301 | NOTSUPPORTED, /* GetNextMemory */ | ||
302 | NOTSUPPORTED, /* SetMemory */ | ||
303 | NOTSUPPORTED, /* AddMemory */ | ||
304 | NOTSUPPORTED, /* DeleteMemory */ | ||
305 | NOTIMPLEMENTED, /* DeleteAllMemory */ | ||
306 | NOTSUPPORTED, /* GetSpeedDial */ | ||
307 | NOTSUPPORTED, /* SetSpeedDial */ | ||
308 | NOTSUPPORTED, /* GetSMSC */ | ||
309 | NOTSUPPORTED, /* SetSMSC */ | ||
310 | NOTSUPPORTED, /* GetSMSStatus */ | ||
311 | NOTSUPPORTED, /* GetSMS */ | ||
312 | NOTSUPPORTED, /* GetNextSMS */ | ||
313 | NOTSUPPORTED, /* SetSMS */ | ||
314 | NOTSUPPORTED, /* AddSMS */ | ||
315 | NOTSUPPORTED, /* DeleteSMS */ | ||
316 | NOTSUPPORTED, /* SendSMS */ | ||
317 | NOTSUPPORTED, /* SendSavedSMS */ | ||
318 | NOTSUPPORTED, /* SetIncomingSMS */ | ||
319 | NOTSUPPORTED, /* SetIncomingCB */ | ||
320 | NOTSUPPORTED, /* GetSMSFolders */ | ||
321 | NOTSUPPORTED, /* AddSMSFolder */ | ||
322 | NOTSUPPORTED, /* DeleteSMSFolder */ | ||
323 | NOTIMPLEMENTED, /* DialVoice */ | ||
324 | NOTIMPLEMENTED, /* AnswerCall */ | ||
325 | NOTIMPLEMENTED, /* CancelCall */ | ||
326 | NOTIMPLEMENTED, /* HoldCall */ | ||
327 | NOTIMPLEMENTED, /* UnholdCall */ | ||
328 | NOTIMPLEMENTED, /* ConferenceCall */ | ||
329 | NOTIMPLEMENTED, /* SplitCall */ | ||
330 | NOTIMPLEMENTED, /* TransferCall */ | ||
331 | NOTIMPLEMENTED, /* SwitchCall */ | ||
332 | NOTSUPPORTED, /* GetCallDivert */ | ||
333 | NOTSUPPORTED, /* SetCallDivert */ | ||
334 | NOTSUPPORTED, /* CancelAllDiverts*/ | ||
335 | NOTIMPLEMENTED, /* SetIncomingCall */ | ||
336 | NOTIMPLEMENTED, /* SetIncomingUSSD */ | ||
337 | NOTSUPPORTED, /* SendDTMF */ | ||
338 | NOTSUPPORTED, /* GetRingtone */ | ||
339 | NOTSUPPORTED, /* SetRingtone */ | ||
340 | NOTSUPPORTED, /* GetRingtonesInfo*/ | ||
341 | NOTIMPLEMENTED, /* DeleteUserRingtones*/ | ||
342 | NOTSUPPORTED, /* PlayTone */ | ||
343 | NOTSUPPORTED, /* GetWAPBookmark */ | ||
344 | NOTSUPPORTED, /* SetWAPBookmark */ | ||
345 | NOTSUPPORTED, /* DeleteWAPBookmark */ | ||
346 | NOTSUPPORTED, /* GetWAPSettings */ | ||
347 | NOTSUPPORTED, /* SetWAPSettings */ | ||
348 | NOTSUPPORTED, /* GetMMSSettings */ | ||
349 | NOTSUPPORTED, /* SetMMSSettings */ | ||
350 | NOTSUPPORTED, /* GetSyncMLSettings*/ | ||
351 | NOTSUPPORTED, /* SetSyncMLSettings*/ | ||
352 | NOTSUPPORTED, /* GetChatSettings */ | ||
353 | NOTSUPPORTED, /* SetChatSettings */ | ||
354 | NOTSUPPORTED, /* GetBitmap */ | ||
355 | NOTSUPPORTED, /* SetBitmap */ | ||
356 | NOTSUPPORTED, /* GetToDoStatus */ | ||
357 | NOTSUPPORTED, /* GetToDo */ | ||
358 | NOTSUPPORTED, /* GetNextToDo */ | ||
359 | NOTSUPPORTED, /* SetToDo */ | ||
360 | NOTSUPPORTED, /* AddToDo */ | ||
361 | NOTSUPPORTED, /* DeleteToDo */ | ||
362 | NOTSUPPORTED, /* DeleteAllToDo */ | ||
363 | NOTIMPLEMENTED, /* GetCalendarStatus*/ | ||
364 | NOTIMPLEMENTED, /* GetCalendar */ | ||
365 | NOTSUPPORTED, /* GetNextCalendar */ | ||
366 | NOTIMPLEMENTED, /* SetCalendar */ | ||
367 | NOTSUPPORTED, /* AddCalendar */ | ||
368 | NOTSUPPORTED, /* DeleteCalendar */ | ||
369 | NOTIMPLEMENTED, /* DeleteAllCalendar*/ | ||
370 | NOTSUPPORTED, /* GetCalendarSettings*/ | ||
371 | NOTSUPPORTED, /* SetCalendarSettings*/ | ||
372 | NOTSUPPORTED, /* GetNote */ | ||
373 | NOTSUPPORTED, /* GetProfile */ | ||
374 | NOTSUPPORTED, /* SetProfile */ | ||
375 | NOTSUPPORTED, /* GetFMStation */ | ||
376 | NOTSUPPORTED, /* SetFMStation */ | ||
377 | NOTSUPPORTED, /* ClearFMStations */ | ||
378 | N3650_GetNextFileFolder, | ||
379 | N3650_GetFilePart, | ||
380 | NOTIMPLEMENTED, /* AddFilePart */ | ||
381 | NOTSUPPORTED, /* GetFileSystemStatus*/ | ||
382 | NOTIMPLEMENTED, /* DeleteFile */ | ||
383 | NOTIMPLEMENTED, /* AddFolder */ | ||
384 | NOTSUPPORTED, /* GetGPRSAccessPoint*/ | ||
385 | NOTSUPPORTED /* SetGPRSAccessPoint*/ | ||
386 | }; | ||
387 | |||
388 | #endif | ||
389 | |||
390 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
391 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
392 | */ | ||