summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/phone/at
Unidiff
Diffstat (limited to 'gammu/emb/common/phone/at') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/phone/at/atgen.c295
-rw-r--r--gammu/emb/common/phone/at/atgen.h8
-rw-r--r--gammu/emb/common/phone/at/samsung.c447
-rw-r--r--gammu/emb/common/phone/at/samsung.h16
-rw-r--r--gammu/emb/common/phone/at/siemens.c74
-rw-r--r--gammu/emb/common/phone/at/sonyeric.c141
6 files changed, 874 insertions, 107 deletions
diff --git a/gammu/emb/common/phone/at/atgen.c b/gammu/emb/common/phone/at/atgen.c
index 1834f15..ba23eb2 100644
--- a/gammu/emb/common/phone/at/atgen.c
+++ b/gammu/emb/common/phone/at/atgen.c
@@ -11,39 +11,19 @@
11#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
12#include "../../misc/coding/coding.h" 12#include "../../misc/coding/coding.h"
13#include "../../service/sms/gsmsms.h" 13#include "../../service/sms/gsmsms.h"
14#include "../pfunc.h" 14#include "../pfunc.h"
15
15#include "atgen.h" 16#include "atgen.h"
16 17
18#include "samsung.h"
19#include "siemens.h"
20#include "sonyeric.h"
21
17#ifdef GSM_ENABLE_ALCATEL 22#ifdef GSM_ENABLE_ALCATEL
18 extern GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s); 23GSM_Error ALCATEL_ProtocolVersionReply (GSM_Protocol_Message, GSM_StateMachine *);
19#endif 24#endif
20 25
21 extern GSM_Error ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s);
22 extern GSM_Error ATGEN_CMS35ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s);
23 extern GSM_Error ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s);
24 extern GSM_Error ATGEN_CMS35ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s);
25 extern GSM_Error ATGEN_CMS35ReplyGetNextCal(GSM_Protocol_Message msg, GSM_StateMachine *s);
26 extern GSM_Error ATGEN_CMS35ReplySetCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s);
27 extern GSM_Error ATGEN_CMS35ReplyDeleteCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s);
28 extern GSM_Error ATGEN_SL45ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s);
29
30 extern GSM_Error ATGEN_GetRingtone (GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone);
31 extern GSM_Error ATGEN_SetRingtone (GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength);
32 extern GSM_Error ATGEN_GetBitmap (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
33 extern GSM_Error ATGEN_SetBitmap (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
34 extern GSM_Error SIEMENS_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start);
35 extern GSM_Error SIEMENS_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
36 extern GSM_Error SIEMENS_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
37
38 extern GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start);
39 extern GSM_Error SONYERIC_GetNextToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start);
40 extern GSM_Error SONYERIC_GetToDoStatus (GSM_StateMachine *s, GSM_ToDoStatus *status);
41 extern GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
42 extern GSM_Error SONYERIC_AddToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
43 extern GSM_Error SONYERIC_DeleteAllToDo (GSM_StateMachine *s);
44 extern GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
45 extern GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status);
46 26
47typedef struct { 27typedef struct {
48 int Number; 28 int Number;
49 char Text[60]; 29 char Text[60];
@@ -174,8 +154,10 @@ GSM_Error ATGEN_HandleCMEError(GSM_StateMachine *s)
174 smprintf(s, "CME Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText); 154 smprintf(s, "CME Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText);
175 } 155 }
176 /* For error codes descriptions see table a bit above */ 156 /* For error codes descriptions see table a bit above */
177 switch (Priv->ErrorCode) { 157 switch (Priv->ErrorCode) {
158 case -1:
159 return ERR_EMPTY;
178 case 3: 160 case 3:
179 return ERR_PERMISSION; 161 return ERR_PERMISSION;
180 case 4: 162 case 4:
181 return ERR_NOTSUPPORTED; 163 return ERR_NOTSUPPORTED;
@@ -255,10 +237,18 @@ int ATGEN_ExtractOneParameter(unsigned char *input, unsigned char *output)
255} 237}
256 238
257void ATGEN_DecodeDateTime(GSM_DateTime *dt, unsigned char *input) 239void ATGEN_DecodeDateTime(GSM_DateTime *dt, unsigned char *input)
258{ 240{
259 dt->Year=2000+(*input-'0')*10; input++; 241 /* Samsung phones report year as %d instead of %02d */
242 if (input[2] == '/') {
243 dt->Year=(*input-'0')*10;
244 input++;
245 } else {
246 dt->Year=0;
247 }
248
260 dt->Year=dt->Year+(*input-'0'); input++; 249 dt->Year=dt->Year+(*input-'0'); input++;
250 dt->Year+=2000;
261 251
262 input++; 252 input++;
263 dt->Month=(*input-'0')*10; input++; 253 dt->Month=(*input-'0')*10; input++;
264 dt->Month=dt->Month+(*input-'0'); input++; 254 dt->Month=dt->Month+(*input-'0'); input++;
@@ -321,8 +311,20 @@ GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s)
321 if (!strncmp(line,"+CMS ERROR:",11)) { 311 if (!strncmp(line,"+CMS ERROR:",11)) {
322 Priv->ReplyState = AT_Reply_CMSError; 312 Priv->ReplyState = AT_Reply_CMSError;
323 ErrorCodes = CMSErrorCodes; 313 ErrorCodes = CMSErrorCodes;
324 } 314 }
315
316 /* FIXME: Samsung phones can answer +CME ERROR:-1 meaning empty location */
317 if (Priv->ReplyState == AT_Reply_CMEError && Priv->Manufacturer == AT_Samsung) {
318 err = line + 11;
319 Priv->ErrorCode = atoi(err);
320
321 if (Priv->ErrorCode == -1) {
322 Priv->ErrorText = "[Samsung] Empty location";
323 return GSM_DispatchMessage(s);
324 }
325 }
326
325 if (Priv->ReplyState == AT_Reply_CMEError || Priv->ReplyState == AT_Reply_CMSError) { 327 if (Priv->ReplyState == AT_Reply_CMEError || Priv->ReplyState == AT_Reply_CMSError) {
326 j = 0; 328 j = 0;
327 /* One char behind +CM[SE] ERROR */ 329 /* One char behind +CM[SE] ERROR */
328 err = line + 12; 330 err = line + 12;
@@ -369,8 +371,44 @@ GSM_Error ATGEN_GenericReply(GSM_Protocol_Message msg, GSM_StateMachine *s)
369 } 371 }
370 return ERR_UNKNOWNRESPONSE; 372 return ERR_UNKNOWNRESPONSE;
371} 373}
372 374
375GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message msg, GSM_StateMachine *s)
376{
377 unsigned char buffer[2000],buffer2[4000];
378 int i = 10;
379
380 /* Ugly hack */
381 while (msg.Buffer[i]!=13) i++;
382 i = i - 6;
383 memcpy(buffer,msg.Buffer+10,i-11);
384 buffer[i-11] = 0x00;
385
386 smprintf(s, "USSD reply: \"%s\"\n",buffer);
387
388 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
389 EncodeUnicode(buffer2,buffer,strlen(buffer));
390 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2);
391 }
392
393 return ERR_NONE;
394}
395
396GSM_Error ATGEN_SetIncomingUSSD(GSM_StateMachine *s, bool enable)
397{
398 GSM_Error error;
399
400 if (enable) {
401 smprintf(s, "Enabling incoming USSD\n");
402 error=GSM_WaitFor (s, "AT+CUSD=1\r", 10, 0x00, 3, ID_SetUSSD);
403 } else {
404 smprintf(s, "Disabling incoming USSD\n");
405 error=GSM_WaitFor (s, "AT+CUSD=0\r", 10, 0x00, 3, ID_SetUSSD);
406 }
407 if (error==ERR_NONE) s->Phone.Data.EnableIncomingUSSD = enable;
408 return error;
409}
410
373GSM_Error ATGEN_ReplyGetModel(GSM_Protocol_Message msg, GSM_StateMachine *s) 411GSM_Error ATGEN_ReplyGetModel(GSM_Protocol_Message msg, GSM_StateMachine *s)
374{ 412{
375 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 413 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
376 GSM_Phone_Data *Data = &s->Phone.Data; 414 GSM_Phone_Data *Data = &s->Phone.Data;
@@ -393,12 +431,14 @@ GSM_Error ATGEN_ReplyGetModel(GSM_Protocol_Message msg, GSM_StateMachine *s)
393 431
394 if (strstr(msg.Buffer,"Nokia")) Priv->Manufacturer = AT_Nokia; 432 if (strstr(msg.Buffer,"Nokia")) Priv->Manufacturer = AT_Nokia;
395 else if (strstr(msg.Buffer,"M20")) Priv->Manufacturer = AT_Siemens; 433 else if (strstr(msg.Buffer,"M20")) Priv->Manufacturer = AT_Siemens;
396 else if (strstr(msg.Buffer,"MC35")) Priv->Manufacturer = AT_Siemens; 434 else if (strstr(msg.Buffer,"MC35")) Priv->Manufacturer = AT_Siemens;
435 else if (strstr(msg.Buffer,"TC35")) Priv->Manufacturer = AT_Siemens;
397 else if (strstr(msg.Buffer, "iPAQ")) Priv->Manufacturer = AT_HP; 436 else if (strstr(msg.Buffer, "iPAQ")) Priv->Manufacturer = AT_HP;
398 437
399 if (strstr(msg.Buffer,"M20")) strcpy(Data->Model,"M20"); 438 if (strstr(msg.Buffer,"M20")) strcpy(Data->Model,"M20");
400 else if (strstr(msg.Buffer,"MC35")) strcpy(Data->Model,"MC35"); 439 else if (strstr(msg.Buffer,"MC35")) strcpy(Data->Model,"MC35");
440 else if (strstr(msg.Buffer,"TC35")) strcpy(Data->Model,"TC35");
401 else if (strstr(msg.Buffer, "iPAQ")) strcpy(Data->Model,"iPAQ"); 441 else if (strstr(msg.Buffer, "iPAQ")) strcpy(Data->Model,"iPAQ");
402 } else { 442 } else {
403 smprintf(s, "WARNING: Model name too long, increase MAX_MODEL_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2))); 443 smprintf(s, "WARNING: Model name too long, increase MAX_MODEL_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2)));
404 } 444 }
@@ -480,8 +520,13 @@ GSM_Error ATGEN_ReplyGetManufacturer(GSM_Protocol_Message msg, GSM_StateMachine
480 smprintf(s, "Sagem\n"); 520 smprintf(s, "Sagem\n");
481 strcpy(s->Phone.Data.Manufacturer,"Sagem"); 521 strcpy(s->Phone.Data.Manufacturer,"Sagem");
482 Priv->Manufacturer = AT_Sagem; 522 Priv->Manufacturer = AT_Sagem;
483 } 523 }
524 if (strstr(msg.Buffer,"Samsung")) {
525 smprintf(s, "Samsung\n");
526 strcpy(s->Phone.Data.Manufacturer,"Samsung");
527 Priv->Manufacturer = AT_Samsung;
528 }
484 return ERR_NONE; 529 return ERR_NONE;
485 case AT_Reply_CMSError: 530 case AT_Reply_CMSError:
486 return ATGEN_HandleCMSError(s); 531 return ATGEN_HandleCMSError(s);
487 default: 532 default:
@@ -673,18 +718,28 @@ GSM_Error ATGEN_ReplyGetSMSMemories(GSM_Protocol_Message msg, GSM_StateMachine *
673 * available for everything. Then we need to find out whether 718 * available for everything. Then we need to find out whether
674 * phone supports writing to memory. This is done by searching 719 * phone supports writing to memory. This is done by searching
675 * for "), (", which will appear between lists. 720 * for "), (", which will appear between lists.
676 */ 721 */
677 s->Phone.Data.Priv.ATGEN.CanSaveSMS = (strstr(msg.Buffer, "), (") != NULL); 722 s->Phone.Data.Priv.ATGEN.CanSaveSMS = false;
723 if (strstr(msg.Buffer, "), (") != NULL || strstr(msg.Buffer, "),(") != NULL) {
724 s->Phone.Data.Priv.ATGEN.CanSaveSMS = true;
725 }
726
678 if (strstr(msg.Buffer, "\"SM\"") != NULL) s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_AVAILABLE; 727 if (strstr(msg.Buffer, "\"SM\"") != NULL) s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_AVAILABLE;
679 else s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_NOTAVAILABLE; 728 else s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_NOTAVAILABLE;
729
680 if (strstr(msg.Buffer, "\"ME\"") != NULL) s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_AVAILABLE; 730 if (strstr(msg.Buffer, "\"ME\"") != NULL) s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_AVAILABLE;
681 else s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_NOTAVAILABLE; 731 else s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_NOTAVAILABLE;
682 smprintf(s, "Available SMS memories received, ME = %d, SM = %d\n", s->Phone.Data.Priv.ATGEN.PhoneSMSMemory, s->Phone.Data.Priv.ATGEN.SIMSMSMemory); 732
733 smprintf(s, "Available SMS memories received, ME = %d, SM = %d, cansavesms =", s->Phone.Data.Priv.ATGEN.PhoneSMSMemory, s->Phone.Data.Priv.ATGEN.SIMSMSMemory);
734 if (s->Phone.Data.Priv.ATGEN.CanSaveSMS) smprintf(s, "true");
735 smprintf(s, "\n");
683 return ERR_NONE; 736 return ERR_NONE;
684 case AT_Reply_Error: 737 case AT_Reply_Error:
685 case AT_Reply_CMSError: 738 case AT_Reply_CMSError:
686 return ATGEN_HandleCMSError(s); 739 return ATGEN_HandleCMSError(s);
740 case AT_Reply_CMEError:
741 return ATGEN_HandleCMEError(s);
687 default: 742 default:
688 return ERR_UNKNOWNRESPONSE; 743 return ERR_UNKNOWNRESPONSE;
689 } 744 }
690} 745}
@@ -857,10 +912,11 @@ GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s
857 /* Siemens MC35 (only ?) */ 912 /* Siemens MC35 (only ?) */
858 if (strstr(msg.Buffer,"+CMGR: 0,,0")!=NULL) return ERR_EMPTY; 913 if (strstr(msg.Buffer,"+CMGR: 0,,0")!=NULL) return ERR_EMPTY;
859 /* Siemens M20 */ 914 /* Siemens M20 */
860 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 915 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
861 if (buffer[1]!=NUMBER_UNKNOWN && buffer[1]!=NUMBER_INTERNATIONAL && 916 /* we check for the most often visible */
862 buffer[1]!=NUMBER_ALPHANUMERIC) { 917 if (buffer[1]!=NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN && buffer[1]!=NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN &&
918 buffer[1]!=NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
863 /* Seems to be Delivery Report */ 919 /* Seems to be Delivery Report */
864 smprintf(s, "SMS type - status report (M20 style)\n"); 920 smprintf(s, "SMS type - status report (M20 style)\n");
865 sms->PDU = SMS_Status_Report; 921 sms->PDU = SMS_Status_Report;
866 sms->Folder = 1;/*INBOX SIM*/ 922 sms->Folder = 1;/*INBOX SIM*/
@@ -893,9 +949,9 @@ GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s
893 } 949 }
894 sms->InboxFolder = true; 950 sms->InboxFolder = true;
895 current2=((buffer[current])+1)/2+1; 951 current2=((buffer[current])+1)/2+1;
896 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 952 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
897 if (buffer[current+1]==NUMBER_ALPHANUMERIC) { 953 if (buffer[current+1]==NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
898 smprintf(s, "Trying to read alphanumeric number\n"); 954 smprintf(s, "Trying to read alphanumeric number\n");
899 for(i=0;i<4;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++]; 955 for(i=0;i<4;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++];
900 current+=6; 956 current+=6;
901 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSDeliver.Number+i+4]=buffer[current++]; 957 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSDeliver.Number+i+4]=buffer[current++];
@@ -924,9 +980,9 @@ GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s
924 sms->InboxFolder = false; 980 sms->InboxFolder = false;
925 smsframe[PHONE_SMSSubmit.TPMR] = buffer[current++]; 981 smsframe[PHONE_SMSSubmit.TPMR] = buffer[current++];
926 current2=((buffer[current])+1)/2+1; 982 current2=((buffer[current])+1)/2+1;
927 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 983 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
928 if (buffer[current+1]==NUMBER_ALPHANUMERIC) { 984 if (buffer[current+1]==NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
929 smprintf(s, "Trying to read alphanumeric number\n"); 985 smprintf(s, "Trying to read alphanumeric number\n");
930 for(i=0;i<4;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++]; 986 for(i=0;i<4;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++];
931 current+=6; 987 current+=6;
932 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSSubmit.Number+i+4]=buffer[current++]; 988 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSSubmit.Number+i+4]=buffer[current++];
@@ -948,9 +1004,9 @@ GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s
948 smprintf(s, "SMS type - status report\n"); 1004 smprintf(s, "SMS type - status report\n");
949 sms->PDU = SMS_Status_Report; 1005 sms->PDU = SMS_Status_Report;
950 sms->Folder = 1;/*INBOX SIM*/ 1006 sms->Folder = 1;/*INBOX SIM*/
951 sms->InboxFolder = true; 1007 sms->InboxFolder = true;
952 smprintf(s, "TPMR is %02x\n",buffer[current]); 1008 smprintf(s, "TPMR is %d\n",buffer[current]);
953 smsframe[PHONE_SMSStatusReport.TPMR] = buffer[current++]; 1009 smsframe[PHONE_SMSStatusReport.TPMR] = buffer[current++];
954 current2=((buffer[current])+1)/2+1; 1010 current2=((buffer[current])+1)/2+1;
955 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++]; 1011 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++];
956 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++]; 1012 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++];
@@ -1639,19 +1695,19 @@ GSM_Error ATGEN_ReplySendSMS(GSM_Protocol_Message msg, GSM_StateMachine *s)
1639 switch (Priv->ReplyState) { 1695 switch (Priv->ReplyState) {
1640 case AT_Reply_OK: 1696 case AT_Reply_OK:
1641 smprintf(s, "SMS sent OK\n"); 1697 smprintf(s, "SMS sent OK\n");
1642 if (s->User.SendSMSStatus!=NULL) { 1698 if (s->User.SendSMSStatus!=NULL) {
1643 start = strstr(msg.Buffer, "+CMGW: "); 1699 start = strstr(msg.Buffer, "+CMGS: ");
1644 if (start != NULL) { 1700 if (start != NULL) {
1645 s->User.SendSMSStatus(s->CurrentConfig->Device,0,atoi(start+7)); 1701 s->User.SendSMSStatus(s->CurrentConfig->Device,0,atoi(start+7));
1646 } else { 1702 } else {
1647 s->User.SendSMSStatus(s->CurrentConfig->Device,0,0); 1703 s->User.SendSMSStatus(s->CurrentConfig->Device,0,-1);
1648 } 1704 }
1649 } 1705 }
1650 return ERR_NONE; 1706 return ERR_NONE;
1651 case AT_Reply_CMSError: 1707 case AT_Reply_CMSError:
1652 smprintf(s, "Error %i\n",Priv->ErrorCode); 1708 smprintf(s, "Error %i\n",Priv->ErrorCode);
1653 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,Priv->ErrorCode,0); 1709 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,Priv->ErrorCode,-1);
1654 return ATGEN_HandleCMSError(s); 1710 return ATGEN_HandleCMSError(s);
1655 case AT_Reply_Error: 1711 case AT_Reply_Error:
1656 return ERR_UNKNOWN; 1712 return ERR_UNKNOWN;
1657 default: 1713 default:
@@ -1786,8 +1842,21 @@ GSM_Error ATGEN_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
1786 smprintf(s, "Getting alarm\n"); 1842 smprintf(s, "Getting alarm\n");
1787 return GSM_WaitFor (s, "AT+CALA?\r", 9, 0x00, 4, ID_GetAlarm); 1843 return GSM_WaitFor (s, "AT+CALA?\r", 9, 0x00, 4, ID_GetAlarm);
1788} 1844}
1789 1845
1846/* R320 only takes HH:MM. Do other phones understand full date? */
1847GSM_Error ATGEN_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
1848{
1849 char req[20];
1850
1851 if (alarm->Location != 1) return ERR_INVALIDLOCATION;
1852
1853 sprintf(req, "AT+CALA=\"%02i:%02i\"\r",alarm->DateTime.Hour,alarm->DateTime.Minute);
1854
1855 smprintf(s, "Setting Alarm\n");
1856 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetAlarm);
1857}
1858
1790GSM_Error ATGEN_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 1859GSM_Error ATGEN_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
1791{ 1860{
1792 GSM_SMSC *SMSC = s->Phone.Data.SMSC; 1861 GSM_SMSC *SMSC = s->Phone.Data.SMSC;
1793 int current; 1862 int current;
@@ -2201,8 +2270,10 @@ GSM_Error ATGEN_GetMemoryInfo(GSM_StateMachine *s, GSM_MemoryStatus *Status, GSM
2201 Priv->TextLength = 0; 2270 Priv->TextLength = 0;
2202 Priv->NumberLength = 0; 2271 Priv->NumberLength = 0;
2203 2272
2204 error = GSM_WaitFor (s, "AT+CPBR=?\r", 10, 0x00, 4, ID_GetMemoryStatus); 2273 error = GSM_WaitFor (s, "AT+CPBR=?\r", 10, 0x00, 4, ID_GetMemoryStatus);
2274 if (Priv->Manufacturer == AT_Samsung)
2275 error = GSM_WaitFor (s, "", 0, 0x00, 4, ID_GetMemoryStatus);
2205 if (error != ERR_NONE) return error; 2276 if (error != ERR_NONE) return error;
2206 if (NeededInfo == AT_Total || NeededInfo == AT_Sizes || NeededInfo == AT_First) return ERR_NONE; 2277 if (NeededInfo == AT_Total || NeededInfo == AT_Sizes || NeededInfo == AT_First) return ERR_NONE;
2207 2278
2208 smprintf(s, "Getting memory status by reading values\n"); 2279 smprintf(s, "Getting memory status by reading values\n");
@@ -2267,8 +2338,14 @@ GSM_Error ATGEN_SetPBKCharset(GSM_StateMachine *s, bool PreferUnicode)
2267 2338
2268 error=ATGEN_GetManufacturer(s); 2339 error=ATGEN_GetManufacturer(s);
2269 if (error != ERR_NONE) return error; 2340 if (error != ERR_NONE) return error;
2270 2341
2342 /* Samsung (and Sagem?) phones use only PCCP437? */
2343 if (Priv->Manufacturer == AT_Samsung) {
2344 Priv->PBKCharset = AT_PBK_PCCP437;
2345 return ERR_NONE;
2346 }
2347
2271 if (PreferUnicode && !Priv->UCS2CharsetFailed) { 2348 if (PreferUnicode && !Priv->UCS2CharsetFailed) {
2272 smprintf(s, "Setting charset to UCS2\n"); 2349 smprintf(s, "Setting charset to UCS2\n");
2273 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset); 2350 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset);
2274 if (error == ERR_NONE) { 2351 if (error == ERR_NONE) {
@@ -2384,9 +2461,39 @@ GSM_Error ATGEN_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
2384 break; 2461 break;
2385 case AT_PBK_UCS2: 2462 case AT_PBK_UCS2:
2386 DecodeHexUnicode(Memory->Entries[1].Text,buffer+1,strlen(buffer+1) - 1); 2463 DecodeHexUnicode(Memory->Entries[1].Text,buffer+1,strlen(buffer+1) - 1);
2387 break; 2464 break;
2465 case AT_PBK_PCCP437:
2466 /* FIXME: correctly decode PCCP437 */
2467 DecodeDefault(Memory->Entries[1].Text,buffer+1,strlen(buffer)-2,false,NULL);
2468 break;
2469 }
2470
2471 /* Samsung number type */
2472 if (Priv->Manufacturer == AT_Samsung) {
2473 int type;
2474
2475 pos += ATGEN_ExtractOneParameter(pos, buffer);
2476 smprintf(s, "Number type: %s\n",buffer);
2477 type = strtoul(buffer, NULL, 0);
2478 switch (type) {
2479 case 0:
2480 Memory->Entries[0].EntryType = PBK_Number_Mobile;
2481 break;
2482 case 1:
2483 Memory->Entries[0].EntryType = PBK_Number_Work;
2484 break;
2485 case 2:
2486 Memory->Entries[0].EntryType = PBK_Number_Home;
2487 break;
2488 case 3:
2489 Memory->Entries[0].EntryType = PBK_Text_Email;
2490 break;
2491 default:
2492 Memory->Entries[0].EntryType = PBK_Number_General;
2493 }
2388 } 2494 }
2495
2389 return ERR_NONE; 2496 return ERR_NONE;
2390 case AT_Reply_CMEError: 2497 case AT_Reply_CMEError:
2391 return ATGEN_HandleCMEError(s); 2498 return ATGEN_HandleCMEError(s);
2392 case AT_Reply_Error: 2499 case AT_Reply_Error:
@@ -2561,8 +2668,10 @@ GSM_Error ATGEN_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachin
2561 smprintf(s, "Incorrect security code\n"); 2668 smprintf(s, "Incorrect security code\n");
2562 return ERR_SECURITYERROR; 2669 return ERR_SECURITYERROR;
2563 case AT_Reply_CMSError: 2670 case AT_Reply_CMSError:
2564 return ATGEN_HandleCMSError(s); 2671 return ATGEN_HandleCMSError(s);
2672 case AT_Reply_CMEError:
2673 return ATGEN_HandleCMEError(s);
2565 default: 2674 default:
2566 break; 2675 break;
2567 } 2676 }
2568 return ERR_UNKNOWNRESPONSE; 2677 return ERR_UNKNOWNRESPONSE;
@@ -2923,8 +3032,14 @@ GSM_Error ATGEN_PrivSetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2923 case AT_PBK_UCS2: 3032 case AT_PBK_UCS2:
2924 EncodeHexUnicode(name, entry->Entries[Name].Text, UnicodeLength(entry->Entries[Name].Text)); 3033 EncodeHexUnicode(name, entry->Entries[Name].Text, UnicodeLength(entry->Entries[Name].Text));
2925 len = strlen(name); 3034 len = strlen(name);
2926 break; 3035 break;
3036 case AT_PBK_PCCP437:
3037 /* FIXME: correctly decode PCCP437 */
3038 smprintf(s, "str: %s\n", DecodeUnicodeString(entry->Entries[Name].Text));
3039 len = UnicodeLength(entry->Entries[Name].Text);
3040 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL);
3041 break;
2927 } 3042 }
2928 } else { 3043 } else {
2929 smprintf(s, "WARNING: No usable name found!\n"); 3044 smprintf(s, "WARNING: No usable name found!\n");
2930 len = 0; 3045 len = 0;
@@ -3251,8 +3366,45 @@ GSM_Error ATGEN_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
3251 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_DelCalendarNote(s, Note); 3366 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_DelCalendarNote(s, Note);
3252 return ERR_NOTSUPPORTED; 3367 return ERR_NOTSUPPORTED;
3253} 3368}
3254 3369
3370
3371GSM_Error ATGEN_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
3372{
3373 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3374
3375 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_GetBitmap(s, Bitmap);
3376 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_GetBitmap(s, Bitmap);
3377 return ERR_NOTSUPPORTED;
3378}
3379
3380GSM_Error ATGEN_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
3381{
3382 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3383
3384 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_SetBitmap(s, Bitmap);
3385 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_SetBitmap(s, Bitmap);
3386 return ERR_NOTSUPPORTED;
3387}
3388
3389GSM_Error ATGEN_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
3390{
3391 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3392
3393 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_GetRingtone(s, Ringtone, PhoneRingtone);
3394 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_GetRingtone(s, Ringtone, PhoneRingtone);
3395 return ERR_NOTSUPPORTED;
3396}
3397
3398GSM_Error ATGEN_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
3399{
3400 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3401
3402 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_SetRingtone(s, Ringtone, maxlength);
3403 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_SetRingtone(s, Ringtone, maxlength);
3404 return ERR_NOTSUPPORTED;
3405}
3406
3255GSM_Error ATGEN_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press) 3407GSM_Error ATGEN_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press)
3256{ 3408{
3257 GSM_Errorerror; 3409 GSM_Errorerror;
3258 unsigned char Frame[] = "AT+CKPD=\"?\"\r"; 3410 unsigned char Frame[] = "AT+CKPD=\"?\"\r";
@@ -3345,8 +3497,19 @@ GSM_Error ATGEN_SetIncomingCB(GSM_StateMachine *s, bool enable)
3345 return ERR_SOURCENOTAVAILABLE; 3497 return ERR_SOURCENOTAVAILABLE;
3346#endif 3498#endif
3347} 3499}
3348 3500
3501GSM_Error ATGEN_SetFastSMSSending(GSM_StateMachine *s, bool enable)
3502{
3503 if (enable) {
3504 smprintf(s, "Enabling fast SMS sending\n");
3505 return GSM_WaitFor(s, "AT+CMMS=2\r", 10, 0x00, 4, ID_SetFastSMSSending);
3506 } else {
3507 smprintf(s, "Disabling fast SMS sending\n");
3508 return GSM_WaitFor(s, "AT+CMMS=0\r", 10, 0x00, 4, ID_SetFastSMSSending);
3509 }
3510}
3511
3349GSM_Error ATGEN_IncomingSMSInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 3512GSM_Error ATGEN_IncomingSMSInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3350{ 3513{
3351 smprintf(s, "Incoming SMS\n"); 3514 smprintf(s, "Incoming SMS\n");
3352 return ERR_NONE; 3515 return ERR_NONE;
@@ -3423,16 +3586,33 @@ GSM_Error ATGEN_SetIncomingSMS(GSM_StateMachine *s, bool enable)
3423 } 3586 }
3424 return ERR_NONE; 3587 return ERR_NONE;
3425} 3588}
3426 3589
3590GSM_Error ATGEN_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
3591{
3592 if (s->Phone.Data.Priv.ATGEN.Manufacturer==AT_Ericsson) return ERICSSON_GetLocale(s,locale);
3593 return ERR_NOTSUPPORTED;
3594}
3595
3596GSM_Error ATGEN_SetLocale(GSM_StateMachine *s, GSM_Locale *locale)
3597{
3598 if (s->Phone.Data.Priv.ATGEN.Manufacturer==AT_Ericsson) return ERICSSON_SetLocale(s,locale);
3599 return ERR_NOTSUPPORTED;
3600}
3601
3427GSM_Reply_Function ATGENReplyFunctions[] = { 3602GSM_Reply_Function ATGENReplyFunctions[] = {
3428 {ATGEN_GenericReply, "AT\r" ,0x00,0x00,ID_IncomingFrame }, 3603 {ATGEN_GenericReply, "AT\r" ,0x00,0x00,ID_IncomingFrame },
3429 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_EnableEcho }, 3604 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_EnableEcho },
3430 {ATGEN_GenericReply, "AT+CMEE=" ,0x00,0x00,ID_EnableErrorInfo }, 3605 {ATGEN_GenericReply, "AT+CMEE=" ,0x00,0x00,ID_EnableErrorInfo },
3431 {ATGEN_GenericReply, "AT+CKPD=" ,0x00,0x00,ID_PressKey }, 3606 {ATGEN_GenericReply, "AT+CKPD=" ,0x00,0x00,ID_PressKey },
3432 {ATGEN_ReplyGetSIMIMSI, "AT+CIMI" ,0x00,0x00,ID_GetSIMIMSI }, 3607 {ATGEN_ReplyGetSIMIMSI, "AT+CIMI" ,0x00,0x00,ID_GetSIMIMSI },
3433 {ATGEN_GenericReply, "AT*EOBEX" ,0x00,0x00,ID_SetOBEX }, 3608 {ATGEN_GenericReply, "AT*EOBEX" ,0x00,0x00,ID_SetOBEX },
3434 3609
3610 {ERICSSON_ReplyGetDateLocale, "*ESDF:" ,0x00,0x00,ID_GetLocale },
3611 {ERICSSON_ReplyGetTimeLocale, "*ESTF:" ,0x00,0x00,ID_GetLocale },
3612 {ATGEN_GenericReply, "AT*ESDF=" ,0x00,0x00,ID_SetLocale },
3613 {ATGEN_GenericReply, "AT*ESTF=" ,0x00,0x00,ID_SetLocale },
3614
3435#ifdef GSM_ENABLE_CELLBROADCAST 3615#ifdef GSM_ENABLE_CELLBROADCAST
3436 {ATGEN_ReplyIncomingCB, "+CBM:" ,0x00,0x00,ID_IncomingFrame }, 3616 {ATGEN_ReplyIncomingCB, "+CBM:" ,0x00,0x00,ID_IncomingFrame },
3437 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingCB }, 3617 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingCB },
3438#endif 3618#endif
@@ -3461,15 +3641,17 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
3461 {ATGEN_ReplyGetSMSC, "AT+CSCA?" ,0x00,0x00,ID_GetSMSC }, 3641 {ATGEN_ReplyGetSMSC, "AT+CSCA?" ,0x00,0x00,ID_GetSMSC },
3462 {ATGEN_ReplyDeleteSMSMessage, "AT+CMGD" ,0x00,0x00,ID_DeleteSMSMessage }, 3642 {ATGEN_ReplyDeleteSMSMessage, "AT+CMGD" ,0x00,0x00,ID_DeleteSMSMessage },
3463 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_SetSMSParameters }, 3643 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_SetSMSParameters },
3464 {ATGEN_GenericReply, "\x1b\x0D" ,0x00,0x00,ID_SetSMSParameters }, 3644 {ATGEN_GenericReply, "\x1b\x0D" ,0x00,0x00,ID_SetSMSParameters },
3645 {ATGEN_GenericReply, "AT+CMMS" ,0x00,0x00,ID_SetFastSMSSending },
3465 {ATGEN_IncomingSMSInfo, "+CMTI:" ,0x00,0x00,ID_IncomingFrame }, 3646 {ATGEN_IncomingSMSInfo, "+CMTI:" ,0x00,0x00,ID_IncomingFrame },
3466 {ATGEN_IncomingSMSDeliver, "+CMT:" ,0x00,0x00,ID_IncomingFrame }, 3647 {ATGEN_IncomingSMSDeliver, "+CMT:" ,0x00,0x00,ID_IncomingFrame },
3467 {ATGEN_IncomingSMSReport, "+CDS:" ,0x00,0x00,ID_IncomingFrame }, 3648 {ATGEN_IncomingSMSReport, "+CDS:" ,0x00,0x00,ID_IncomingFrame },
3468 {ATGEN_IncomingSMSCInfo, "^SCN:" ,0x00,0x00,ID_IncomingFrame }, 3649 {ATGEN_IncomingSMSCInfo, "^SCN:" ,0x00,0x00,ID_IncomingFrame },
3469 3650
3470 {ATGEN_ReplyGetDateTime_Alarm, "AT+CCLK?" ,0x00,0x00,ID_GetDateTime }, 3651 {ATGEN_ReplyGetDateTime_Alarm, "AT+CCLK?" ,0x00,0x00,ID_GetDateTime },
3471 {ATGEN_GenericReply, "AT+CCLK=" ,0x00,0x00,ID_SetDateTime }, 3652 {ATGEN_GenericReply, "AT+CCLK=" ,0x00,0x00,ID_SetDateTime },
3653 {ATGEN_GenericReply, "AT+CALA=" ,0x00,0x00,ID_SetAlarm },
3472 {ATGEN_ReplyGetDateTime_Alarm, "AT+CALA?" ,0x00,0x00,ID_GetAlarm }, 3654 {ATGEN_ReplyGetDateTime_Alarm, "AT+CALA?" ,0x00,0x00,ID_GetAlarm },
3473 3655
3474 {ATGEN_ReplyGetNetworkLAC_CID, "AT+CREG?" ,0x00,0x00,ID_GetNetworkInfo }, 3656 {ATGEN_ReplyGetNetworkLAC_CID, "AT+CREG?" ,0x00,0x00,ID_GetNetworkInfo },
3475 {ATGEN_GenericReply, "AT+CREG=2" ,0x00,0x00,ID_GetNetworkInfo }, 3657 {ATGEN_GenericReply, "AT+CREG=2" ,0x00,0x00,ID_GetNetworkInfo },
@@ -3483,25 +3665,27 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
3483 3665
3484 {ATGEN_ReplyGetPBKMemories, "AT+CPBS=?" ,0x00,0x00,ID_SetMemoryType }, 3666 {ATGEN_ReplyGetPBKMemories, "AT+CPBS=?" ,0x00,0x00,ID_SetMemoryType },
3485 {ATGEN_GenericReply, "AT+CPBS=" ,0x00,0x00,ID_SetMemoryType }, 3667 {ATGEN_GenericReply, "AT+CPBS=" ,0x00,0x00,ID_SetMemoryType },
3486 {ATGEN_ReplyGetCPBSMemoryStatus,"AT+CPBS?" ,0x00,0x00,ID_GetMemoryStatus }, 3668 {ATGEN_ReplyGetCPBSMemoryStatus,"AT+CPBS?" ,0x00,0x00,ID_GetMemoryStatus },
3669// /* Samsung phones reply +CPBR: after OK --claudio*/
3487 {ATGEN_ReplyGetCPBRMemoryInfo, "AT+CPBR=?" ,0x00,0x00,ID_GetMemoryStatus }, 3670 {ATGEN_ReplyGetCPBRMemoryInfo, "AT+CPBR=?" ,0x00,0x00,ID_GetMemoryStatus },
3671 {ATGEN_ReplyGetCPBRMemoryInfo, "+CPBR:" ,0x00,0x00,ID_GetMemoryStatus },
3488 {ATGEN_ReplyGetCPBRMemoryStatus,"AT+CPBR=" ,0x00,0x00,ID_GetMemoryStatus }, 3672 {ATGEN_ReplyGetCPBRMemoryStatus,"AT+CPBR=" ,0x00,0x00,ID_GetMemoryStatus },
3489 {ATGEN_GenericReply, "AT+CSCS=" ,0x00,0x00,ID_SetMemoryCharset }, 3673 {ATGEN_GenericReply, "AT+CSCS=" ,0x00,0x00,ID_SetMemoryCharset },
3490 {ATGEN_ReplyGetMemory, "AT+CPBR=" ,0x00,0x00,ID_GetMemory }, 3674 {ATGEN_ReplyGetMemory, "AT+CPBR=" ,0x00,0x00,ID_GetMemory },
3491 {ATGEN_GenericReply, "AT^SBNR=?" ,0x00,0x00,ID_GetMemory }, 3675 {ATGEN_GenericReply, "AT^SBNR=?" ,0x00,0x00,ID_GetMemory },
3492 {ATGEN_SL45ReplyGetMemory, "AT^SBNR" ,0x00,0x00,ID_GetMemory }, 3676 {SIEMENS_ReplyGetMemory, "AT^SBNR" ,0x00,0x00,ID_GetMemory },
3493 {ATGEN_ReplySetMemory, "AT+CPBW" ,0x00,0x00,ID_SetMemory }, 3677 {ATGEN_ReplySetMemory, "AT+CPBW" ,0x00,0x00,ID_SetMemory },
3494 3678
3495 {ATGEN_CMS35ReplyGetBitmap, "AT^SBNR=\"bmp\"" ,0x00,0x00,ID_GetBitmap }, 3679 {SIEMENS_ReplyGetBitmap, "AT^SBNR=\"bmp\"" ,0x00,0x00,ID_GetBitmap },
3496 {ATGEN_CMS35ReplySetBitmap, "AT^SBNW=\"bmp\"" ,0x00,0x00,ID_SetBitmap }, 3680 {SIEMENS_ReplySetBitmap, "AT^SBNW=\"bmp\"" ,0x00,0x00,ID_SetBitmap },
3497 3681
3498 {ATGEN_CMS35ReplyGetRingtone, "AT^SBNR=\"mid\"" ,0x00,0x00,ID_GetRingtone }, 3682 {SIEMENS_ReplyGetRingtone, "AT^SBNR=\"mid\"" ,0x00,0x00,ID_GetRingtone },
3499 {ATGEN_CMS35ReplySetRingtone, "AT^SBNW=\"mid\"" ,0x00,0x00,ID_SetRingtone }, 3683 {SIEMENS_ReplySetRingtone, "AT^SBNW=\"mid\"" ,0x00,0x00,ID_SetRingtone },
3500 3684
3501 {ATGEN_CMS35ReplyGetNextCal, "AT^SBNR=\"vcs\"" ,0x00,0x00,ID_GetCalendarNote }, 3685 {SIEMENS_ReplyGetNextCalendar, "AT^SBNR=\"vcs\"" ,0x00,0x00,ID_GetCalendarNote },
3502 {ATGEN_CMS35ReplySetCalendar, "AT^SBNW=\"vcs\"" ,0x00,0x00,ID_SetCalendarNote }, 3686 {SIEMENS_ReplyAddCalendarNote, "AT^SBNW=\"vcs\"" ,0x00,0x00,ID_SetCalendarNote },
3503 {ATGEN_CMS35ReplyDeleteCalendar,"AT^SBNW=\"vcs\"",0x00,0x00,ID_DeleteCalendarNote }, 3687 {SIEMENS_ReplyDelCalendarNote, "AT^SBNW=\"vcs\"",0x00,0x00,ID_DeleteCalendarNote },
3504 3688
3505 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN=" ,0x00,0x00,ID_EnterSecurityCode }, 3689 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN=" ,0x00,0x00,ID_EnterSecurityCode },
3506 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN2=" ,0x00,0x00,ID_EnterSecurityCode }, 3690 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN2=" ,0x00,0x00,ID_EnterSecurityCode },
3507 {ATGEN_ReplyGetSecurityStatus, "AT+CPIN?" ,0x00,0x00,ID_GetSecurityStatus }, 3691 {ATGEN_ReplyGetSecurityStatus, "AT+CPIN?" ,0x00,0x00,ID_GetSecurityStatus },
@@ -3510,8 +3694,10 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
3510 {ATGEN_GenericReply, "AT+VTS" ,0x00,0x00,ID_SendDTMF }, 3694 {ATGEN_GenericReply, "AT+VTS" ,0x00,0x00,ID_SendDTMF },
3511 {ATGEN_ReplyCancelCall, "AT+CHUP" ,0x00,0x00,ID_CancelCall }, 3695 {ATGEN_ReplyCancelCall, "AT+CHUP" ,0x00,0x00,ID_CancelCall },
3512 {ATGEN_ReplyDialVoice, "ATDT" ,0x00,0x00,ID_DialVoice }, 3696 {ATGEN_ReplyDialVoice, "ATDT" ,0x00,0x00,ID_DialVoice },
3513 {ATGEN_ReplyCancelCall, "ATH" ,0x00,0x00,ID_CancelCall }, 3697 {ATGEN_ReplyCancelCall, "ATH" ,0x00,0x00,ID_CancelCall },
3698 {ATGEN_GenericReply, "AT+CUSD" ,0x00,0x00,ID_SetUSSD },
3699 {ATGEN_ReplyGetUSSD, "+CUSD" ,0x00,0x00,ID_IncomingFrame },
3514 {ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame }, 3700 {ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame },
3515 {ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame }, 3701 {ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame },
3516 {ATGEN_ReplyIncomingCallInfo, "+COLP" ,0x00,0x00,ID_IncomingFrame }, 3702 {ATGEN_ReplyIncomingCallInfo, "+COLP" ,0x00,0x00,ID_IncomingFrame },
3517 {ATGEN_ReplyIncomingCallInfo, "RING" ,0x00,0x00,ID_IncomingFrame }, 3703 {ATGEN_ReplyIncomingCallInfo, "RING" ,0x00,0x00,ID_IncomingFrame },
@@ -3520,8 +3706,14 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
3520 {ATGEN_ReplyReset, "AT^SRESET" ,0x00,0x00,ID_Reset }, 3706 {ATGEN_ReplyReset, "AT^SRESET" ,0x00,0x00,ID_Reset },
3521 {ATGEN_ReplyReset, "AT+CFUN=1,1" ,0x00,0x00,ID_Reset }, 3707 {ATGEN_ReplyReset, "AT+CFUN=1,1" ,0x00,0x00,ID_Reset },
3522 {ATGEN_ReplyResetPhoneSettings, "AT&F" ,0x00,0x00,ID_ResetPhoneSettings }, 3708 {ATGEN_ReplyResetPhoneSettings, "AT&F" ,0x00,0x00,ID_ResetPhoneSettings },
3523 3709
3710 {SAMSUNG_ReplyGetBitmap, "AT+IMGR=" ,0x00,0x00,ID_GetBitmap },
3711 {SAMSUNG_ReplySetBitmap, "SDNDCRC =" ,0x00,0x00,ID_SetBitmap },
3712
3713 {SAMSUNG_ReplyGetRingtone, "AT+MELR=" ,0x00,0x00,ID_GetRingtone },
3714 {SAMSUNG_ReplySetRingtone, "SDNDCRC =" ,0x00,0x00,ID_SetRingtone },
3715
3524#ifdef GSM_ENABLE_ALCATEL 3716#ifdef GSM_ENABLE_ALCATEL
3525/* Why do I give Alcatel specific things here? It's simple, Alcatel needs 3717/* Why do I give Alcatel specific things here? It's simple, Alcatel needs
3526 * some AT commands to start it's binary mode, so this needs to be in AT 3718 * some AT commands to start it's binary mode, so this needs to be in AT
3527 * related stuff. 3719 * related stuff.
@@ -3537,9 +3729,9 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
3537 {NULL, "\x00" ,0x00,0x00,ID_None } 3729 {NULL, "\x00" ,0x00,0x00,ID_None }
3538}; 3730};
3539 3731
3540GSM_Phone_Functions ATGENPhone = { 3732GSM_Phone_Functions ATGENPhone = {
3541 "A2D|iPAQ|at|M20|S25|MC35|C35i|5110|5130|5190|5210|6110|6130|6150|6190|6210|6250|6310|6310i|6510|7110|8210|8250|8290|8310|8390|8850|8855|8890|8910|9110|9210", 3733 "A2D|iPAQ|at|M20|S25|MC35|TC35|C35i|S300|5110|5130|5190|5210|6110|6130|6150|6190|6210|6250|6310|6310i|6510|7110|8210|8250|8290|8310|8390|8850|8855|8890|8910|9110|9210",
3542 ATGENReplyFunctions, 3734 ATGENReplyFunctions,
3543 ATGEN_Initialise, 3735 ATGEN_Initialise,
3544 ATGEN_Terminate, 3736 ATGEN_Terminate,
3545 ATGEN_DispatchMessage, 3737 ATGEN_DispatchMessage,
@@ -3556,11 +3748,11 @@ GSM_Phone_Functions ATGENPhone = {
3556 ATGEN_GetSIMIMSI, 3748 ATGEN_GetSIMIMSI,
3557 ATGEN_GetDateTime, 3749 ATGEN_GetDateTime,
3558 ATGEN_SetDateTime, 3750 ATGEN_SetDateTime,
3559 ATGEN_GetAlarm, 3751 ATGEN_GetAlarm,
3560 NOTIMPLEMENTED, /* SetAlarm */ 3752 ATGEN_SetAlarm,
3561 NOTSUPPORTED, /* GetLocale */ 3753 ATGEN_GetLocale,
3562 NOTSUPPORTED, /* SetLocale */ 3754 ATGEN_SetLocale,
3563 ATGEN_PressKey, 3755 ATGEN_PressKey,
3564 ATGEN_Reset, 3756 ATGEN_Reset,
3565 ATGEN_ResetPhoneSettings, 3757 ATGEN_ResetPhoneSettings,
3566 ATGEN_EnterSecurityCode, 3758 ATGEN_EnterSecurityCode,
@@ -3591,8 +3783,9 @@ GSM_Phone_Functions ATGENPhone = {
3591 ATGEN_AddSMS, 3783 ATGEN_AddSMS,
3592 ATGEN_DeleteSMS, 3784 ATGEN_DeleteSMS,
3593 ATGEN_SendSMS, 3785 ATGEN_SendSMS,
3594 ATGEN_SendSavedSMS, 3786 ATGEN_SendSavedSMS,
3787 ATGEN_SetFastSMSSending,
3595 ATGEN_SetIncomingSMS, 3788 ATGEN_SetIncomingSMS,
3596 ATGEN_SetIncomingCB, 3789 ATGEN_SetIncomingCB,
3597 ATGEN_GetSMSFolders, 3790 ATGEN_GetSMSFolders,
3598 NOTSUPPORTED, /* AddSMSFolder */ 3791 NOTSUPPORTED, /* AddSMSFolder */
@@ -3609,9 +3802,9 @@ GSM_Phone_Functions ATGENPhone = {
3609 NOTSUPPORTED, /* GetCallDivert */ 3802 NOTSUPPORTED, /* GetCallDivert */
3610 NOTSUPPORTED, /* SetCallDivert */ 3803 NOTSUPPORTED, /* SetCallDivert */
3611 NOTSUPPORTED, /* CancelAllDiverts*/ 3804 NOTSUPPORTED, /* CancelAllDiverts*/
3612 NONEFUNCTION, /* SetIncomingCall */ 3805 NONEFUNCTION, /* SetIncomingCall */
3613 NOTSUPPORTED, /* SetIncomingUSSD */ 3806 ATGEN_SetIncomingUSSD,
3614 ATGEN_SendDTMF, 3807 ATGEN_SendDTMF,
3615 ATGEN_GetRingtone, 3808 ATGEN_GetRingtone,
3616 ATGEN_SetRingtone, 3809 ATGEN_SetRingtone,
3617 NOTSUPPORTED, /* GetRingtonesInfo*/ 3810 NOTSUPPORTED, /* GetRingtonesInfo*/
@@ -3645,9 +3838,9 @@ GSM_Phone_Functions ATGENPhone = {
3645 ATGEN_DelCalendarNote, 3838 ATGEN_DelCalendarNote,
3646 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 3839 NOTIMPLEMENTED, /* DeleteAllCalendar*/
3647 NOTSUPPORTED, /* GetCalendarSettings*/ 3840 NOTSUPPORTED, /* GetCalendarSettings*/
3648 NOTSUPPORTED, /* SetCalendarSettings*/ 3841 NOTSUPPORTED, /* SetCalendarSettings*/
3649 NOTSUPPORTED, /* GetNote */ 3842 NOTSUPPORTED, /* GetNextNote */
3650 NOTSUPPORTED, /* GetProfile */ 3843 NOTSUPPORTED, /* GetProfile */
3651 NOTSUPPORTED, /* SetProfile */ 3844 NOTSUPPORTED, /* SetProfile */
3652 NOTSUPPORTED, /* GetFMStation */ 3845 NOTSUPPORTED, /* GetFMStation */
3653 NOTSUPPORTED, /* SetFMStation */ 3846 NOTSUPPORTED, /* SetFMStation */
diff --git a/gammu/emb/common/phone/at/atgen.h b/gammu/emb/common/phone/at/atgen.h
index 0e08ee4..bb5c559 100644
--- a/gammu/emb/common/phone/at/atgen.h
+++ b/gammu/emb/common/phone/at/atgen.h
@@ -41,15 +41,17 @@ typedef enum {
41 AT_HP, 41 AT_HP,
42 AT_Falcom, 42 AT_Falcom,
43 AT_Ericsson, 43 AT_Ericsson,
44 AT_Sagem, 44 AT_Sagem,
45 AT_Samsung,
45 AT_Unknown 46 AT_Unknown
46} GSM_AT_Manufacturer; 47} GSM_AT_Manufacturer;
47 48
48typedef enum { 49typedef enum {
49 AT_PBK_HEX = 1, 50 AT_PBK_HEX = 1,
50 AT_PBK_GSM, 51 AT_PBK_GSM,
51 AT_PBK_UCS2 52 AT_PBK_UCS2,
53 AT_PBK_PCCP437
52} GSM_AT_PBK_Charset; 54} GSM_AT_PBK_Charset;
53 55
54typedef enum { 56typedef enum {
55 AT_AVAILABLE = 1, 57 AT_AVAILABLE = 1,
@@ -102,8 +104,12 @@ typedef struct {
102 bool OBEX; 104 bool OBEX;
103 GSM_File file; 105 GSM_File file;
104} GSM_Phone_ATGENData; 106} GSM_Phone_ATGENData;
105 107
108 GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *);
109 GSM_Error ATGEN_HandleCMEError(GSM_StateMachine *);
110 GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *);
111
106#endif 112#endif
107 113
108/* How should editor hadle tabs in this file? Add editor commands here. 114/* How should editor hadle tabs in this file? Add editor commands here.
109 * vim: noexpandtab sw=8 ts=8 sts=8: 115 * vim: noexpandtab sw=8 ts=8 sts=8:
diff --git a/gammu/emb/common/phone/at/samsung.c b/gammu/emb/common/phone/at/samsung.c
new file mode 100644
index 0000000..55a42e5
--- a/dev/null
+++ b/gammu/emb/common/phone/at/samsung.c
@@ -0,0 +1,447 @@
1/* Samsung-specific functions
2 * Copyright (C) 2004 Claudio Matsuoka <cmatsuoka@gmail.com>
3 * Tested with S300 only!
4 */
5
6#include "../../gsmstate.h"
7
8#ifdef GSM_ENABLE_ATGEN
9
10#include <string.h>
11#include <time.h>
12#include <ctype.h>
13
14#include "../../misc/coding/coding.h"
15#include "../../gsmcomon.h"
16#include "../../service/sms/gsmsms.h"
17#include "../pfunc.h"
18
19#include "atgen.h"
20#include "samsung.h"
21
22/* Binary frame size */
23#define BLKSZ 1024
24
25struct ModelRes {
26 char *model;
27 int width;
28 int height;
29};
30
31static struct ModelRes modres[] = {
32 { "S100", 128, 128 },
33 { "S200", 128, 113 },
34 { "S300", 128, 97 },
35 { "S500", 128, 128 },
36 { "T100", 128, 128 },
37 { "E700", 128, 128 },
38 { NULL, 0, 0 }
39};
40
41/*
42 * CRC functions from the Granch SBNI12 Linux driver by
43 * Denis I. Timofeev <timofeev@granch.ru>
44 */
45static unsigned int crc32tab[] = {
46 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37,
47 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,
48 0xDCD967BF, 0xABDE5729, 0x32D70693, 0x45D03605,
49 0xDBB4A3A6, 0xACB39330, 0x35BAC28A, 0x42BDF21C,
50 0xCFB5FFE9, 0xB8B2CF7F, 0x21BB9EC5, 0x56BCAE53,
51 0xC8D83BF0, 0xBFDF0B66, 0x26D65ADC, 0x51D16A4A,
52 0xC16E77DB, 0xB669474D, 0x2F6016F7, 0x58672661,
53 0xC603B3C2, 0xB1048354, 0x280DD2EE, 0x5F0AE278,
54 0xE96CCF45, 0x9E6BFFD3, 0x0762AE69, 0x70659EFF,
55 0xEE010B5C, 0x99063BCA, 0x000F6A70, 0x77085AE6,
56 0xE7B74777, 0x90B077E1, 0x09B9265B, 0x7EBE16CD,
57 0xE0DA836E, 0x97DDB3F8, 0x0ED4E242, 0x79D3D2D4,
58 0xF4DBDF21, 0x83DCEFB7, 0x1AD5BE0D, 0x6DD28E9B,
59 0xF3B61B38, 0x84B12BAE, 0x1DB87A14, 0x6ABF4A82,
60 0xFA005713, 0x8D076785, 0x140E363F, 0x630906A9,
61 0xFD6D930A, 0x8A6AA39C, 0x1363F226, 0x6464C2B0,
62 0xA4DEAE1D, 0xD3D99E8B, 0x4AD0CF31, 0x3DD7FFA7,
63 0xA3B36A04, 0xD4B45A92, 0x4DBD0B28, 0x3ABA3BBE,
64 0xAA05262F, 0xDD0216B9, 0x440B4703, 0x330C7795,
65 0xAD68E236, 0xDA6FD2A0, 0x4366831A, 0x3461B38C,
66 0xB969BE79, 0xCE6E8EEF, 0x5767DF55, 0x2060EFC3,
67 0xBE047A60, 0xC9034AF6, 0x500A1B4C, 0x270D2BDA,
68 0xB7B2364B, 0xC0B506DD, 0x59BC5767, 0x2EBB67F1,
69 0xB0DFF252, 0xC7D8C2C4, 0x5ED1937E, 0x29D6A3E8,
70 0x9FB08ED5, 0xE8B7BE43, 0x71BEEFF9, 0x06B9DF6F,
71 0x98DD4ACC, 0xEFDA7A5A, 0x76D32BE0, 0x01D41B76,
72 0x916B06E7, 0xE66C3671, 0x7F6567CB, 0x0862575D,
73 0x9606C2FE, 0xE101F268, 0x7808A3D2, 0x0F0F9344,
74 0x82079EB1, 0xF500AE27, 0x6C09FF9D, 0x1B0ECF0B,
75 0x856A5AA8, 0xF26D6A3E, 0x6B643B84, 0x1C630B12,
76 0x8CDC1683, 0xFBDB2615, 0x62D277AF, 0x15D54739,
77 0x8BB1D29A, 0xFCB6E20C, 0x65BFB3B6, 0x12B88320,
78 0x3FBA6CAD, 0x48BD5C3B, 0xD1B40D81, 0xA6B33D17,
79 0x38D7A8B4, 0x4FD09822, 0xD6D9C998, 0xA1DEF90E,
80 0x3161E49F, 0x4666D409, 0xDF6F85B3, 0xA868B525,
81 0x360C2086, 0x410B1010, 0xD80241AA, 0xAF05713C,
82 0x220D7CC9, 0x550A4C5F, 0xCC031DE5, 0xBB042D73,
83 0x2560B8D0, 0x52678846, 0xCB6ED9FC, 0xBC69E96A,
84 0x2CD6F4FB, 0x5BD1C46D, 0xC2D895D7, 0xB5DFA541,
85 0x2BBB30E2, 0x5CBC0074, 0xC5B551CE, 0xB2B26158,
86 0x04D44C65, 0x73D37CF3, 0xEADA2D49, 0x9DDD1DDF,
87 0x03B9887C, 0x74BEB8EA, 0xEDB7E950, 0x9AB0D9C6,
88 0x0A0FC457, 0x7D08F4C1, 0xE401A57B, 0x930695ED,
89 0x0D62004E, 0x7A6530D8, 0xE36C6162, 0x946B51F4,
90 0x19635C01, 0x6E646C97, 0xF76D3D2D, 0x806A0DBB,
91 0x1E0E9818, 0x6909A88E, 0xF000F934, 0x8707C9A2,
92 0x17B8D433, 0x60BFE4A5, 0xF9B6B51F, 0x8EB18589,
93 0x10D5102A, 0x67D220BC, 0xFEDB7106, 0x89DC4190,
94 0x49662D3D, 0x3E611DAB, 0xA7684C11, 0xD06F7C87,
95 0x4E0BE924, 0x390CD9B2, 0xA0058808, 0xD702B89E,
96 0x47BDA50F, 0x30BA9599, 0xA9B3C423, 0xDEB4F4B5,
97 0x40D06116, 0x37D75180, 0xAEDE003A, 0xD9D930AC,
98 0x54D13D59, 0x23D60DCF, 0xBADF5C75, 0xCDD86CE3,
99 0x53BCF940, 0x24BBC9D6, 0xBDB2986C, 0xCAB5A8FA,
100 0x5A0AB56B, 0x2D0D85FD, 0xB404D447, 0xC303E4D1,
101 0x5D677172, 0x2A6041E4, 0xB369105E, 0xC46E20C8,
102 0x72080DF5, 0x050F3D63, 0x9C066CD9, 0xEB015C4F,
103 0x7565C9EC, 0x0262F97A, 0x9B6BA8C0, 0xEC6C9856,
104 0x7CD385C7, 0x0BD4B551, 0x92DDE4EB, 0xE5DAD47D,
105 0x7BBE41DE, 0x0CB97148, 0x95B020F2, 0xE2B71064,
106 0x6FBF1D91, 0x18B82D07, 0x81B17CBD, 0xF6B64C2B,
107 0x68D2D988, 0x1FD5E91E, 0x86DCB8A4, 0xF1DB8832,
108 0x616495A3, 0x1663A535, 0x8F6AF48F, 0xF86DC419,
109 0x660951BA, 0x110E612C, 0x88073096, 0xFF000000
110};
111
112static unsigned int GetCRC(char *data, int size)
113{
114 unsigned int crc = 0;
115
116 while (size--)
117 crc = crc32tab[(crc ^ *data++) & 0xff] ^ ((crc >> 8) & 0x00FFFFFF);
118
119 return crc;
120}
121
122/*
123 * Frame transfer
124 */
125
126static GSM_Error WaitFor(GSM_StateMachine *s, char *t, int ttl)
127{
128 char readbuf[100];
129 int n;
130 unsigned int sec;
131 GSM_DateTime Date;
132
133 GSM_GetCurrentDateTime (&Date);
134 sec = Date.Second;
135
136 n = s->Device.Functions->ReadDevice(s, readbuf, 80);
137 readbuf[n] = 0;
138 while (strstr(readbuf, t) == NULL && (sec + ttl) >= Date.Second) {
139 my_sleep(5000);
140 n = s->Device.Functions->ReadDevice(s, readbuf, 80);
141 readbuf[n] = 0;
142 GSM_GetCurrentDateTime (&Date);
143 }
144
145 return (sec + ttl) >= Date.Second ? ERR_NONE : ERR_TIMEOUT;
146}
147
148static GSM_Error SetSamsungFrame(GSM_StateMachine *s, unsigned char *buff, int size, GSM_Phone_RequestID id)
149{
150 GSM_Phone_Data *Phone = &s->Phone.Data;
151 GSM_Error error;
152 int i, count;
153
154 count = size / BLKSZ;
155
156 for (i = 0; i < count; i++) {
157 error = WaitFor(s, ">", 4);
158 if (error!=ERR_NONE) return error;
159
160 error = s->Protocol.Functions->WriteMessage(s,
161 buff + i * BLKSZ, BLKSZ, 0x00);
162 if (error!=ERR_NONE) return error;
163 }
164
165 error = WaitFor(s, ">", 4);
166 if (error!=ERR_NONE) return error;
167 error = s->Protocol.Functions->WriteMessage(s,
168 buff + i * BLKSZ, size%BLKSZ, 0x00);
169 if (error!=ERR_NONE) return error;
170
171 error = GSM_WaitFor(s, "", 0, 0x00, 4, id);
172 if (error!=ERR_NONE) return error;
173
174 return Phone->DispatchError;
175}
176
177/* Answer format for binary data transfer
178 *
179 * SDNDCRC = 0xa : RECEIVECRC = 0xcbf53a1c : BINSIZE = 5
180 * CRCERR
181 */
182static GSM_Error ReplySetSamsungFrame(GSM_Protocol_Message msg, GSM_StateMachine *s)
183{
184 unsigned long txcrc, rxcrc;
185 int binsize;
186 char *pos;
187
188 /* Parse SDNDCRC */
189 pos = strchr(msg.Buffer, '=');
190 if (!pos) return ERR_UNKNOWN;
191 pos++;
192 txcrc = strtoul(pos, NULL, 0);
193 smprintf(s, "Sent CRC : 0x%lx\n", txcrc);
194
195 /* Parse RECEIVECRC */
196 pos = strchr(pos, '=');
197 if (!pos) return ERR_UNKNOWN;
198 pos++;
199 rxcrc = strtoul(pos, NULL, 0);
200 smprintf(s, "Reveived CRC : 0x%lx\n", rxcrc);
201
202 /* Parse BINSIZE */
203 pos = strchr(pos, '=');
204 if (!pos) return ERR_UNKNOWN;
205 pos++;
206 binsize = strtoul(pos, NULL, 0);
207 smprintf(s, "Binary size : %d\n", binsize);
208
209 return txcrc == rxcrc ? ERR_NONE : ERR_WRONGCRC;
210}
211
212/*
213 * Bitmaps
214 */
215
216GSM_Error SAMSUNG_ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
217{
218 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
219 unsigned char buffer[32];
220 char *pos;
221 int location, count;
222
223 switch (Priv->ReplyState) {
224 case AT_Reply_OK:
225 smprintf(s, "Bitmap info received\n");
226 /* Parse +IMGR:location,name,0,0,0,0 */
227
228 /* Parse location */
229 pos = strchr(msg.Buffer, ':');
230 if (!pos) return ERR_UNKNOWN;
231 pos++;
232 location = atoi(pos);
233 smprintf(s, "Location : %d\n", location);
234
235 /* Parse name */
236 pos = strchr(pos, '"');
237 if (!pos) return ERR_UNKNOWN;
238 pos++;
239 for (count = 0; count < 31; count++) {
240 if (pos[count] == '"')
241 break;
242 buffer[count] = pos[count];
243 }
244 buffer[count] = 0;
245 smprintf(s, "Name : %s\n", buffer);
246 s->Phone.Data.Bitmap->Name = malloc((strlen(buffer) + 1) * 2);
247 if (s->Phone.Data.Bitmap->Name == NULL)
248 return ERR_MOREMEMORY;
249 EncodeUnicode(s->Phone.Data.Bitmap->Name, buffer, strlen(buffer));
250
251 s->Phone.Data.Bitmap->Location = location;
252
253 return ERR_NONE;
254 case AT_Reply_Error:
255 return ERR_UNKNOWN;
256 case AT_Reply_CMSError:
257 return ATGEN_HandleCMSError(s);
258 case AT_Reply_CMEError:
259 return ATGEN_HandleCMEError(s);
260 default:
261 return ERR_UNKNOWNRESPONSE;
262 }
263}
264
265GSM_Error SAMSUNG_ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
266{
267 smprintf(s, "Bitmap sent\n");
268 return ReplySetSamsungFrame(msg, s);
269}
270
271GSM_Error SAMSUNG_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
272{
273 unsigned char req[100];
274
275 s->Phone.Data.Bitmap=Bitmap;
276 smprintf(s, "Getting bitmap\n");
277 sprintf(req, "AT+IMGR=%d\r", Bitmap->Location-1);
278 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap);
279}
280
281GSM_Error SAMSUNG_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
282{
283 unsigned charreq[100];
284 unsigned longcrc;
285 GSM_Errorerror;
286 char name[50], *dot, *model;
287 GSM_Phone_Data *Data = &s->Phone.Data;
288 int i;
289
290 s->Phone.Data.Bitmap = Bitmap;
291 smprintf(s, "Setting bitmap\n");
292
293 if (Bitmap->Type != GSM_PictureBinary) {
294 smprintf(s, "Invalid picture type\n");
295 return ERR_INVALIDDATA;
296 }
297
298 if (Bitmap->BinaryPic.Type != PICTURE_GIF) {
299 smprintf(s, "Invalid binary picture type\n");
300 return ERR_INVALIDDATA;
301 }
302
303 /* Check if picture size matches phone model */
304 model = GetModelData(NULL,Data->Model,NULL)->model;
305 smprintf(s, "Checking picture size for %s\n", model);
306 for (i = 0; modres[i].model; i++) {
307 if (!strcmp(model, modres[i].model)) {
308 if (Bitmap->BitmapWidth != modres[i].width ||
309 Bitmap->BitmapHeight != modres[i].height) {
310 smprintf(s, "Model %s must use %d x %d picture size\n",
311 modres[i].model, modres[i].width,
312 modres[i].height);
313 return ERR_INVALIDDATA;
314 }
315 break;
316 }
317 }
318 if (modres[i].model == NULL) {
319 smprintf(s, "Model \"%s\" is not supported.\n", Data->Model);
320 return ERR_NOTSUPPORTED;
321 }
322
323 crc = GetCRC(Bitmap->BinaryPic.Buffer, Bitmap->BinaryPic.Length);
324
325 /* Remove extension from file name */
326 strncpy(name, DecodeUnicodeString(Bitmap->Name), 50);
327 if ((dot = strrchr(name, '.')) != NULL)
328 *dot = 0;
329
330 sprintf(req, "AT+IMGW=0,\"%s\",2,0,0,0,0,100,%d,%u\r", name,
331 Bitmap->BinaryPic.Length, (unsigned int)crc);
332
333 error = s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00);
334 if (error!=ERR_NONE) return error;
335
336 return SetSamsungFrame(s, Bitmap->BinaryPic.Buffer,
337 Bitmap->BinaryPic.Length, ID_SetBitmap);
338}
339
340/*
341 * Ringtones
342 */
343
344GSM_Error SAMSUNG_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
345{
346 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
347 unsigned char buffer[32];
348 char *pos;
349 int location, length, count;
350
351 switch (Priv->ReplyState) {
352 case AT_Reply_OK:
353 smprintf(s, "Ringtone info received\n");
354 /* Parse +MELR:location,name,size */
355
356 /* Parse location */
357 pos = strchr(msg.Buffer, ':');
358 if (!pos) return ERR_UNKNOWN;
359 pos++;
360 location = atoi(pos);
361 smprintf(s, "Location : %d\n", location);
362
363 /* Parse name */
364 pos = strchr(pos, '"');
365 if (!pos) return ERR_UNKNOWN;
366 pos++;
367 /* Ringtone.Name size is 20 chars */
368 for (count = 0; count < 19; count++) {
369 if (pos[count] == '"')
370 break;
371 buffer[count] = pos[count];
372 }
373 buffer[count] = 0;
374 smprintf(s, "Name : %s\n", buffer);
375 EncodeUnicode(s->Phone.Data.Ringtone->Name,buffer,strlen(buffer));
376
377 /* Parse ringtone length */
378 pos = strchr(pos, ',');
379 if (!pos) return ERR_UNKNOWN;
380 pos++;
381 length = atoi(pos);
382 smprintf(s, "Length : %d\n", length);
383
384 /* S300 ringtones are always MMF */
385 s->Phone.Data.Ringtone->Format = RING_MMF;
386 s->Phone.Data.Ringtone->Location = location;
387 s->Phone.Data.Ringtone->BinaryTone.Length = length;
388
389 return ERR_NONE;
390 case AT_Reply_Error:
391 return ERR_UNKNOWN;
392 case AT_Reply_CMSError:
393 return ATGEN_HandleCMSError(s);
394 case AT_Reply_CMEError:
395 return ATGEN_HandleCMEError(s);
396 default:
397 return ERR_UNKNOWNRESPONSE;
398 }
399}
400
401GSM_Error SAMSUNG_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
402{
403 unsigned char req[100];
404
405 s->Phone.Data.Ringtone = Ringtone;
406 smprintf(s, "Getting ringtone\n");
407 sprintf(req, "AT+MELR=%d\r", Ringtone->Location-1);
408 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone);
409}
410
411GSM_Error SAMSUNG_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
412{
413 smprintf(s, "Ringtone sent\n");
414 return ReplySetSamsungFrame(msg, s);
415}
416
417GSM_Error SAMSUNG_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
418{
419 unsigned charreq[100];
420 unsigned longcrc;
421 GSM_Errorerror;
422 char name[50], *dot;
423
424 s->Phone.Data.Ringtone = Ringtone;
425 smprintf(s, "Setting ringtone\n");
426
427 if (Ringtone->Format != RING_MMF) {
428 smprintf(s, "Not MMF ringtone\n");
429 return ERR_INVALIDDATA;
430 }
431
432 /* Remove extension from file name */
433 strncpy(name, DecodeUnicodeString(Ringtone->Name), 50);
434 if ((dot = strrchr(name, '.')) != NULL) *dot = 0;
435
436 crc = GetCRC(Ringtone->BinaryTone.Buffer, Ringtone->BinaryTone.Length);
437 sprintf(req, "AT+MELW=0,\"%s\",4,%d,%u\r", name,
438 Ringtone->BinaryTone.Length, (unsigned int)crc);
439
440 error = s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00);
441 if (error!=ERR_NONE) return error;
442
443 return SetSamsungFrame(s, Ringtone->BinaryTone.Buffer,
444 Ringtone->BinaryTone.Length, ID_SetRingtone);
445}
446
447#endif
diff --git a/gammu/emb/common/phone/at/samsung.h b/gammu/emb/common/phone/at/samsung.h
new file mode 100644
index 0000000..3b2947c
--- a/dev/null
+++ b/gammu/emb/common/phone/at/samsung.h
@@ -0,0 +1,16 @@
1#ifndef samsung_h
2#define samsung_h
3
4#include "../../gsmstate.h"
5
6 GSM_Error SAMSUNG_ReplyGetRingtone(GSM_Protocol_Message, GSM_StateMachine *);
7 GSM_Error SAMSUNG_ReplySetRingtone(GSM_Protocol_Message, GSM_StateMachine *);
8 GSM_Error SAMSUNG_ReplyGetBitmap(GSM_Protocol_Message, GSM_StateMachine *);
9 GSM_Error SAMSUNG_ReplySetBitmap(GSM_Protocol_Message, GSM_StateMachine *);
10 GSM_Error SAMSUNG_GetRingtone (GSM_StateMachine *, GSM_Ringtone *, bool);
11 GSM_Error SAMSUNG_SetRingtone (GSM_StateMachine *, GSM_Ringtone *, int *);
12 GSM_Error SAMSUNG_GetBitmap (GSM_StateMachine *, GSM_Bitmap *);
13 GSM_Error SAMSUNG_SetBitmap (GSM_StateMachine *, GSM_Bitmap *);
14 GSM_Error SAMSUNG_GetCallLogs (GSM_StateMachine *, GSM_MemoryEntry *, int);
15
16#endif
diff --git a/gammu/emb/common/phone/at/siemens.c b/gammu/emb/common/phone/at/siemens.c
index ab7dd2c..7f66cf8 100644
--- a/gammu/emb/common/phone/at/siemens.c
+++ b/gammu/emb/common/phone/at/siemens.c
@@ -12,27 +12,13 @@
12#include "../../gsmcomon.h" 12#include "../../gsmcomon.h"
13#include "../../service/sms/gsmsms.h" 13#include "../../service/sms/gsmsms.h"
14#include "../pfunc.h" 14#include "../pfunc.h"
15 15
16extern GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *s); 16#include "atgen.h"
17#include "siemens.h"
17 18
18GSM_Error ATGEN_CMS35ReplySetFunction (GSM_Protocol_Message msg, GSM_StateMachine *s,char *function)
19{
20 if (s->Protocol.Data.AT.EditMode) {
21 s->Protocol.Data.AT.EditMode = false;
22 return ERR_NONE;
23 }
24 dbgprintf ("Written %s",function);
25 if (s->Phone.Data.Priv.ATGEN.ReplyState == AT_Reply_OK){
26 dbgprintf (" - OK\n");
27 return ERR_NONE;
28 } else {
29 dbgprintf (" - error\n");
30 return ERR_UNKNOWN;
31 }
32}
33 19
34GSM_Error GetSiemensFrame(GSM_Protocol_Message msg, GSM_StateMachine *s, char *templ, 20static GSM_Error GetSiemensFrame(GSM_Protocol_Message msg, GSM_StateMachine *s, char *templ,
35 unsigned char *buffer, int *len) 21 unsigned char *buffer, int *len)
36{ 22{
37 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 23 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
38 int i=2, pos=0, length=0; 24 int i=2, pos=0, length=0;
@@ -56,9 +42,9 @@ GSM_Error GetSiemensFrame(GSM_Protocol_Message msg, GSM_StateMachine *s, char *t
56 *len = pos; 42 *len = pos;
57 return ERR_NONE; 43 return ERR_NONE;
58} 44}
59 45
60GSM_Error SetSiemensFrame (GSM_StateMachine *s, unsigned char *buff, char *templ, 46static GSM_Error SetSiemensFrame (GSM_StateMachine *s, unsigned char *buff, char *templ,
61 int Location, GSM_Phone_RequestID RequestID, int len) 47 int Location, GSM_Phone_RequestID RequestID, int len)
62{ 48{
63 GSM_Phone_Data *Phone = &s->Phone.Data; 49 GSM_Phone_Data *Phone = &s->Phone.Data;
64 GSM_Error error; 50 GSM_Error error;
@@ -89,9 +75,9 @@ GSM_Error SetSiemensFrame (GSM_StateMachine *s, unsigned char *buff, char *templ
89 } 75 }
90 return Phone->DispatchError; 76 return Phone->DispatchError;
91} 77}
92 78
93GSM_Error ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s) 79GSM_Error SIEMENS_ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
94{ 80{
95 unsigned char buffer[4096]; 81 unsigned char buffer[4096];
96 int length; 82 int length;
97 GSM_Error error; 83 GSM_Error error;
@@ -103,33 +89,47 @@ GSM_Error ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *
103 if (error==ERR_NONE) return error; 89 if (error==ERR_NONE) return error;
104 else return ERR_UNKNOWN; 90 else return ERR_UNKNOWN;
105} 91}
106 92
107GSM_Error ATGEN_CMS35ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s) 93GSM_Error SIEMENS_ReplySetFunction (GSM_Protocol_Message msg, GSM_StateMachine *s,char *function)
108{ 94{
109 return ATGEN_CMS35ReplySetFunction (msg, s, "Operator Logo"); 95 if (s->Protocol.Data.AT.EditMode) {
96 s->Protocol.Data.AT.EditMode = false;
97 return ERR_NONE;
98 }
99 dbgprintf ("Written %s",function);
100 if (s->Phone.Data.Priv.ATGEN.ReplyState == AT_Reply_OK){
101 dbgprintf (" - OK\n");
102 return ERR_NONE;
103 } else {
104 dbgprintf (" - error\n");
105 return ERR_UNKNOWN;
106 }
110} 107}
111 108
112GSM_Error ATGEN_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 109GSM_Error SIEMENS_ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
110{
111 return SIEMENS_ReplySetFunction (msg, s, "Operator Logo");
112}
113
114GSM_Error SIEMENS_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
113{ 115{
114 unsigned char req[32]; 116 unsigned char req[32];
115 117
116 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
117 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED; 118 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED;
118 if (Bitmap->Location-1 < 0) Bitmap->Location++; 119 if (Bitmap->Location-1 < 0) Bitmap->Location++;
119 s->Phone.Data.Bitmap=Bitmap; 120 s->Phone.Data.Bitmap=Bitmap;
120 sprintf(req, "AT^SBNR=\"bmp\",%i\r", Bitmap->Location-1); 121 sprintf(req, "AT^SBNR=\"bmp\",%i\r", Bitmap->Location-1);
121 smprintf(s, "Getting Bitmap\n"); 122 smprintf(s, "Getting Bitmap\n");
122 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap); 123 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap);
123} 124}
124 125
125GSM_Error ATGEN_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 126GSM_Error SIEMENS_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
126{ 127{
127 unsigned char buffer[4096]; 128 unsigned char buffer[4096];
128 int length; 129 int length;
129 GSM_Errorerror; 130 GSM_Errorerror;
130 131
131 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
132 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED; 132 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED;
133 133
134 error = Bitmap2BMP (buffer,NULL,Bitmap); 134 error = Bitmap2BMP (buffer,NULL,Bitmap);
135 if (error!=ERR_NONE) return error; 135 if (error!=ERR_NONE) return error;
@@ -140,9 +140,9 @@ GSM_Error ATGEN_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
140 return SetSiemensFrame(s, buffer,"bmp",Bitmap->Location-1, 140 return SetSiemensFrame(s, buffer,"bmp",Bitmap->Location-1,
141 ID_SetBitmap,length); 141 ID_SetBitmap,length);
142} 142}
143 143
144GSM_Error ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 144GSM_Error SIEMENS_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
145{ 145{
146 unsigned char buffer[32]; 146 unsigned char buffer[32];
147 int length; 147 int length;
148 GSM_Error error; 148 GSM_Error error;
@@ -157,31 +157,27 @@ GSM_Error ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine
157 EncodeUnicode (s->Phone.Data.Ringtone->Name,buffer,strlen(buffer)); 157 EncodeUnicode (s->Phone.Data.Ringtone->Name,buffer,strlen(buffer));
158 return ERR_NONE; 158 return ERR_NONE;
159} 159}
160 160
161GSM_Error ATGEN_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone) 161GSM_Error SIEMENS_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
162{ 162{
163 unsigned char req[32]; 163 unsigned char req[32];
164 164
165 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
166
167 s->Phone.Data.Ringtone=Ringtone; 165 s->Phone.Data.Ringtone=Ringtone;
168 sprintf(req, "AT^SBNR=\"mid\",%i\r", Ringtone->Location-1); 166 sprintf(req, "AT^SBNR=\"mid\",%i\r", Ringtone->Location-1);
169 smprintf(s, "Getting RingTone\n"); 167 smprintf(s, "Getting RingTone\n");
170 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone); 168 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone);
171} 169}
172 170
173GSM_Error ATGEN_CMS35ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 171GSM_Error SIEMENS_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
174{ 172{
175 return ATGEN_CMS35ReplySetFunction (msg, s, "Ringtone"); 173 return SIEMENS_ReplySetFunction (msg, s, "Ringtone");
176} 174}
177 175
178GSM_Error ATGEN_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength) 176GSM_Error SIEMENS_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
179{ 177{
180 GSM_Phone_Data *Phone = &s->Phone.Data; 178 GSM_Phone_Data *Phone = &s->Phone.Data;
181 179
182 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
183
184 if (Ringtone->Location==255) Ringtone->Location=1; 180 if (Ringtone->Location==255) Ringtone->Location=1;
185 if (Ringtone->Location-1 > 1) return ERR_INVALIDLOCATION; 181 if (Ringtone->Location-1 > 1) return ERR_INVALIDLOCATION;
186 182
187 s->Phone.Data.Ringtone= Ringtone; 183 s->Phone.Data.Ringtone= Ringtone;
@@ -189,9 +185,9 @@ GSM_Error ATGEN_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *ma
189 return SetSiemensFrame(s, Ringtone->NokiaBinary.Frame,"mid",Ringtone->Location-1, 185 return SetSiemensFrame(s, Ringtone->NokiaBinary.Frame,"mid",Ringtone->Location-1,
190 ID_SetRingtone,Ringtone->NokiaBinary.Length); 186 ID_SetRingtone,Ringtone->NokiaBinary.Length);
191} 187}
192 188
193GSM_Error ATGEN_CMS35ReplyGetNextCal(GSM_Protocol_Message msg, GSM_StateMachine *s) 189GSM_Error SIEMENS_ReplyGetNextCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s)
194{ 190{
195 GSM_Phone_Data *Data = &s->Phone.Data; 191 GSM_Phone_Data *Data = &s->Phone.Data;
196 GSM_CalendarEntry*Calendar = Data->Cal; 192 GSM_CalendarEntry*Calendar = Data->Cal;
197 GSM_ToDoEntry ToDo; 193 GSM_ToDoEntry ToDo;
@@ -234,14 +230,14 @@ GSM_Error SIEMENS_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note,
234 } 230 }
235 return error; 231 return error;
236} 232}
237 233
238GSM_Error ATGEN_CMS35ReplySetCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s) 234GSM_Error SIEMENS_ReplyAddCalendarNote(GSM_Protocol_Message msg, GSM_StateMachine *s)
239{ 235{
240 return ATGEN_CMS35ReplySetFunction (msg, s, "Calendar Note"); 236 return SIEMENS_ReplySetFunction (msg, s, "Calendar Note");
241} 237}
242 238
243GSM_Error ATGEN_CMS35ReplyDeleteCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s) 239GSM_Error SIEMENS_ReplyDelCalendarNote(GSM_Protocol_Message msg, GSM_StateMachine *s)
244{ 240{
245 GSM_Phone_Data *Data = &s->Phone.Data; 241 GSM_Phone_Data *Data = &s->Phone.Data;
246 242
247 if (Data->Cal->Location > MAX_VCALENDAR_LOCATION) return ERR_UNKNOWN; 243 if (Data->Cal->Location > MAX_VCALENDAR_LOCATION) return ERR_UNKNOWN;
@@ -282,9 +278,9 @@ GSM_Error SIEMENS_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
282 return SetSiemensFrame (s,req,"vcs",Note->Location,ID_SetCalendarNote,size); 278 return SetSiemensFrame (s,req,"vcs",Note->Location,ID_SetCalendarNote,size);
283} 279}
284 280
285/* (c) by Timo Teras */ 281/* (c) by Timo Teras */
286GSM_Error ATGEN_SL45ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 282GSM_Error SIEMENS_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
287{ 283{
288#ifndef ENABLE_LGPL 284#ifndef ENABLE_LGPL
289 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 285 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
290 GSM_MemoryEntry *Memory = s->Phone.Data.Memory; 286 GSM_MemoryEntry *Memory = s->Phone.Data.Memory;
diff --git a/gammu/emb/common/phone/at/sonyeric.c b/gammu/emb/common/phone/at/sonyeric.c
index 4b2670a..8eeb39b 100644
--- a/gammu/emb/common/phone/at/sonyeric.c
+++ b/gammu/emb/common/phone/at/sonyeric.c
@@ -10,19 +10,17 @@
10 10
11#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
12#include "../../misc/coding/coding.h" 12#include "../../misc/coding/coding.h"
13 13
14 extern GSM_Reply_Function ATGENReplyFunctions[]; 14#include "atgen.h"
15 extern GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s); 15#include "sonyeric.h"
16 16
17#ifdef GSM_ENABLE_OBEXGEN 17#ifdef GSM_ENABLE_OBEXGEN
18 18
19 extern GSM_Reply_Function OBEXGENReplyFunctions[]; 19#include "../obex/obexgen.h"
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 20
24#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 21 extern GSM_Reply_FunctionOBEXGENReplyFunctions[];
22 extern GSM_Reply_FunctionATGENReplyFunctions[];
25 23
26static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s) 24static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s)
27{ 25{
28 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 26 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
@@ -125,9 +123,9 @@ static GSM_Error SONYERIC_SetFile(GSM_StateMachine *s, unsigned char *FileName,
125#endif 123#endif
126 124
127GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 125GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
128{ 126{
129#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 127#ifdef GSM_ENABLE_OBEXGEN
130 GSM_Error error; 128 GSM_Error error;
131 GSM_ToDoEntry ToDo; 129 GSM_ToDoEntry ToDo;
132 int Pos, num, Loc; 130 int Pos, num, Loc;
133 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 131 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
@@ -161,9 +159,9 @@ GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note,
161} 159}
162 160
163GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) 161GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start)
164{ 162{
165#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 163#ifdef GSM_ENABLE_OBEXGEN
166 GSM_Error error; 164 GSM_Error error;
167 GSM_CalendarEntryCalendar; 165 GSM_CalendarEntryCalendar;
168 int Pos, num, Loc; 166 int Pos, num, Loc;
169 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 167 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
@@ -200,9 +198,9 @@ GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool st
200} 198}
201 199
202GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) 200GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
203{ 201{
204#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 202#ifdef GSM_ENABLE_OBEXGEN
205 GSM_Error error; 203 GSM_Error error;
206 GSM_ToDoEntry ToDo; 204 GSM_ToDoEntry ToDo;
207 GSM_CalendarEntry Calendar; 205 GSM_CalendarEntry Calendar;
208 int Pos; 206 int Pos;
@@ -231,9 +229,9 @@ GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
231} 229}
232 230
233GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 231GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
234{ 232{
235#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 233#ifdef GSM_ENABLE_OBEXGEN
236 unsigned char req[5000]; 234 unsigned char req[5000];
237 int size=0; 235 int size=0;
238 236
239 smprintf(s,"Adding calendar note\n"); 237 smprintf(s,"Adding calendar note\n");
@@ -247,9 +245,9 @@ GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
247} 245}
248 246
249GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 247GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
250{ 248{
251#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 249#ifdef GSM_ENABLE_OBEXGEN
252 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 250 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
253 unsigned char req[5000]; 251 unsigned char req[5000];
254 int size=0; 252 int size=0;
255 253
@@ -266,9 +264,9 @@ GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
266} 264}
267 265
268GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) 266GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s)
269{ 267{
270#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 268#ifdef GSM_ENABLE_OBEXGEN
271 GSM_Error error; 269 GSM_Error error;
272 int Pos,Level = 0,Used; 270 int Pos,Level = 0,Used;
273 unsigned char *Buf; 271 unsigned char *Buf;
274 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 272 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
@@ -318,9 +316,9 @@ GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s)
318} 316}
319 317
320GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 318GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
321{ 319{
322#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 320#ifdef GSM_ENABLE_OBEXGEN
323 GSM_Error error; 321 GSM_Error error;
324 int Pos,Level = 0,Loc=0,Used; 322 int Pos,Level = 0,Loc=0,Used;
325 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 323 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
326 unsigned char Line[2000]; 324 unsigned char Line[2000];
@@ -373,9 +371,9 @@ GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
373} 371}
374 372
375GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) 373GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
376{ 374{
377#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 375#ifdef GSM_ENABLE_OBEXGEN
378 GSM_Error error; 376 GSM_Error error;
379 GSM_ToDoEntry ToDo; 377 GSM_ToDoEntry ToDo;
380 GSM_CalendarEntry Calendar; 378 GSM_CalendarEntry Calendar;
381 int Pos; 379 int Pos;
@@ -402,9 +400,120 @@ GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *St
402 return ERR_SOURCENOTAVAILABLE; 400 return ERR_SOURCENOTAVAILABLE;
403#endif 401#endif
404} 402}
405 403
406#endif 404GSM_Error ERICSSON_ReplyGetDateLocale(GSM_Protocol_Message msg, GSM_StateMachine *s)
405 { /*Author: Peter Ondraska, based on code by Marcin Wiacek and Michal Cihar
406 License: Whatever the current maintainer of gammulib chooses, as long as there
407 is an easy way to obtain the source under GPL, otherwise the author's parts
408 of this function are GPL 2.0.
409 */
410 GSM_Locale*locale = s->Phone.Data.Locale;
411 char format;
412
413 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
414 case AT_Reply_OK:
415 smprintf(s, "Date settings received\n");
416 format=atoi(msg.Buffer);
417 switch (format) {
418 case 0: locale->DateFormat = GSM_Date_OFF;
419 locale->DateSeparator = 0;
420 break;
421 case 1: locale->DateFormat = GSM_Date_DDMMMYY;
422 locale->DateSeparator = '-';
423 break;
424 case 2: locale->DateFormat = GSM_Date_DDMMYY;
425 locale->DateSeparator = '-';
426 break;
427 case 3: locale->DateFormat = GSM_Date_MMDDYY;
428 locale->DateSeparator = '/';
429 break;
430 case 4: locale->DateFormat = GSM_Date_DDMMYY;
431 locale->DateSeparator = '/';
432 break;
433 case 5: locale->DateFormat = GSM_Date_DDMMYY;
434 locale->DateSeparator = '.';
435 break;
436 case 6: locale->DateFormat = GSM_Date_YYMMDD;
437 locale->DateSeparator = 0;
438 break;
439 case 7: locale->DateFormat = GSM_Date_YYMMDD;
440 locale->DateSeparator = '-';
441 break;
442 default:return ERR_UNKNOWNRESPONSE;
443 }
444 default:
445 return ERR_NOTSUPPORTED;
446 }
447}
448
449GSM_Error ERICSSON_ReplyGetTimeLocale(GSM_Protocol_Message msg, GSM_StateMachine *s)
450 { /*Author: Peter Ondraska
451 License: Whatever the current maintainer of gammulib chooses, as long as there
452 is an easy way to obtain the source under GPL, otherwise the author's parts
453 of this function are GPL 2.0.
454 */
455 char format;
456
457 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
458 case AT_Reply_OK:
459 smprintf(s, "Time settings received\n");
460 format=atoi(msg.Buffer);
461 switch (format) {
462 case 1:
463 case 2: s->Phone.Data.Locale->AMPMTime=(format==2);
464 return ERR_NONE;
465 default:return ERR_UNKNOWNRESPONSE;
466 }
467 default: return ERR_NOTSUPPORTED;
468 }
469}
470
471GSM_Error ERICSSON_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
472{
473 GSM_Error error;
474
475 s->Phone.Data.Locale = locale;
476
477 smprintf(s, "Getting date format\n");
478 error=GSM_WaitFor (s, "AT+ESDF?\r", 9, 0x00, 3, ID_GetLocale);
479 if (error!=ERR_NONE) return error;
480
481 smprintf(s, "Getting time format\n");
482 return GSM_WaitFor (s, "AT+ESTF?\r", 9, 0x00, 3, ID_GetLocale);
483}
484
485
486GSM_Error ERICSSON_SetLocale(GSM_StateMachine *s, GSM_Locale *locale)
487 { /*Author: Peter Ondraska
488 License: Whatever the current maintainer of gammulib chooses, as long as there
489 is an easy way to obtain the source under GPL, otherwise the author's parts
490 of this function are GPL 2.0.
491 */
492 /* this is not yet supported by gammu.c */
493 intformat=0;
494 charreq[12];
495
496 if (locale->DateFormat==GSM_Date_OFF) { format=0; } else
497 if ((locale->DateFormat==GSM_Date_DDMMMYY)&&(locale->DateSeparator=='-')) { format=1; } else
498 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='-')) { format=2; } else
499 if ((locale->DateFormat==GSM_Date_MMDDYY)&&(locale->DateSeparator=='/')) { format=3; } else
500 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='/')) { format=4; } else
501 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='.')) { format=5; } else
502 if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator==0)) { format=6; } else
503 if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator=='-')) { format=7; }
504 else { return ERR_NOTSUPPORTED; } /* ERR_WRONGINPUT */
505
506 sprintf(req,"AT+ESDF=%i\r",format);
507 smprintf(s, "Setting date format\n");
508 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
509
510 if (locale->AMPMTime) { format=2; } else { format=1; }
511 sprintf(req,"AT+ESTF=%i\r",format);
512 smprintf(s, "Setting time format\n");
513 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
514}
515
407#endif 516#endif
408 517
409/* How should editor hadle tabs in this file? Add editor commands here. 518/* How should editor hadle tabs in this file? Add editor commands here.
410 * vim: noexpandtab sw=8 ts=8 sts=8: 519 * vim: noexpandtab sw=8 ts=8 sts=8: