Diffstat (limited to 'gammu/emb/common/phone/at/sonyeric.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/phone/at/sonyeric.c | 411 |
1 files changed, 411 insertions, 0 deletions
diff --git a/gammu/emb/common/phone/at/sonyeric.c b/gammu/emb/common/phone/at/sonyeric.c new file mode 100644 index 0000000..4b2670a --- a/dev/null +++ b/gammu/emb/common/phone/at/sonyeric.c | |||
@@ -0,0 +1,411 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | |||
3 | #include "../../gsmstate.h" | ||
4 | |||
5 | #ifdef GSM_ENABLE_ATGEN | ||
6 | |||
7 | #include <string.h> | ||
8 | #include <time.h> | ||
9 | #include <ctype.h> | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "../../misc/coding/coding.h" | ||
13 | |||
14 | extern GSM_Reply_Function ATGENReplyFunctions[]; | ||
15 | extern GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s); | ||
16 | |||
17 | #ifdef GSM_ENABLE_OBEXGEN | ||
18 | |||
19 | extern GSM_Reply_Function OBEXGENReplyFunctions[]; | ||
20 | extern GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File); | ||
21 | extern GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos); | ||
22 | extern GSM_Error OBEXGEN_Disconnect(GSM_StateMachine *s); | ||
23 | |||
24 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
25 | |||
26 | static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s) | ||
27 | { | ||
28 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
29 | GSM_Error error; | ||
30 | |||
31 | if (Priv->OBEX) return ERR_NONE; | ||
32 | |||
33 | dbgprintf ("Changing to OBEX\n"); | ||
34 | |||
35 | error=GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 4, ID_SetOBEX); | ||
36 | if (error != ERR_NONE) return error; | ||
37 | |||
38 | error = s->Protocol.Functions->Terminate(s); | ||
39 | if (error != ERR_NONE) return error; | ||
40 | |||
41 | s->Protocol.Functions = &OBEXProtocol; | ||
42 | error = s->Protocol.Functions->Initialise(s); | ||
43 | if (error != ERR_NONE) { | ||
44 | s->Protocol.Functions = &ATProtocol; | ||
45 | return error; | ||
46 | } | ||
47 | strcpy(s->CurrentConfig->Model,"seobex"); | ||
48 | s->Phone.Data.Priv.OBEXGEN.Service = 0; | ||
49 | s->Phone.Functions->DispatchMessage= GSM_DispatchMessage; | ||
50 | s->Phone.Functions->ReplyFunctions= OBEXGENReplyFunctions; | ||
51 | Priv->OBEX = true; | ||
52 | return ERR_NONE; | ||
53 | } | ||
54 | |||
55 | static GSM_Error SONYERIC_SetATMode(GSM_StateMachine *s) | ||
56 | { | ||
57 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
58 | GSM_Error error; | ||
59 | |||
60 | if (!Priv->OBEX) return ERR_NONE; | ||
61 | |||
62 | dbgprintf ("Changing to AT\n"); | ||
63 | |||
64 | error = OBEXGEN_Disconnect(s); | ||
65 | if (error != ERR_NONE) return error; | ||
66 | |||
67 | error = s->Protocol.Functions->Terminate(s); | ||
68 | if (error != ERR_NONE) return error; | ||
69 | |||
70 | s->Protocol.Functions = &ATProtocol; | ||
71 | error = s->Protocol.Functions->Initialise(s); | ||
72 | if (error != ERR_NONE) { | ||
73 | s->Protocol.Functions = &OBEXProtocol; | ||
74 | return error; | ||
75 | } | ||
76 | strcpy(s->CurrentConfig->Model,"at"); | ||
77 | s->Phone.Functions->DispatchMessage= ATGEN_DispatchMessage; | ||
78 | s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; | ||
79 | Priv->OBEX = false; | ||
80 | return ERR_NONE; | ||
81 | } | ||
82 | |||
83 | static GSM_Error SONYERIC_GetFile(GSM_StateMachine *s, GSM_File *File, unsigned char *FileName) | ||
84 | { | ||
85 | GSM_Error error; | ||
86 | |||
87 | strcpy(File->ID_FullName,FileName); | ||
88 | File->Used = 0; | ||
89 | if (File->Buffer != NULL) free(File->Buffer); | ||
90 | File->Buffer = NULL; | ||
91 | |||
92 | error = SONYERIC_SetOBEXMode(s); | ||
93 | if (error != ERR_NONE) return error; | ||
94 | |||
95 | error = ERR_NONE; | ||
96 | while (error == ERR_NONE) error = OBEXGEN_GetFilePart(s,File); | ||
97 | if (error != ERR_EMPTY) return error; | ||
98 | |||
99 | return SONYERIC_SetATMode(s); | ||
100 | } | ||
101 | |||
102 | static GSM_Error SONYERIC_SetFile(GSM_StateMachine *s, unsigned char *FileName, unsigned char *Buffer, int Length) | ||
103 | { | ||
104 | GSM_Errorerror; | ||
105 | GSM_File File; | ||
106 | int Pos = 0; | ||
107 | |||
108 | error = SONYERIC_SetOBEXMode(s); | ||
109 | if (error != ERR_NONE) return error; | ||
110 | |||
111 | strcpy(File.ID_FullName,FileName); | ||
112 | EncodeUnicode(File.Name,FileName,strlen(FileName)); | ||
113 | File.Used = Length; | ||
114 | File.Buffer = malloc(Length); | ||
115 | memcpy(File.Buffer,Buffer,Length); | ||
116 | |||
117 | error = ERR_NONE; | ||
118 | while (error == ERR_NONE) error = OBEXGEN_AddFilePart(s,&File,&Pos); | ||
119 | free(File.Buffer); | ||
120 | if (error != ERR_EMPTY) return error; | ||
121 | |||
122 | return SONYERIC_SetATMode(s); | ||
123 | } | ||
124 | |||
125 | #endif | ||
126 | |||
127 | GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) | ||
128 | { | ||
129 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
130 | GSM_Error error; | ||
131 | GSM_ToDoEntry ToDo; | ||
132 | int Pos, num, Loc; | ||
133 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
134 | |||
135 | if (start) { | ||
136 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
137 | if (error != ERR_NONE) return error; | ||
138 | |||
139 | Note->Location = 1; | ||
140 | } else { | ||
141 | Note->Location++; | ||
142 | } | ||
143 | smprintf(s, "Getting calendar note %i\n",Note->Location); | ||
144 | |||
145 | Loc = Note->Location; | ||
146 | Pos = 0; | ||
147 | num = 0; | ||
148 | while (1) { | ||
149 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, Note, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | ||
150 | if (error == ERR_EMPTY) break; | ||
151 | if (error != ERR_NONE) return error; | ||
152 | if (Note->EntriesNum != 0) { | ||
153 | num++; | ||
154 | if (num == Loc) return ERR_NONE; | ||
155 | } | ||
156 | } | ||
157 | return ERR_EMPTY; | ||
158 | #else | ||
159 | return ERR_SOURCENOTAVAILABLE; | ||
160 | #endif | ||
161 | } | ||
162 | |||
163 | GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) | ||
164 | { | ||
165 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
166 | GSM_Error error; | ||
167 | GSM_CalendarEntryCalendar; | ||
168 | int Pos, num, Loc; | ||
169 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
170 | |||
171 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | ||
172 | |||
173 | if (start) { | ||
174 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
175 | if (error != ERR_NONE) return error; | ||
176 | |||
177 | ToDo->Location = 1; | ||
178 | } else { | ||
179 | ToDo->Location++; | ||
180 | } | ||
181 | smprintf(s,"Getting ToDo %i\n",ToDo->Location); | ||
182 | |||
183 | Loc = ToDo->Location; | ||
184 | Pos = 0; | ||
185 | num = 0; | ||
186 | while (1) { | ||
187 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | ||
188 | if (error == ERR_EMPTY) break; | ||
189 | if (error != ERR_NONE) return error; | ||
190 | if (ToDo->EntriesNum != 0) { | ||
191 | num++; | ||
192 | if (num == Loc) return ERR_NONE; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | return ERR_EMPTY; | ||
197 | #else | ||
198 | return ERR_SOURCENOTAVAILABLE; | ||
199 | #endif | ||
200 | } | ||
201 | |||
202 | GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) | ||
203 | { | ||
204 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
205 | GSM_Error error; | ||
206 | GSM_ToDoEntry ToDo; | ||
207 | GSM_CalendarEntry Calendar; | ||
208 | int Pos; | ||
209 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
210 | |||
211 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | ||
212 | |||
213 | smprintf(s,"Getting ToDo status\n"); | ||
214 | |||
215 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
216 | if (error != ERR_NONE) return error; | ||
217 | |||
218 | status->Used = 0; | ||
219 | Pos = 0; | ||
220 | while (1) { | ||
221 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | ||
222 | if (error == ERR_EMPTY) break; | ||
223 | if (error != ERR_NONE) return error; | ||
224 | if (ToDo.EntriesNum != 0) status->Used++; | ||
225 | } | ||
226 | |||
227 | return ERR_NONE; | ||
228 | #else | ||
229 | return ERR_SOURCENOTAVAILABLE; | ||
230 | #endif | ||
231 | } | ||
232 | |||
233 | GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) | ||
234 | { | ||
235 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
236 | unsigned char req[5000]; | ||
237 | int size=0; | ||
238 | |||
239 | smprintf(s,"Adding calendar note\n"); | ||
240 | |||
241 | GSM_EncodeVCALENDAR(req,&size,Note,true,SonyEricsson_VCalendar); | ||
242 | |||
243 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); | ||
244 | #else | ||
245 | return ERR_SOURCENOTAVAILABLE; | ||
246 | #endif | ||
247 | } | ||
248 | |||
249 | GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) | ||
250 | { | ||
251 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
252 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
253 | unsigned char req[5000]; | ||
254 | int size=0; | ||
255 | |||
256 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | ||
257 | |||
258 | smprintf(s,"Adding ToDo\n"); | ||
259 | |||
260 | GSM_EncodeVTODO(req,&size,ToDo,true,SonyEricsson_VToDo); | ||
261 | |||
262 | return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); | ||
263 | #else | ||
264 | return ERR_SOURCENOTAVAILABLE; | ||
265 | #endif | ||
266 | } | ||
267 | |||
268 | GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) | ||
269 | { | ||
270 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
271 | GSM_Error error; | ||
272 | int Pos,Level = 0,Used; | ||
273 | unsigned char *Buf; | ||
274 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
275 | unsigned char Line[2000]; | ||
276 | |||
277 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | ||
278 | |||
279 | smprintf(s,"Deleting all ToDo\n"); | ||
280 | |||
281 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
282 | if (error != ERR_NONE) return error; | ||
283 | |||
284 | Pos = 0; | ||
285 | Buf = NULL; | ||
286 | Used = 0; | ||
287 | while (1) { | ||
288 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); | ||
289 | if (strlen(Line) == 0) break; | ||
290 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); | ||
291 | switch (Level) { | ||
292 | case 0: | ||
293 | if (strstr(Line,"BEGIN:VTODO")) { | ||
294 | Level = 2; | ||
295 | break; | ||
296 | } | ||
297 | Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3); | ||
298 | strcpy(Buf+Used,Line); | ||
299 | Used=Used+strlen(Line)+3; | ||
300 | Buf[Used-3] = 13; | ||
301 | Buf[Used-2] = 10; | ||
302 | Buf[Used-1] = 0x00; | ||
303 | break; | ||
304 | case 2: /* ToDo note */ | ||
305 | if (strstr(Line,"END:VTODO")) { | ||
306 | Level = 0; | ||
307 | } | ||
308 | break; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); | ||
313 | //if (Buf != NULL) free(Buf); | ||
314 | return error; | ||
315 | #else | ||
316 | return ERR_SOURCENOTAVAILABLE; | ||
317 | #endif | ||
318 | } | ||
319 | |||
320 | GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) | ||
321 | { | ||
322 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
323 | GSM_Error error; | ||
324 | int Pos,Level = 0,Loc=0,Used; | ||
325 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
326 | unsigned char Line[2000]; | ||
327 | unsigned char *Buf; | ||
328 | |||
329 | smprintf(s, "Deleting calendar note %i\n",Note->Location); | ||
330 | |||
331 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
332 | if (error != ERR_NONE) return error; | ||
333 | |||
334 | Pos = 0; | ||
335 | Buf = NULL; | ||
336 | Used = 0; | ||
337 | while (1) { | ||
338 | MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); | ||
339 | if (strlen(Line) == 0) break; | ||
340 | dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); | ||
341 | switch (Level) { | ||
342 | case 0: | ||
343 | if (strstr(Line,"BEGIN:VEVENT")) { | ||
344 | Loc++; | ||
345 | if (Loc == Note->Location) { | ||
346 | Level = 1; | ||
347 | break; | ||
348 | } | ||
349 | } | ||
350 | Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3); | ||
351 | strcpy(Buf+Used,Line); | ||
352 | Used=Used+strlen(Line)+3; | ||
353 | Buf[Used-3] = 13; | ||
354 | Buf[Used-2] = 10; | ||
355 | Buf[Used-1] = 0x00; | ||
356 | break; | ||
357 | case 1: /* Calendar note */ | ||
358 | if (strstr(Line,"END:VEVENT")) { | ||
359 | Level = 0; | ||
360 | } | ||
361 | break; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | DumpMessage(s->di.df, s->di.dl, Buf, Used); | ||
366 | |||
367 | error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); | ||
368 | if (Buf != NULL) free(Buf); | ||
369 | return error; | ||
370 | #else | ||
371 | return ERR_SOURCENOTAVAILABLE; | ||
372 | #endif | ||
373 | } | ||
374 | |||
375 | GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) | ||
376 | { | ||
377 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
378 | GSM_Error error; | ||
379 | GSM_ToDoEntry ToDo; | ||
380 | GSM_CalendarEntry Calendar; | ||
381 | int Pos; | ||
382 | GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; | ||
383 | |||
384 | if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; | ||
385 | |||
386 | smprintf(s, "Getting calendar status\n"); | ||
387 | |||
388 | error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); | ||
389 | if (error != ERR_NONE) return error; | ||
390 | |||
391 | Status->Used = 0; | ||
392 | Pos = 0; | ||
393 | while (1) { | ||
394 | error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); | ||
395 | if (error == ERR_EMPTY) break; | ||
396 | if (error != ERR_NONE) return error; | ||
397 | if (Calendar.EntriesNum != 0) Status->Used++; | ||
398 | } | ||
399 | |||
400 | return ERR_NONE; | ||
401 | #else | ||
402 | return ERR_SOURCENOTAVAILABLE; | ||
403 | #endif | ||
404 | } | ||
405 | |||
406 | #endif | ||
407 | #endif | ||
408 | |||
409 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
410 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
411 | */ | ||