X-Git-Url: http://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=common%2Fnewmodules%2Fnewat.c;h=441370d9133e04ab139213d99fb2326bcfc84318;hp=127dd0ee507d91ae58282da4fc4848cf0fea0bbf;hb=82bcbc2300f764bcb3551b152a0a961f4fef5e66;hpb=975a83d253eea8aa37bf3dfd7e026df3027db4ff diff --git a/common/newmodules/newat.c b/common/newmodules/newat.c index 127dd0e..441370d 100644 --- a/common/newmodules/newat.c +++ b/common/newmodules/newat.c @@ -134,6 +134,7 @@ GSM_Information Nat_Information = { "at", /* Supported models in AT commands mode */ "", "", + "", 4, /* Max RF Level */ 0, /* Min RF Level */ GRF_Arbitrary, /* RF level units */ @@ -239,20 +240,30 @@ void Nat_ReplyGetID(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { 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; } @@ -279,7 +290,7 @@ void Nat_ReplyGetHW(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { 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")); @@ -292,7 +303,7 @@ void Nat_ReplyGetHW(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { 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 */ @@ -375,16 +386,22 @@ GSM_Error Nat_Initialise(char *port_device, char *initlength, 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; @@ -403,6 +420,15 @@ GSM_Error Nat_GetManufacturer(char* manufacturer) 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 @@ -465,6 +491,16 @@ GSM_Error SetCharset() 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; @@ -554,7 +590,7 @@ GSM_Error Nat_WritePhonebookLocation(GSM_PhonebookEntry * entry) 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: @@ -615,6 +651,13 @@ void Nat_ReplyGetMemoryStatusCPBS(u16 MessageLength, u8 *MessageBuffer, u8 Messa } 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; @@ -730,6 +773,8 @@ void Nat_ReplyGetNetworkInfo(u16 MessageLength, u8 *MessageBuffer, u8 MessageTyp int i,current; GSM_NetworkInfo NullNetworkInfo; + if (!strncmp(MessageBuffer,"AT+CREG=",8)) return; + /* TODO: checking if phone really registered to network */ current=23; @@ -766,6 +811,26 @@ void Nat_ReplyGetNetworkInfo(u16 MessageLength, u8 *MessageBuffer, u8 MessageTyp 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; @@ -776,6 +841,10 @@ GSM_Error Nat_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo) 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; @@ -907,10 +976,11 @@ GSM_Error Nat_PressKey(int key, int event) { 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) { @@ -1050,6 +1120,14 @@ void Nat_ReplySetDateTime(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) 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]; @@ -1109,35 +1187,45 @@ GSM_Error Nat_SetAlarm(int alarm_number, GSM_DateTime *date_time) (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;iNumber,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 */ @@ -1227,6 +1315,7 @@ GSM_Error GSM_DecodeETSISMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int le SMS_MessageType PDU=SMS_Deliver; GSM_ETSISMSMessage ETSI; int i,current=0,current2=0; + GSM_Error error; for(i=0;iCoding) { + 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, @@ -1813,15 +1942,27 @@ GSM_Error Nat_GetSMSStatus(GSM_SMSStatus *Status) (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 }, @@ -1841,7 +1982,8 @@ struct AT_OneReply ATRepliesOK[] = { {"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 }, @@ -1867,6 +2009,7 @@ void Nat_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { 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; @@ -1887,34 +2030,23 @@ void Nat_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { 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; - } } }