9 #include "../../gsmcomon.h" 10 #include "../../gsmphones.h" 11 #include "../../misc/coding/coding.h" 12 #include "../../service/gsmmisc.h" 13 #include "../../service/gsmcal.h" 14 #include "../nokia/nfunc.h" 17 #ifdef GSM_ENABLE_GNAPGEN 19 unsigned char GNAPGEN_MEMORY_TYPES[] = {
43 smprintf(s,
"Failed to load applet data!\n");
49 smprintf(s,
"Failed to load applet configuration!\n");
69 strcpy(cfg->
Model,
"obexnone");
107 if( msg->
Buffer[3] == 17){
129 unsigned char req[] = {0, 3,
148 DT->
Timezone=(10*(req[6]&0x07)+(req[6]>>4))*3600/4;
152 smprintf(s,
"Decoding date & time: ");
168 if( (buffer[0] % 2) == 0 )
169 position = (buffer[0] / 2) + 1;
171 position = ((buffer[0] +1 ) / 2) + 1;
177 switch( buffer[position] & 1 ) {
180 smprintf(s,
"Message type: SMS-DELIVER\n");
184 Layout->
Number = position;
186 if( (buffer[position] % 2) == 0 )
187 position += (buffer[position] / 2) + 1;
189 position += ((buffer[position] + 1 ) / 2) + 1;
192 Layout->
TPPID = position;
195 Layout->
TPDCS = position;
202 Layout->
TPUDL = position;
205 Layout->
Text = position;
215 smprintf(s,
"Message type: SMS-SUBMIT\n");
219 Layout->
TPMR = position;
222 Layout->
Number = position;
224 if( (buffer[position] % 2) == 0 )
225 position += (buffer[position] / 2) + 1;
227 position += ((buffer[position] + 1 ) / 2) + 1;
230 Layout->
TPPID = position;
233 Layout->
TPDCS = position;
237 if( buffer[position] & 0x16 ) {
239 Layout->
TPVP = position;
240 }
else if ( buffer[position] & 0x08 ) {
242 Layout->
TPVP = position;
247 Layout->
TPUDL = position;
250 Layout->
Text = position;
274 smprintf(s,
"ERROR: firstbyte in SMS layout not set\n");
279 if (Layout->
TPMR != 255)
smprintf(s,
"TPMR : %02x %i\n",buffer[Layout->
TPMR] ,buffer[Layout->
TPMR]);
283 if (Layout->
Text != 255)
smprintf(s,
"Text : %02x %i\n",buffer[Layout->
Text] ,buffer[Layout->
Text]);
316 if (Layout->
Number!=255) {
324 if (Layout->
Text != 255 && Layout->
TPDCS!=255 && Layout->
TPUDL!=255) {
337 smprintf(s,
"SMSC response date: ");
345 if (Layout->
TPDCS != 255) {
347 if ((buffer[Layout->
TPDCS] & 0xD0) == 0x10) {
349 if ((buffer[Layout->
TPDCS] & 0xC) == 0xC) {
350 smprintf(s,
"WARNING: reserved alphabet value in TPDCS\n");
354 }
else if ((buffer[Layout->
TPDCS] & 0xF0) == 0xF0) {
356 if ((buffer[Layout->
TPDCS] & 8) == 8) {
357 smprintf(s,
"WARNING: set reserved bit 3 in TPDCS\n");
369 if (Layout->
TPPID != 255) {
370 if (buffer[Layout->
TPPID] > 0x40 && buffer[Layout->
TPPID] < 0x48) {
382 unsigned char buffer[800];
383 int numberOfMessages = 0;
390 numberOfMessages = msg->
Buffer[4] * 256 + msg->
Buffer[5];
408 for( i=0; i<numberOfMessages; i++ ) {
409 messageLen = msg->
Buffer[current] * 256 + msg->
Buffer[current+1];
410 memset( buffer, 0, 800 );
411 memcpy( buffer, msg->
Buffer + current + 2, messageLen );
412 current += messageLen + 2;
419 GNAPGEN_PrivSetSMSLayout(s, sms, buffer, &layout );
420 GNAPGEN_DecodeSMSFrame(s, sms,buffer,messageLen,&layout);
433 unsigned char req [8] = {0,11,
435 0x00,0x10,0x00,0x3F};
465 }
while( skipfolder );
477 sms->
SMS[0].
Location = ( req[4] * (256*256*256) ) + req[5] * 256 * 256 + req[6] * 256 + req[7];
514 smprintf(s,
"SMSCNumber: %d\n", count );
522 smprintf(s,
"firstbyte: %d\n", count);
526 Layout->
TPMR = count;
541 Layout->
TPPID = count;
546 Layout->
TPDCS = count;
552 smprintf(s,
"DateTime: %d\n", count);
555 Layout->
TPVP = count;
560 Layout->
TPUDL = count;
564 Layout->
Text = count;
568 if (error !=
ERR_NONE)
return error;
584 unsigned char req [300] = {0,15};
587 memset(req+2,0x00,
sizeof(req) - 2);
588 error=GNAPGEN_EncodeSMSFrame(s, sms, req + 2, &Layout, &length);
589 if (error !=
ERR_NONE)
return error;
609 unsigned char req [300] = {0,13,
611 0x00,0x10,0x00,0x3F};
621 memset(req+8,0x00,300-8);
623 error = GNAPGEN_EncodeSMSFrame( s, sms, req + 10, &Layout, &length );
624 if (error !=
ERR_NONE)
return error;
636 return GNAPGEN_PrivSetSMSMessage(s, sms);
654 unsigned char req[] = {0x00,0x03};
657 smprintf(s,
"Getting network level\n");
673 unsigned char req[] = {0x00, 0x01};
677 smprintf(s,
"Getting battery level\n");
690 case 0x00 :
smprintf(s,
"home network ?\n");
break;
693 if (msg->
Buffer[9]==0x00) {
699 memset(buf,0,
sizeof(buf));
703 smprintf(s,
"Network name for Gammu : %s ",
718 memset(buf,0,
sizeof(buf));
727 unsigned char req[] = {0x00, 0x01};
731 smprintf(s,
"Getting network info\n");
739 smprintf(s,
"Memory status received\n");
752 unsigned char req[] = {0x00,0x07,0x00,
761 smprintf(s,
"Getting memory status\n");
766 int i,pos=8,type,subtype,len;
771 if( msg->
Buffer[3] == 17 ) {
772 smprintf(s,
"unknown memory type\n");
779 for (i=0;i<msg->
Buffer[7];i++) {
888 unsigned char req[] = {0x00, 11,
912 int i,pos=6,type,subtype,len;
917 smprintf(s,
"Phonebook entry received\n");
918 for (i=0;i<msg->
Buffer[5];i++) {
1024 unsigned char req[] = {0x00, 0x01,
1026 0x00, 0x00, 0x00, 0x00};
1039 smprintf(s,
"Getting phonebook entry\n");
1044 smprintf(s,
"Got reply: SetMemory()\n");
1045 if( msg->
Buffer[4] == 0 )
1053 unsigned char req[1000] = {0x00, 0x03,
1055 0x00, 0x00, 0x00, 0x00,
1059 int currentByte = 10;
1064 memset( req + 3,0x00,
sizeof(req) - 3 );
1077 subMemoryEntry = &entry->
Entries[i];
1084 req[currentByte++] = 0x00;
1085 req[currentByte++] = 0x0b;
1086 req[currentByte++] = 0x00;
1087 req[currentByte++] = 0x02;
1089 req[currentByte++] = 0x00;
1090 req[currentByte++] = 0x0b;
1091 req[currentByte++] = 0x00;
1092 req[currentByte++] = 0x06;
1094 req[currentByte++] = 0x00;
1095 req[currentByte++] = 0x0b;
1096 req[currentByte++] = 0x00;
1097 req[currentByte++] = 0x03;
1102 req[currentByte++] = 0x00;
1103 req[currentByte++] = 0x0b;
1104 req[currentByte++] = 0x00;
1105 req[currentByte++] = 0x04;
1109 req[currentByte++] = 0x00;
1110 req[currentByte++] = 0x08;
1111 req[currentByte++] = 0x00;
1112 req[currentByte++] = 0x00;
1116 req[currentByte++] = 0x00;
1117 req[currentByte++] = 0x07;
1118 req[currentByte++] = 0x00;
1119 req[currentByte++] = 0x00;
1127 req[currentByte++] = 0x00;
1134 req[9] = entryCount;
1146 unsigned char req[] = {0x00, 0x05,
1148 0x00, 0x00, 0x00, 0x00 };
1165 return GNAPGEN_SetMemory( s, entry );
1170 switch( msg->
Buffer[3] ) {
1175 smprintf(s,
"unknown memory type\n");
1186 unsigned char req[] = {0x00, 17,
1188 0x00, 0x00, 0x00, 0x00 };
1192 req[4] = (sms->
Location / (256*256*256)) % 256;
1193 req[5] = (sms->
Location / (256*256)) % 256;
1194 req[6] = (sms->
Location / 256) % 256 ;
1218 switch (msg->
Buffer[pos]) {
1235 unsigned char req[] = {0x00, 0x07,
1236 0x00, 0x00, 0x00, 0x00};
1256 unsigned char req[] = {0x00, 0x05,
1257 0x00, 0x00, 0x00, 0x00};
1262 smprintf(s,
"Deleting calendar note\n");
1269 int Text, Time, Alarm, Phone, EndTime, Location, current=7;
1270 unsigned char req[5000] = {
1271 0x00, 0x03,0x00,0x00,
1272 0x00, 0x00, 0x00, 0x00,
1275 switch(Note->
Type) {
1279 default : req[6] = 0x08;
break;
1286 req[current++] = DT.
Year / 256;
1287 req[current++] = DT.
Year % 256;
1288 req[current++] = DT.
Month;
1289 req[current++] = DT.
Day;
1290 req[current++] = DT.
Hour;
1291 req[current++] = DT.
Minute;
1292 req[current++] = DT.
Second;
1294 if (EndTime == -1) {
1302 req[current++] = DT.
Year / 256;
1303 req[current++] = DT.
Year % 256;
1304 req[current++] = DT.
Month;
1305 req[current++] = DT.
Day;
1306 req[current++] = DT.
Hour;
1307 req[current++] = DT.
Minute;
1308 req[current++] = DT.
Second;
1317 req[current++] = DT.
Year / 256;
1318 req[current++] = DT.
Year % 256;
1319 req[current++] = DT.
Month;
1320 req[current++] = DT.
Day;
1321 req[current++] = DT.
Hour;
1322 req[current++] = DT.
Minute;
1323 req[current++] = DT.
Second;
1348 req[current++] = 0xff;
1349 req[current++] = 0xff;
1352 smprintf(s,
"Writing calendar note\n");
1361 switch (msg->
Buffer[3]) {
1363 smprintf(s,
"Calendar note received\n");
1364 switch (msg->
Buffer[8]) {
1377 smprintf(s,
"Time : %02i-%02i-%04i %02i:%02i:%02i\n",
1385 smprintf(s,
"Time : %02i-%02i-%04i %02i:%02i:%02i\n",
1394 smprintf(s,
"Alarm : %02i-%02i-%04i %02i:%02i:%02i\n",
1408 if (msg->
Buffer[pos+1] != 0x00) {
1412 pos+=msg->
Buffer[pos+1]*2+4;
1418 if (msg->
Buffer[pos+1] != 0x00) {
1422 pos+=msg->
Buffer[pos+1]*2+2;
1430 smprintf(s,
"Can't get calendar note - too high location?\n");
1440 unsigned char req[] = {0x00, 0x01,
1441 0x00, 0x00, 0x00, 0x00};
1454 smprintf(s,
"Getting calendar note\n");
1475 unsigned char req[] = {0x00, 0x09};
1478 smprintf(s,
"Getting SMS status\n");
1488 smprintf(s,
"SMS folders names received\n");
1492 for (j=0;j<msg->
Buffer[5];j++) {
1504 if( msg->
Buffer[pos+1] == 12 )
1513 pos+=msg->
Buffer[pos+3]*2+4;
1520 unsigned char req[] = {0x00,0x01};
1523 smprintf(s,
"Getting SMS folders\n");
1561 unsigned char req[] = {0x00,21,
1588 unsigned char req[] = {0x00, 0x05};
1599 smprintf(s,
"Date & time received\n");
1606 unsigned char req[2] = {0x00,0x01};
1609 smprintf(s,
"Getting date & time\n");
1614 smprintf(s,
"Dialed voice number\n");
1620 unsigned char req[100] = {0x00,0x09};
1622 int currentByte = 2;
1624 unsigned char unicodeNumber[200];
1626 memset( req + 2,0x00,
sizeof(req) - 2 );
1630 req[currentByte++] = 0x00;
1633 memcpy( req + currentByte, unicodeNumber,
UnicodeLength( unicodeNumber ) * 2 );
1641 unsigned char buff[200];
1646 memset(buff,0,
sizeof(buff));
1647 memcpy(buff,msg->
Buffer+pos+2,len*2);
1660 unsigned char req[2] = {0x00,0x01};
1675 unsigned char buff[200];
1683 memset(buff,0,
sizeof(buff));
1684 memcpy(buff,msg->
Buffer+pos+2,len*2);
1693 unsigned char req[2] = {0x00,0x01};
1695 smprintf(s,
"Getting manufacturer\n");
1701 unsigned char buff[200];
1706 memset(buff,0,
sizeof(buff));
1707 memcpy(buff,msg->
Buffer+pos+2,len*2);
1719 unsigned char req[2] = {0x00,0x01};
1758 unsigned char req[2] = {0x00,0x01};
1774 unsigned char req[2] = {0x00,0x01};
1779 smprintf(s,
"Getting firmware version\n");
1795 error = GNAPGEN_GetManufacturer(s);
1796 if (error !=
ERR_NONE)
return error;
1804 {GNAPGEN_ReplyGetIMEI,
"\x01",0x01,0x02,
ID_GetIMEI },
1807 {GNAPGEN_ReplyGetID,
"\x01",0x01,0x02,
ID_GetModel },
1810 {GNAPGEN_ReplyGetMemory,
"\x02",0x01,0x02,
ID_GetMemory },
1813 {GNAPGEN_ReplySetMemory,
"\x02",0x01,0x04,
ID_SetMemory },
1814 {GNAPGEN_ReplyDialVoice,
"\x02",0x01,10 ,
ID_DialVoice },
1815 {GNAPGEN_ReplyGetNextMemory,
"\x02",0x01,12 ,ID_GetMemory },
1828 {GNAPGEN_ReplyGetSMSC,
"\x06",0x01,0x16,
ID_GetSMSC },
1837 {GNAPGEN_ReplyGetToDo,
"\x07",0x01,0x08,
ID_GetToDo },
1841 {GNAPGEN_ReplyGetAlarm,
"\x08",0x01,0x06,
ID_GetAlarm },
1843 {NULL,
"\x00",0x00,0x00,
ID_None }
1848 GNAPGENReplyFunctions,
1854 GNAPGEN_GetManufacturer,
1856 GNAPGEN_GetFirmware,
1864 GNAPGEN_GetDateTime,
1877 GNAPGEN_GetBatteryCharge,
1878 GNAPGEN_GetSignalQuality,
1879 GNAPGEN_GetNetworkInfo,
1883 GNAPGEN_GetMemoryStatus,
1885 GNAPGEN_GetNextMemory,
1888 GNAPGEN_DeleteMemory,
1894 GNAPGEN_GetSMSStatus,
1899 GNAPGEN_DeleteSMSMessage,
1900 GNAPGEN_SendSMSMessage,
1905 GNAPGEN_GetSMSFolders,
1946 GNAPGEN_GetNextToDo,
1953 GNAPGEN_GetNextCalendar,
1955 GNAPGEN_AddCalendar,
1956 GNAPGEN_DeleteCalendar,
GSM_Config * CurrentConfig
gboolean LastContactArrived
gboolean UseGlobalDebugFile
GSM_ChargeState ChargeState
const unsigned char * GSM_GetNetworkName(const char *NetworkCode)
char * DecodeUnicodeString(const unsigned char *src)
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
GSM_StateMachine * GSM_AllocStateMachine(void)
GSM_ToDo_Priority Priority
void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
unsigned char ReplaceMessage
GSM_MemoryType MemoryType
void FreeLines(GSM_CutLines *lines)
GSM_CalendarNoteType Type
unsigned char NetworkName[15 *2]
GSM_MemoryType NOKIA_GetMemoryType(GSM_StateMachine *s, GSM_MemoryType memory_type, unsigned char *ID)
GSM_SMSMemoryStatus * SMSStatus
char VerDate[GSM_MAX_VERSION_DATE_LENGTH+1]
GSM_MultiSMSMessage * GetSMSMessage
GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
gboolean RejectDuplicates
const char * GetLineString(const char *message, GSM_CutLines *lines, int start)
GSM_NetworkInfo * NetworkInfo
GSM_OneSMSFolder Folder[GSM_MAX_SMS_FOLDERS]
void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS)
size_t UnicodeLength(const unsigned char *str)
GSM_SMSMessageLayout PHONE_SMSDeliver
char * DayOfWeek(unsigned int year, unsigned int month, unsigned int day)
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
GSM_Error(* WriteMessage)(GSM_StateMachine *s, unsigned const char *buffer, int length, int type)
char IMEI[GSM_MAX_IMEI_LENGTH+1]
char Version[GSM_MAX_VERSION_LENGTH+1]
char Manufacturer[GSM_MAX_MANUFACTURER_LENGTH+1]
GSM_PhoneModel * ModelInfo
int smprintf_level(GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
GSM_SignalQuality * SignalQuality
void GSM_GetCalendarRecurranceRepeat(GSM_Debug_Info *di, unsigned char *rec, unsigned char *endday, GSM_CalendarEntry *entry)
void GSM_CalendarFindDefaultTextTimeAlarmPhone(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *EndTime, int *Location)
void GSM_ClearBatteryCharge(GSM_BatteryCharge *bat)
unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1) *2]
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
GSM_ValidityPeriodFormat Format
#define GSM_MAX_SMS_FOLDER_NAME_LEN
GSM_CalendarNoteType Type
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
void InitLines(GSM_CutLines *lines)
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
unsigned char Name[(GSM_MAX_SMS_NAME_LENGTH+1) *2]
GSM_Error GSM_DecodeSMSFrameText(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
struct GSM_Phone_Data::@2 Priv
GSM_SubToDoEntry Entries[GSM_TODO_ENTRIES]
GSM_Error GSM_WaitFor(GSM_StateMachine *s, unsigned const char *buffer, size_t length, int type, int timeout, GSM_Phone_RequestID request)
GSM_Error PHONE_FindDataFile(GSM_StateMachine *s, GSM_File *File, const char *ExtraPath, const char *filename)
GSM_Coding_Type GSM_GetMessageCoding(GSM_Debug_Info *di, const char TPDCS)
GSM_Phone_RequestID RequestID
unsigned char Name[(GSM_MAX_SMS_FOLDER_NAME_LEN+1) *2]
int DecodeWithBCDAlphabet(unsigned char value)
GSM_SMSMessage SMS[GSM_MAX_MULTI_SMS]
GSM_CalendarType EntryType
GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
GSM_BatteryCharge * BatteryCharge
GSM_Config * GSM_GetConfig(GSM_StateMachine *s, int num)
GSM_NetworkInfo_State State
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
GSM_Error GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet)
GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES]
GSM_MemoryType MemoryType
GSM_SMSFolders * SMSFolders
gboolean GSM_SetDebugLevel(const char *info, GSM_Debug_Info *privdi)
GSM_SMSMessageLayout PHONE_SMSSubmit
GSM_EntryLocation Location
void GSM_CreateFirmwareNumber(GSM_StateMachine *s)
GSM_Protocol_Functions * Functions
GSM_Error PHONE_UploadFile(GSM_StateMachine *s, GSM_File *File)
GSM_MemoryStatus * MemoryStatus
GSM_SMSMessage * SaveSMSMessage
void NOKIA_DecodeDateTime(GSM_StateMachine *s, unsigned char *buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse)
unsigned char MessageReference
gboolean ReplyViaSameSMSC
GSM_Error PHONE_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
unsigned char Text[(GSM_MAX_TODO_TEXT_LENGTH+1) *2]
void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines, const char *whitespaces, const size_t spaceslen, const char *quotes, const size_t quoteslen, const gboolean eot)
void GSM_FreeStateMachine(GSM_StateMachine *s)
GSM_ValidityPeriod Relative
char Model[GSM_MAX_MODEL_LENGTH+1]
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
GSM_Error GSM_DecodeSMSFrameStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
const unsigned char * GSM_GetCountryName(const char *CountryCode)
int smprintf(GSM_StateMachine *s, const char *format,...)
#define GSM_MAX_SMSC_NAME_LENGTH
GSM_Debug_Info * GSM_GetDebug(GSM_StateMachine *s)
unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1) *2]
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]