summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/phone/nokia/nfuncold.c
Unidiff
Diffstat (limited to 'gammu/emb/common/phone/nokia/nfuncold.c') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/phone/nokia/nfuncold.c226
1 files changed, 226 insertions, 0 deletions
diff --git a/gammu/emb/common/phone/nokia/nfuncold.c b/gammu/emb/common/phone/nokia/nfuncold.c
new file mode 100644
index 0000000..0e40bc6
--- a/dev/null
+++ b/gammu/emb/common/phone/nokia/nfuncold.c
@@ -0,0 +1,226 @@
1/* (c) 2003 by Marcin Wiacek */
2
3#include <string.h> /* memcpy only */
4#include <stdio.h>
5#include <ctype.h>
6#include <time.h>
7
8#include "../../misc/coding/coding.h"
9#include "../../gsmstate.h"
10#include "../../service/sms/gsmsms.h"
11#include "../pfunc.h"
12#include "nfunc.h"
13
14#ifdef DEBUG
15static void N71_65_GetCalendarAlarm(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry, int DT, GSM_Phone_Data *Data)
16{
17 unsigned long diff;
18
19 if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0xff && buffer[3] == 0xff) {
20 smprintf(s, "No alarm\n");
21 } else {
22 memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[DT].Date,sizeof(GSM_DateTime));
23
24 diff = ((unsigned int)buffer[0]) << 24;
25 diff += ((unsigned int)buffer[1]) << 16;
26 diff += ((unsigned int)buffer[2]) << 8;
27 diff += buffer[3];
28 smprintf(s, " Difference : %li seconds\n", diff);
29
30 switch (entry->Type) {
31 case GSM_CAL_MEETING:
32 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 60);
33 break;
34 case GSM_CAL_MEMO:
35 if (!IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
36 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 60);
37 break;
38 }
39 case GSM_CAL_CALL:
40 if (!IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
41 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 60);
42 break;
43 }
44 default:
45 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 1);
46 }
47 smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
48 entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month,
49 entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour,
50 entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);
51
52 entry->Entries[entry->EntriesNum].EntryType = CAL_ALARM_DATETIME;
53 if (entry->Type == GSM_CAL_BIRTHDAY) {
54 if (buffer[14]!=0x00) entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
55 smprintf(s, "Alarm type : Silent\n");
56 }
57
58 entry->EntriesNum++;
59 }
60}
61
62/* method 2 */
63GSM_Error N71_65_ReplyGetNextCalendar2(GSM_Protocol_Message msg, GSM_StateMachine *s)
64{
65 GSM_DateTime Date;
66 GSM_CalendarEntry*entry = s->Phone.Data.Cal;
67 GSM_Phone_Data *Data = &s->Phone.Data;
68 int i;
69 unsigned long diff;
70
71 smprintf(s, "Calendar note received method 2\n");
72
73 if (msg.Length < 10) return ERR_EMPTY;
74
75 entry->Location = msg.Buffer[4]*256 + msg.Buffer[5];
76 smprintf(s, "Location: %i\n",entry->Location);
77
78 /* Not birthday */
79 if (msg.Buffer[21] != 0x04) {
80 Date.Year = 2030; Date.Month = 01; Date.Day = 01;
81 Date.Hour = 00; Date.Minute = 00; Date.Second = 00;
82 } else {
83 Date.Year = 2029; Date.Month = 12; Date.Day = 31;
84 Date.Hour = 22; Date.Minute = 59; Date.Second = 58;
85 }
86 diff = ((unsigned int)msg.Buffer[12]) << 24;
87 diff += ((unsigned int)msg.Buffer[13]) << 16;
88 diff += ((unsigned int)msg.Buffer[14]) << 8;
89 diff += msg.Buffer[15];
90 smprintf(s, " Difference : %li seconds\n", diff);
91 GetTimeDifference(diff, &Date, true, 1);
92 Date.Year += 20;
93 entry->Entries[0].EntryType = CAL_START_DATETIME;
94
95 smprintf(s, "Note type %02x: ",msg.Buffer[21]);
96 switch (msg.Buffer[21]) {
97 case 0x01:
98 case 0x08:
99 if (msg.Buffer[21] == 0x01) {
100 smprintf(s, "Meeting or Reminder\n");
101 entry->Type = GSM_CAL_MEETING;
102 } else {
103 smprintf(s, "Memo\n");
104 Data->Cal->Type = GSM_CAL_MEMO;
105 }
106
107 memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
108 entry->EntriesNum++;
109
110 N71_65_GetCalendarAlarm(s, msg.Buffer+16, entry, 0, Data);
111 N71_65_GetCalendarRecurrance(s, msg.Buffer+22, entry);
112
113 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+30, msg.Buffer[28]*2);
114 entry->Entries[entry->EntriesNum].Text[msg.Buffer[28]*2] = 0;
115 entry->Entries[entry->EntriesNum].Text[msg.Buffer[28]*2+1] = 0;
116 entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
117 break;
118 case 0x02:
119 smprintf(s, "Call\n");
120 entry->Type = GSM_CAL_CALL;
121
122 memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
123 entry->EntriesNum++;
124
125 N71_65_GetCalendarAlarm(s, msg.Buffer+16, entry, 0, Data);
126 N71_65_GetCalendarRecurrance(s, msg.Buffer+22, entry);
127
128 i = msg.Buffer[28] * 2;
129 if (i!=0) {
130 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+30, i);
131 entry->Entries[entry->EntriesNum].Text[i] = 0;
132 entry->Entries[entry->EntriesNum].Text[i+1] = 0;
133 entry->Entries[entry->EntriesNum].EntryType= CAL_PHONE;
134 smprintf(s, "Phone : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
135 entry->EntriesNum++;
136 }
137
138 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+30+i, msg.Buffer[29]*2);
139 entry->Entries[entry->EntriesNum].Text[msg.Buffer[29]*2] = 0;
140 entry->Entries[entry->EntriesNum].Text[msg.Buffer[29]*2+1] = 0;
141 entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
142 break;
143 case 0x04:
144 smprintf(s, "Birthday\n");
145 Data->Cal->Type = GSM_CAL_BIRTHDAY;
146
147 /* Year was set earlier */
148 entry->Entries[0].Date.Month= Date.Month;
149 entry->Entries[0].Date.Day= Date.Day;
150 entry->Entries[0].Date.Hour= 23;
151 entry->Entries[0].Date.Minute= 59;
152 entry->Entries[0].Date.Second= 58;
153 entry->EntriesNum++;
154
155 N71_65_GetCalendarAlarm(s, msg.Buffer+16, entry, 0, Data);
156 N71_65_GetCalendarRecurrance(s, msg.Buffer+22, entry);
157
158 /* Birthday year */
159 entry->Entries[0].Date.Year = msg.Buffer[28]*256 + msg.Buffer[29];
160 if (msg.Buffer[28] == 0xff && msg.Buffer[29] == 0xff) entry->Entries[0].Date.Year = 0;
161 smprintf(s, "Birthday date: %02i-%02i-%04i\n",
162 entry->Entries[0].Date.Day,entry->Entries[0].Date.Month,
163 entry->Entries[0].Date.Year);
164
165 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+32, msg.Buffer[31]*2);
166 entry->Entries[entry->EntriesNum].Text[msg.Buffer[31]*2] = 0;
167 entry->Entries[entry->EntriesNum].Text[msg.Buffer[31]*2+1] = 0;
168 entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
169 break;
170 default:
171 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[6]);
172 return ERR_UNKNOWNRESPONSE;
173 }
174 smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
175 entry->EntriesNum++;
176 return ERR_NONE;
177}
178
179/* method 2 */
180/* Note: in known phones texts of notes cut to 50 chars */
181GSM_Error N71_65_GetNextCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start, int *LastCalendarYear, int *LastCalendarPos)
182{
183 GSM_Error error;
184 GSM_DateTime date_time;
185 unsigned char req[] = {N6110_FRAME_HEADER, 0x3e,
186 0xFF, 0xFE}; /* Location */
187
188 if (start) {
189 /* We have to get current year. It's NOT written in frame for
190 * Birthday
191 */
192 error=s->Phone.Functions->GetDateTime(s,&date_time);
193 switch (error) {
194 case ERR_EMPTY:
195 case ERR_NOTIMPLEMENTED:
196 GSM_GetCurrentDateTime(&date_time);
197 break;
198 case ERR_NONE:
199 break;
200 default:
201 return error;
202 }
203 *LastCalendarYear = date_time.Year;
204
205 /* First location at all */
206 req[4] = 0xFF;
207 req[5] = 0xFE;
208 } else {
209 req[4] = *LastCalendarPos / 256;
210 req[5] = *LastCalendarPos % 256;
211 }
212 Note->EntriesNum = 0;
213 Note->Entries[0].Date.Year = *LastCalendarYear;
214
215 s->Phone.Data.Cal = Note;
216 smprintf(s, "Getting calendar note method 2\n");
217 error=GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNote);
218 *LastCalendarPos = Note->Location;
219 return error;
220}
221
222#endif
223
224/* How should editor hadle tabs in this file? Add editor commands here.
225 * vim: noexpandtab sw=8 ts=8 sts=8:
226 */