"at", /* Supported models in AT commands mode */
"",
"",
+ "",
4, /* Max RF Level */
0, /* Min RF Level */
GRF_Arbitrary, /* RF level units */
fprintf(stdout, _(" Model: RAE-3\n"));
#endif
strcpy(Current_Model,"RAE-3");
-
- } else {
- while (MessageBuffer[i]!=0x0d && MessageBuffer[i]!=0x0a) {
- Current_Model[i-10]=MessageBuffer[i];
- i++;
- }
- Current_Model[i-9]=0;
-
+ CurrentMagicError=GE_NONE;
+ return;
+ }
+ if (strncmp("Nokia 6210",MessageBuffer+i,10)==0) {
#ifdef DEBUG
fprintf(stdout, _("Message: Mobile phone model identification received:\n"));
- fprintf(stdout, _(" Model: %s\n"),Current_Model);
+ fprintf(stdout, _(" Model: NPE-3\n"));
#endif
+ strcpy(Current_Model,"NPE-3");
+ CurrentMagicError=GE_NONE;
+ return;
}
+ while (MessageBuffer[i]!=0x0d && MessageBuffer[i]!=0x0a) {
+ Current_Model[i-10]=MessageBuffer[i];
+ i++;
+ }
+ Current_Model[i-9]=0;
+
+#ifdef DEBUG
+ fprintf(stdout, _("Message: Mobile phone model identification received:\n"));
+ fprintf(stdout, _(" Model: %s\n"),Current_Model);
+#endif
+
CurrentMagicError=GE_NONE;
}
for (i=12;i<17;i++) fprintf(stdout,_("%c"),MessageBuffer[i]);
fprintf(stdout, _("\n"));
/* Some Nokia phones like 9210 return only firmware */
- if (MessageLength>22) {
+ if (MessageLength>24) {
fprintf(stdout, _(" Hardware: "));
for (i=21;i<25;i++) fprintf(stdout,_("%c"),MessageBuffer[i]);
fprintf(stdout, _("\n"));
Current_Revision[current++]=' ';
Current_Revision[current++]='H';
Current_Revision[current++]='W';
- if (MessageLength>22) {
+ if (MessageLength>24) {
for (i=21;i<25;i++) Current_Revision[current++]=MessageBuffer[i];
} else {
/* Some Nokia phones like 9210 return only firmware */
return GE_NOTSUPPORTED;
}
+
+ /* We try to escape AT+CMGS mode, at least Siemens M20 then needs to get some rest
+ */
+// WRITEPHONE(PortFD,"\x1B\r",2);
+// usleep(500000);
+
usleep(100);
if (Nat_SendManufacturerFrame()!=GE_NONE) return GE_TIMEOUT;
if (Nat_SendIMEIFrame()!=GE_NONE) return GE_TIMEOUT;
- if (Nat_SendHWFrame()!=GE_NONE) return GE_TIMEOUT;
-
if (Nat_SendIDFrame()!=GE_NONE) return GE_TIMEOUT;
+ if (Nat_SendHWFrame()!=GE_NONE) return GE_TIMEOUT;
+
/* In AT doesn't have any init strings, etc. Phone answered with frame,
so connection should be enabled ;-) */
CurrentLinkOK = true;
return GE_NONE;
}
+void Nat_ReplyPBKSetMemoryTypeError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+
+#ifdef DEBUG
+ fprintf(stdout, _("Message: memory setting error\n"));
+#endif
+
+ CurrentPhonebookError=GE_UNKNOWN;
+}
+
void Nat_ReplyPBKSetMemoryType(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
#ifdef DEBUG
return error;
}
+void Nat_ReplyGetMemoryLocationError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+
+#ifdef DEBUG
+ fprintf(stdout, _("Message: phonebook entry receiving error\n"));
+#endif
+
+ CurrentPhonebookError=GE_UNKNOWN;
+}
+
+/* FIXME: M20 can have " inside name. We can't get endpos by finding first " */
void Nat_ReplyGetMemoryLocation(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
char *pos, *endpos;
case GMT_ME:
/* FIXME: the 7110, 6210... supports long phonebookentries. in lack
of documentation we only support SIM memory */
- if(GetModelFeature (FN_PHONEBOOK)==F_PBK71) return GE_NOTIMPLEMENTED;
+ if(GetModelFeature (FN_PHONEBOOK)==F_PBK71INT) return GE_NOTIMPLEMENTED;
break;
default:
} else CurrentMemoryStatusError=GE_UNKNOWN;
}
+void Nat_ReplyGetMemoryStatusCPBSError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+#ifdef DEBUG
+ fprintf(stdout, _("Message: memory status receiving error\n"));
+#endif
+ CurrentMemoryStatusError=GE_UNKNOWN;
+}
+
void Nat_ReplyGetMemoryStatusCPBR(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
char *start;
int i,current;
GSM_NetworkInfo NullNetworkInfo;
+ if (!strncmp(MessageBuffer,"AT+CREG=",8)) return;
+
/* TODO: checking if phone really registered to network */
current=23;
CurrentNetworkInfoError = GE_NONE;
}
+void Nat_ReplyGetNetworkInfoCOPS(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+ /* Make sure we are expecting NetworkInfo frame */
+ if (CurrentNetworkInfo && CurrentNetworkInfoError == GE_BUSY) {
+#ifdef DEBUG
+ fprintf(stdout, _("Message: network info received\n"));
+#endif
+ if (MessageBuffer[20]=='2') {
+ CurrentNetworkInfo->NetworkCode[0]=MessageBuffer[23];
+ CurrentNetworkInfo->NetworkCode[1]=MessageBuffer[24];
+ CurrentNetworkInfo->NetworkCode[2]=MessageBuffer[25];
+ CurrentNetworkInfo->NetworkCode[3]=' ';
+ CurrentNetworkInfo->NetworkCode[4]=MessageBuffer[26];
+ CurrentNetworkInfo->NetworkCode[5]=MessageBuffer[27];
+ CurrentNetworkInfo->NetworkCode[6]=0;
+
+ CurrentNetworkInfoError = GE_NONE;
+ }
+ }
+}
+
GSM_Error Nat_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo)
{
GSM_Error error;
error=NULL_SendMessageSequence
(20, &CurrentNetworkInfoError, 9, 0x00, "AT+CREG?\r");
+ if (error!=GE_NONE) return error;
+
+ error=NULL_SendMessageSequence
+ (20, &CurrentNetworkInfoError, 9, 0x00, "AT+COPS?\r");
CurrentNetworkInfo = NULL;
{
char req[128];
- sprintf(req, "AT+CKPD=?\r");
+ sprintf(req, "AT+CKPD=\"1\",\"20\"\r");
return NULL_SendMessageSequence
(50, &CurrentPressKeyError, strlen(req), 0x00, req);
+// return GE_NOTSUPPORTED;
}
GSM_Error Nat_DialVoice(char *Number) {
CurrentSetDateTimeError=GE_NONE;
}
+void Nat_ReplyDateTimeError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+#ifdef DEBUG
+ fprintf(stdout,_("Message: date & time functions error\n"));
+#endif
+ CurrentSetDateTimeError=GE_UNKNOWN;
+ CurrentDateTimeError=GE_UNKNOWN;
+}
+
GSM_Error Nat_SetDateTime(GSM_DateTime *date_time)
{
char req[128];
(50, &CurrentSetAlarmError, strlen(req), 0x00, req);
}
+void Nat_ReplyAlarmError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+#ifdef DEBUG
+ fprintf(stdout,_("Message: alarm functions error\n"));
+#endif
+ CurrentSetAlarmError=GE_UNKNOWN;
+ CurrentAlarmError=GE_UNKNOWN;
+}
+
void Nat_ReplyGetSMSCenter(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
int i,start;
unsigned char buffer[300];
start=18;
+#ifdef DEBUG
+ fprintf(stdout, _("Message: SMSC data received\n"));
+#endif
+
/* FIXME: support for all formats */
start+=ExtractOneParameter(MessageBuffer+start, buffer);
for (i=1;i<strlen(buffer)-1;i++) buffer[i-1]=buffer[i];
buffer[i-1]=0;
- /* FIXME: when SMSC in empty, I set default (for my network) */
- /* Any better solution ? */
-// if (buffer[0]==0) strcpy(buffer,"+48602951111");
- if (buffer[0]==0) strcpy(buffer,"+48601000310");
-
- strcpy(CurrentMessageCenter->Number,buffer);
+ if (buffer[0]==0) CurrentMessageCenterError=GE_EMPTYSMSC;
+ else {
+ strcpy(CurrentMessageCenter->Number,buffer);
- /* Some default values. Is it possible to get them ? */
- CurrentMessageCenter->Name[0]=0;
- CurrentMessageCenter->DefaultRecipient[0]=0;
- CurrentMessageCenter->Format=GSMF_Text;
- CurrentMessageCenter->Validity=GSMV_Max_Time;
+ /* Some default values. Is it possible to get them ? */
+ CurrentMessageCenter->Name[0]=0;
+ CurrentMessageCenter->DefaultRecipient[0]=0;
+ CurrentMessageCenter->Format=GSMF_Text;
+ CurrentMessageCenter->Validity=GSMV_Max_Time;
#ifdef DEBUG
- fprintf(stdout, _("Message: SMSC number received\n Number: '%s'\n"),buffer);
+ fprintf(stdout, _(" Number: '%s'\n"),buffer);
#endif
- CurrentMessageCenterError=GE_NONE;
+ CurrentMessageCenterError=GE_NONE;
+ }
}
/* We only get SMSC number */
SMS_MessageType PDU=SMS_Deliver;
GSM_ETSISMSMessage ETSI;
int i,current=0,current2=0;
+ GSM_Error error;
for(i=0;i<req[0]+1;i++) ETSI.SMSCNumber[i]=req[current++];
break;
}
- GSM_DecodeETSISMS(SMS, &ETSI);
+ error=GSM_DecodeETSISMS(SMS, &ETSI);
+ if (error!=GE_NONE) return error;
return GE_NONE;
}
+void Nat_ReplyGetSMSMessageError(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
+ int error;
+
+ error=MessageBuffer[MessageLength-2]-'0';
+ error=error+(MessageBuffer[MessageLength-3]-'0')*10;
+ error=error+(MessageBuffer[MessageLength-4]-'0')*100;
+
+#ifdef DEBUG
+ fprintf(stdout, _("Message: SMS Reading failed\n"));
+
+ switch (error) {
+ case 311:fprintf(stdout, _(" No access to memory (no PIN on card ?)\n"));break;
+ case 321:fprintf(stdout, _(" Empty location!\n"));break;
+ default :fprintf(stdout, _(" Error code %i - please report it \n"),error);break;
+ }
+
+#endif
+
+ switch (error) {
+ case 311:CurrentSMSMessageError = GE_NOACCESS;break;
+ case 321:CurrentSMSMessageError = GE_EMPTYSMSLOCATION;break;
+ default :CurrentSMSMessageError = GE_UNKNOWN;break;
+ }
+}
+
void Nat_ReplyGetSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) {
int i,start,j,end;
unsigned char buffer[300],buffer2[300];
GSM_Error GSM_EncodeETSISMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int *length, SMS_MessageType PDU)
{
GSM_ETSISMSMessage ETSI;
+ GSM_Error error;
int i,current=0;
- GSM_EncodeETSISMS(SMS, &ETSI, PDU, length);
+ error=GSM_EncodeETSISMS(SMS, &ETSI, PDU, length);
+ if (error!=GE_NONE) return error;
for (i=0;i<ETSI.SMSCNumber[0]+1;i++)
req[current++]=ETSI.SMSCNumber[i];
switch (SMSATCMGF) {
case SMS_AT_PDU: /* PDU mode */
- GSM_EncodeETSISMSFrame(message, req3, &length, PDU);
+ error=GSM_EncodeETSISMSFrame(message, req3, &length, PDU);
+ if (error!=GE_NONE) return error;
if (savesms)
sprintf(req2, "AT+CMGW=%i,%i\r",(length-(req3[0]+1)),stat); //saves SMS
break;
case SMS_AT_TEXT:
- GSM_EncodeETSISMS(message, &ETSISMS, PDU, &length);
+ if (ATMan!=AT_MAN_NOKIA) {
+ switch (CurrentSMSMessage->Coding) {
+ case GSM_Coding_Unicode:
+ case GSM_Coding_8bit:
+ return GE_NOTSUPPORTED;
+ default:
+ break;
+ }
+ }
+
+ error=GSM_EncodeETSISMS(message, &ETSISMS, PDU, &length);
+ if (error!=GE_NONE) return error;
sprintf(req4, "AT+CSMP=%i,%i,%i,%i\r",
ETSISMS.firstbyte, ETSISMS.TPVP,
(10, &CurrentSMSStatusError, 13, 0x00, "AT+CPMS=\"SM\"\r");
}
+struct AT_OneReply ATRepliesError[] = {
+
+{"AT+CALA" ,Nat_ReplyAlarmError },
+{"AT+CCLK" ,Nat_ReplyDateTimeError },
+{"AT+CMGR=" ,Nat_ReplyGetSMSMessageError },
+{"AT+CPBR=" ,Nat_ReplyGetMemoryLocationError },
+{"AT+CPBS?" ,Nat_ReplyGetMemoryStatusCPBSError},
+{"AT+CPBS=" ,Nat_ReplyPBKSetMemoryTypeError },
+
+{"",NULL}
+};
+
struct AT_OneReply ATRepliesOK[] = {
{"AT+CCFC=" ,Nat_ReplyCallDivert },
{"AT+CGMI\r",Nat_ReplyGetManufacturer },
{"AT+CPBS?" ,Nat_ReplyGetMemoryStatusCPBS },
+{"AT+CPBS=" ,Nat_ReplyPBKSetMemoryType },
{"AT+CPBR=?",Nat_ReplyGetMemoryStatusCPBR },
{"AT+CPBR=" ,Nat_ReplyGetMemoryLocation },
{"AT+CPBW=" ,Nat_ReplyWritePhonebookLocation},
-{"AT+CPBS=" ,Nat_ReplyPBKSetMemoryType },
{"AT+CSCS=\"HEX\"",Nat_ReplySetCharset },
{"AT+CSCS=\"GSM\"",Nat_ReplySetCharset },
{"AT+CSCA?" ,Nat_ReplyGetSMSCenter },
{"AT+CALA?" ,Nat_ReplyGetAlarm },
{"AT+CGMM\r",Nat_ReplyGetID },
{"AT+CGMR\r",Nat_ReplyGetHW },
-{"AT+CREG?" ,Nat_ReplyGetNetworkInfo },
+{"AT+CREG" ,Nat_ReplyGetNetworkInfo },
+{"AT+COPS?" ,Nat_ReplyGetNetworkInfoCOPS },
{"AT+CGSN\r",Nat_ReplyGetIMEI },
{"AT+CHUP" ,Nat_ReplyCancelCall },
{"AT+CBC" ,Nat_ReplyGetBatteryLevel },
AnswerError=false;
if (strncmp("ERROR\r",MessageBuffer+(MessageLength-6),6)==0) AnswerError=true;
+ if (strncmp("+CMS ERROR: ",MessageBuffer+(MessageLength-16),12)==0) AnswerError=true;
AnswerOK=false;
if (strncmp("OK\r",MessageBuffer+(MessageLength-3),3)==0) AnswerOK=true;
if (ATRepliesOK[i].ReplyFunction==NULL)
fprintf(stdout,_("Message: unknown AT command\n"));
#endif
-
- if (strncmp("AT\r",MessageBuffer+start,3)==0) {
-#ifdef DEBUG
- fprintf(stdout, _("Message: used for setting DLR3 to FBUS - part 1 OK\n"));
-#endif
- CurrentGetHWError=GE_NONE;
- }
- if (strncmp("AT&F\r",MessageBuffer+start,5)==0) {
-#ifdef DEBUG
- fprintf(stdout, _("Message: used for setting DLR3 to FBUS - part 2 OK\n"));
-#endif
- CurrentGetHWError=GE_NONE;
- }
- if (strncmp("AT*NOKIAFBUS\r",MessageBuffer+start,13)==0) {
-#ifdef DEBUG
- fprintf(stdout, _("Message: Setting DLR3 to FBUS - part 3 OK\n"));
-#endif
- CurrentGetHWError=GE_NONE;
- }
}
if (AnswerError) {
- if (strncmp("AT*NOKIAFBUS\r",MessageBuffer+start,13)==0) {
+ i=0;
+ while (true) {
+ if (ATRepliesError[i].ReplyFunction==NULL) break;
+ if (strncmp(ATRepliesError[i].ReplyString,MessageBuffer+start,
+ strlen(ATRepliesError[i].ReplyString))==0) {
+ ATRepliesError[i].ReplyFunction(MessageLength-start,MessageBuffer+start,MessageType);
+ break;
+ }
+ i++;
+ }
+
#ifdef DEBUG
- fprintf(stdout, _("Message: Setting DLR3 to FBUS - part 3 ERROR\n"));
+ if (ATRepliesError[i].ReplyFunction==NULL)
+ fprintf(stdout,_("Message: unknown error AT command\n"));
#endif
-
- CurrentGetHWError=GE_INTERNALERROR;
- }
}
}