2 #include "../../gsmstate.h"
4 #ifdef GSM_ENABLE_ATGEN
10 #include "../../misc/coding/coding.h"
11 #include "../../gsmcomon.h"
12 #include "../../service/sms/gsmsms.h"
15 extern GSM_Error
ATGEN_HandleCMSError(GSM_StateMachine
*s
);
17 GSM_Error
ATGEN_CMS35ReplySetFunction (GSM_Protocol_Message msg
, GSM_StateMachine
*s
,char *function
)
19 if (s
->Protocol
.Data
.AT
.EditMode
) {
20 s
->Protocol
.Data
.AT
.EditMode
= false;
23 dbgprintf ("Written %s",function
);
24 if (s
->Phone
.Data
.Priv
.ATGEN
.ReplyState
== AT_Reply_OK
){
25 dbgprintf (" - OK\n");
28 dbgprintf (" - error\n");
33 GSM_Error
GetSiemensFrame(GSM_Protocol_Message msg
, GSM_StateMachine
*s
, char *templ
,
34 unsigned char *buffer
, int *len
)
36 GSM_Phone_ATGENData
*Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
37 int i
=2, pos
=0, length
=0;
38 unsigned char buf
[512];
40 if (strstr(GetLineString(msg
.Buffer
,Priv
->Lines
,2),"OK")) return GE_EMPTY
;
41 if (!strstr(GetLineString(msg
.Buffer
,Priv
->Lines
,2),templ
)) return GE_UNKNOWN
;
44 if (Priv
->Lines
.numbers
[i
*2+1]==0) break;
45 if ((!strstr(GetLineString(msg
.Buffer
,Priv
->Lines
,i
+1),templ
)) &&
46 (strstr(GetLineString(msg
.Buffer
,Priv
->Lines
,i
),templ
))){
47 length
= strlen(GetLineString(msg
.Buffer
,Priv
->Lines
,i
+1));
48 DecodeHexBin(buf
, GetLineString(msg
.Buffer
,Priv
->Lines
,i
+1),length
);
50 memcpy (buffer
+pos
,buf
,length
);
59 GSM_Error
SetSiemensFrame (GSM_StateMachine
*s
, unsigned char *buff
, char *templ
,
60 int Location
, GSM_Phone_RequestID RequestID
, int len
)
62 GSM_Phone_Data
*Phone
= &s
->Phone
.Data
;
64 unsigned char req
[20],req1
[512],hexreq
[2096];
65 int MaxFrame
,CurrentFrame
,size
,sz
,pos
=0;
67 EncodeHexBin(hexreq
,buff
,len
);
69 MaxFrame
= size
/ 352;
70 if (size
% 352) MaxFrame
++;
72 for (CurrentFrame
=0;CurrentFrame
<MaxFrame
;CurrentFrame
++)
75 if (pos
+352 < size
) sz
= 352; else sz
= size
- pos
;
76 sprintf(req
, "AT^SBNW=\"%s\",%i,%i,%i\r",templ
,Location
,CurrentFrame
+1,MaxFrame
);
77 s
->Protocol
.Data
.AT
.EditMode
= true;
78 error
= GSM_WaitFor (s
, req
, strlen(req
), 0x00, 3, RequestID
);
79 s
->Phone
.Data
.DispatchError
=GE_TIMEOUT
;
80 s
->Phone
.Data
.RequestID
=RequestID
;
81 if (error
!=GE_NONE
) return error
;
82 memcpy (req1
,hexreq
+pos
,sz
);
83 error
= s
->Protocol
.Functions
->WriteMessage(s
, req1
, sz
, 0x00);
84 if (error
!=GE_NONE
) return error
;
85 error
= s
->Protocol
.Functions
->WriteMessage(s
,"\x1A", 1, 0x00);
86 if (error
!=GE_NONE
) return error
;
87 error
= GSM_WaitForOnce(s
, NULL
, 0x00, 0x00, 4);
88 if (error
== GE_TIMEOUT
) return error
;
90 return Phone
->DispatchError
;
93 GSM_Error
ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
95 unsigned char buffer
[4096];
99 error
= GetSiemensFrame(msg
,s
,"bmp",buffer
,&length
);
100 if (error
!=GE_NONE
) return error
;
101 dbgprintf ("Operator logo received lenght=%i\n",length
);
102 error
= BMP2Bitmap (buffer
,NULL
,s
->Phone
.Data
.Bitmap
);
103 if (error
==GE_NONE
) return error
;
104 else return GE_UNKNOWN
;
107 GSM_Error
ATGEN_CMS35ReplySetBitmap(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
109 return ATGEN_CMS35ReplySetFunction (msg
, s
, "Operator Logo");
112 GSM_Error
ATGEN_GetBitmap(GSM_StateMachine
*s
, GSM_Bitmap
*Bitmap
)
114 unsigned char req
[32];
116 if (s
->Phone
.Data
.Priv
.ATGEN
.Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
117 if (Bitmap
->Type
!=GSM_OperatorLogo
) return GE_NOTSUPPORTED
;
118 if (Bitmap
->Location
-1 < 0) Bitmap
->Location
++;
119 s
->Phone
.Data
.Bitmap
=Bitmap
;
120 sprintf(req
, "AT^SBNR=\"bmp\",%i\r", Bitmap
->Location
-1);
121 smprintf(s
, "Getting Bitmap\n");
122 return GSM_WaitFor (s
, req
, strlen(req
), 0x00, 4, ID_GetBitmap
);
125 GSM_Error
ATGEN_SetBitmap(GSM_StateMachine
*s
, GSM_Bitmap
*Bitmap
)
127 unsigned char buffer
[4096];
131 if (s
->Phone
.Data
.Priv
.ATGEN
.Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
132 if (Bitmap
->Type
!=GSM_OperatorLogo
) return GE_NOTSUPPORTED
;
134 error
= Bitmap2BMP (buffer
,NULL
,Bitmap
);
135 if (error
!=GE_NONE
) return error
;
136 length
= 0x100 * buffer
[3] + buffer
[2];
137 buffer
[58]=0xff; buffer
[59]=0xff; buffer
[60]=0xff;
138 if (Bitmap
->Location
-1 < 0) Bitmap
->Location
++;
139 s
->Phone
.Data
.Bitmap
=Bitmap
;
140 return SetSiemensFrame(s
, buffer
,"bmp",Bitmap
->Location
-1,
141 ID_SetBitmap
,length
);
145 GSM_Error
ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
147 unsigned char buffer
[32];
151 error
= GetSiemensFrame(msg
,s
,"mid",s
->Phone
.Data
.Ringtone
->NokiaBinary
.Frame
,&length
);
152 if (error
!=GE_NONE
) return error
;
153 dbgprintf ("Midi ringtone received\n");
155 s
->Phone
.Data
.Ringtone
->Format
= RING_MIDI
;
156 s
->Phone
.Data
.Ringtone
->NokiaBinary
.Length
= length
;
157 sprintf(buffer
,"Individual");
158 EncodeUnicode (s
->Phone
.Data
.Ringtone
->Name
,buffer
,strlen(buffer
));
162 GSM_Error
ATGEN_GetRingtone(GSM_StateMachine
*s
, GSM_Ringtone
*Ringtone
, bool PhoneRingtone
)
164 unsigned char req
[32];
166 if (s
->Phone
.Data
.Priv
.ATGEN
.Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
168 s
->Phone
.Data
.Ringtone
=Ringtone
;
169 sprintf(req
, "AT^SBNR=\"mid\",%i\r", Ringtone
->Location
-1);
170 smprintf(s
, "Getting RingTone\n");
171 return GSM_WaitFor (s
, req
, strlen(req
), 0x00, 4, ID_GetRingtone
);
174 GSM_Error
ATGEN_CMS35ReplySetRingtone(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
176 return ATGEN_CMS35ReplySetFunction (msg
, s
, "Ringtone");
179 GSM_Error
ATGEN_SetRingtone(GSM_StateMachine
*s
, GSM_Ringtone
*Ringtone
, int *maxlength
)
181 GSM_Phone_Data
*Phone
= &s
->Phone
.Data
;
183 if (s
->Phone
.Data
.Priv
.ATGEN
.Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
185 if (Ringtone
->Location
==255) Ringtone
->Location
=1;
186 if (Ringtone
->Location
-1 > 1) return GE_INVALIDLOCATION
;
188 s
->Phone
.Data
.Ringtone
= Ringtone
;
189 Phone
->Ringtone
= Ringtone
;
190 return SetSiemensFrame(s
, Ringtone
->NokiaBinary
.Frame
,"mid",Ringtone
->Location
-1,
191 ID_SetRingtone
,Ringtone
->NokiaBinary
.Length
);
194 GSM_Error
ATGEN_CMS35ReplyGetNextCal(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
196 GSM_Phone_Data
*Data
= &s
->Phone
.Data
;
197 GSM_CalendarEntry
*Calendar
= Data
->Cal
;
200 unsigned char buffer
[354];
203 if (Data
->Priv
.ATGEN
.ReplyState
!= AT_Reply_OK
) return GE_UNKNOWN
;
205 error
= GetSiemensFrame(msg
,s
,"vcs",buffer
,&len
);
206 if (error
!=GE_NONE
) return error
;
207 error
=GSM_DecodeVCALENDAR_VTODO(buffer
,&pos
,Calendar
,&ToDo
,Siemens_VCalendar
,0);
212 GSM_Error
SIEMENS_GetNextCalendar(GSM_StateMachine
*s
, GSM_CalendarEntry
*Note
, bool start
)
214 GSM_Phone_ATGENData
*Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
216 unsigned char req
[32];
219 if (Priv
->Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
221 if (start
) Note
->Location
=Priv
->FirstCalendarPos
;
222 s
->Phone
.Data
.Cal
= Note
;
223 Note
->EntriesNum
= 0;
224 smprintf(s
, "Getting VCALENDAR\n");
225 Location
= Note
->Location
;
228 sprintf(req
, "AT^SBNR=\"vcs\",%i\r",Location
);
229 error
= GSM_WaitFor (s
, req
, strlen(req
), 0x00, 4, ID_GetCalendarNote
);
230 if ((error
!=GE_NONE
) && (error
!=GE_EMPTY
)) return GE_INVALIDLOCATION
;
231 Note
->Location
= Location
;
232 Priv
->FirstCalendarPos
= Location
;
233 if (Location
> MAX_VCALENDAR_LOCATION
) return GE_EMPTY
;
234 if (error
==GE_NONE
) return error
;
239 GSM_Error
ATGEN_CMS35ReplySetCalendar(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
241 return ATGEN_CMS35ReplySetFunction (msg
, s
, "Calendar Note");
244 GSM_Error
ATGEN_CMS35ReplyDeleteCalendar(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
246 GSM_Phone_Data
*Data
= &s
->Phone
.Data
;
248 if (Data
->Cal
->Location
> MAX_VCALENDAR_LOCATION
) return GE_UNKNOWN
;
250 if (Data
->Priv
.ATGEN
.ReplyState
== AT_Reply_OK
) {
251 smprintf(s
, "Calendar note deleted\n");
254 smprintf(s
, "Can't delete calendar note\n");
259 GSM_Error
SIEMENS_DelCalendarNote(GSM_StateMachine
*s
, GSM_CalendarEntry
*Note
)
261 unsigned char req
[32];
263 if (s
->Phone
.Data
.Priv
.ATGEN
.Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
264 s
->Phone
.Data
.Cal
= Note
;
265 sprintf(req
, "AT^SBNW=\"vcs\",%i,0\r",Note
->Location
);
266 smprintf(s
, "Deleting calendar note\n");
267 return GSM_WaitFor (s
, req
, strlen(req
), 0x00, 4, ID_DeleteCalendarNote
);
270 GSM_Error
SIEMENS_AddCalendarNote(GSM_StateMachine
*s
, GSM_CalendarEntry
*Note
)
272 GSM_Phone_ATGENData
*Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
274 unsigned char req
[500];
277 if (Priv
->Manufacturer
!=AT_Siemens
) return GE_NOTSUPPORTED
;
278 // if (Note->Location==0x00) return GE_INVALIDLOCATION;
280 s
->Phone
.Data
.Cal
= Note
;
281 error
=GSM_EncodeVCALENDAR(req
,&size
,Note
,true,Siemens_VCalendar
);
283 return SetSiemensFrame (s
,req
,"vcs",Note
->Location
,ID_SetCalendarNote
,size
);
286 GSM_Error
ATGEN_SL45ReplyGetMemory(GSM_Protocol_Message msg
, GSM_StateMachine
*s
)
288 GSM_Phone_ATGENData
*Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
289 GSM_MemoryEntry
*Memory
= s
->Phone
.Data
.Memory
;
290 unsigned char buffer
[500],buffer2
[500];
292 switch (Priv
->ReplyState
) {
294 smprintf(s
, "Phonebook entry received\n");
295 CopyLineString(buffer
, msg
.Buffer
, Priv
->Lines
, 3);
296 DecodeHexBin(buffer2
,buffer
,strlen(buffer
));
297 Memory
->EntriesNum
= 0;
298 Memory
->PreferUnicode
= false;
299 DecodeVCARD21Text(buffer2
, Memory
);
300 if (Memory
->EntriesNum
== 0) return GE_EMPTY
;
303 smprintf(s
, "Error - too high location ?\n");
304 return GE_INVALIDLOCATION
;
305 case AT_Reply_CMSError
:
306 return ATGEN_HandleCMSError(s
);
310 return GE_UNKNOWNRESPONSE
;
315 /* How should editor hadle tabs in this file? Add editor commands here.
316 * vim: noexpandtab sw=8 ts=8 sts=8: