X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=gnokii%2Fgnokii.c;h=472f4e543ad7db54947cdbf8677ab97a802cba73;hp=9a562e593dee4b6dffc2d6852bdbb2de6cc5f154;hb=7752f472c7fca5f6486e67332e3b8b33bdd78f5a;hpb=2c2798de53319dcec0435cd651e3e1922bdd6e86 diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index 9a562e5..472f4e5 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -18,8 +18,143 @@ WARNING: this code is the test tool. Well, our test tool is now really powerful and useful :-) + $Log$ + Revision 1.1.1.11 2002/04/03 00:08:17 short + Found in "gnokii-working" directory, some November-patches version + + Revision 1.143 2001/09/14 13:30:07 pkot + Fixed bugs introduced during 0.3.3 merge + + Revision 1.142 2001/09/14 13:02:03 pkot + Gnokii calendar changes from 0.3.3 + + Revision 1.141 2001/09/14 12:53:00 pkot + New preview logos. + Localization fixes. + Set valid operator on logos xgnokii screen. + + Revision 1.140 2001/07/27 00:02:21 pkot + Generic AT support for the new structure (Manfred Jonsson) + + Revision 1.139 2001/07/01 23:16:45 pkot + Fixed a typo in gnokii.c avoiding saving logo (Jan Havelka) + + Revision 1.138 2001/06/28 00:28:45 pkot + Small docs updates (Pawel Kot) + + Revision 1.137 2001/06/27 23:52:50 pkot + 7110/6210 updates (Marian Jancar) + + Revision 1.136 2001/06/10 23:49:49 pkot + Small fixes to hide compilation warnings and allow gnokii.c to compile + + Revision 1.135 2001/06/10 11:42:26 machek + Cleanup: some formating, made Statemachine global, converted to new + structure w.r.t. SMS-es + + Revision 1.134 2001/05/24 20:47:30 chris + More updating of 7110 code and some of xgnokii_lowlevel changed over. + + Revision 1.133 2001/04/23 17:20:01 pkot + Added possibility for viewing logos (currently nol and ngg) on console (Bartek Klepacz) + + Revision 1.132 2001/03/21 23:36:06 chris + Added the statemachine + This will break gnokii --identify and --monitor except for 6210/7110 + + Revision 1.131 2001/03/19 23:43:46 pkot + Solaris / BSD '#if defined' cleanup + + Revision 1.130 2001/03/13 01:23:18 pkot + Windows updates (Manfred Jonsson) + + Revision 1.129 2001/03/13 01:21:39 pkot + *BSD updates (Bert Driehuis) + + Revision 1.128 2001/03/08 00:49:06 pkot + Fixed bug (introduced by me) in getmemory function. Now gnokii.c should compile + + Revision 1.127 2001/03/08 00:18:13 pkot + Fixed writephonebook once again. Someone kick me please... + + Revision 1.126 2001/03/07 21:46:12 pkot + Fixed writephonebook patch + + Revision 1.125 2001/03/06 22:19:14 pkot + Cleanups and fixes in gnokii.c: + - reindenting + - fixed bug reported by Gabriele Zappi + - fixed small bugs introduced by Pavel Machek + + Revision 1.124 2001/02/28 21:42:00 machek + Possibility to force overwrite in --getsms (-F). Possibility to get + multiple files (use --getsms -f xyzzy%d), cleanup. + + Revision 1.123 2001/02/20 21:55:11 pkot + Small #include updates + + Revision 1.122 2001/02/16 14:29:53 chris + Restructure of common/. Fixed a problem in fbus-phonet.c + Lots of dprintfs for Marcin + Any size xpm can now be loaded (eg for 7110 startup logos) + nk7110 code detects 7110/6210 and alters startup logo size to suit + Moved Marcin's extended phonebook code into gnokii.c + + Revision 1.121 2001/02/06 21:15:35 chris + Preliminary irda support for 7110 etc. Not well tested! + + Revision 1.120 2001/02/06 08:13:32 pkot + One more include in gnokii.c needed + + Revision 1.119 2001/02/05 12:29:37 pkot + Changes needed to let unicode work + + Revision 1.118 2001/02/01 15:17:33 pkot + Fixed --identify and added Manfred's manufacturer patch + + Revision 1.117 2001/01/31 23:45:27 pkot + --identify should work ok now + + Revision 1.116 2001/01/24 20:19:55 machek + Do not retry identification, if it is not implemented, it is bad idea. + + Revision 1.115 2001/01/22 01:25:10 hugh + Tweaks for 3810 series, datacalls seem to be broken so need to do + some more debugging... + + Revision 1.114 2001/01/17 02:54:55 chris + More 7110 work. Use with care! (eg it is not possible to delete phonebook entries) + I can now edit my phonebook in xgnokii but it is 'work in progress'. + + Revision 1.113 2001/01/15 17:00:49 pkot + Initial keypress sequence support. Disable compilation warning + + Revision 1.112 2001/01/12 14:09:13 pkot + More cleanups. This time mainly in the code. + + Revision 1.111 2001/01/10 16:32:18 pkot + Documentation updates. + FreeBSD fix for 3810 code. + Added possibility for deleting SMS just after reading it in gnokii. + 2110 code updates. + Many cleanups. + + Revision 1.110 2001/01/08 15:11:37 pkot + Documentation updates. + Fixed some bugs and removed FIXMEs. + We need to move some stuff from configure.in to aclocal.m4 + + Revision 1.109 2000/12/29 15:39:07 pkot + Reverted a change in fbus-3810.c which broke compling with --enable-debug. + Small fixes in gnokii.c + + Revision 1.108 2000/12/19 16:18:16 pkot + configure script updates and added shared function for configfile reading + + */ +#include "config.h" #include "misc.h" #include @@ -49,11 +184,11 @@ #include #endif + #ifdef USE_NLS #include #endif -#include "gsm-sms.h" #include "gsm-common.h" #include "gsm-api.h" #include "gsm-networks.h" @@ -137,39 +272,38 @@ char *GetProfileVibrationString(int code) } } -void short_version(void) -{ - fprintf(stderr, _("GNOKII Version %s\n"), VERSION); -} - /* This function shows the copyright and some informations usefull for debugging. */ -void version(void) + +int version(void) { - fprintf(stderr, _("Copyright (C) Hugh Blemings , 1999, 2000\n" + fprintf(stdout, _("GNOKII Version %s\n" + "Copyright (C) Hugh Blemings , 1999, 2000\n" "Copyright (C) Pavel Janík ml. , 1999, 2000\n" "Copyright (C) Pavel Machek , 2001\n" "Copyright (C) Pawe³ Kot , 2001\n" "gnokii is free software, covered by the GNU General Public License, and you are\n" "welcome to change it and/or distribute copies of it under certain conditions.\n" "There is absolutely no warranty for gnokii. See GPL for details.\n" - "Built %s %s for %s on %s \n"), __TIME__, __DATE__, model, Port); + "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, model, Port); + return 0; } /* The function usage is only informative - it prints this program's usage and command-line options. */ + int usage(void) { - fprintf(stderr, _(" usage: gnokii [--help|--monitor|--version]\n" + fprintf(stdout, _(" usage: gnokii [--help|--monitor|--version]\n" " gnokii --getmemory memory_type start [end]\n" " gnokii --writephonebook [-i]\n" " gnokii --getspeeddial number\n" " gnokii --setspeeddial number memory_type location\n" " gnokii --getsms memory_type start [end] [-f file] [-F file] [-d]\n" " gnokii --deletesms memory_type start [end]\n" - " gnokii --sendsms destination [--smsc message_center_number |\n" - " --smscno message_center_index] [-r] [-C n] [-v n]\n" - " [--long n]\n" + " gnokii --sendsms destination [-r] [-C n] [-v n]\n" + " [--longtext|--longudh] [--udh] [-8]\n" + " [--smsc message_center_number | --smscno message_center_index]\n" " gnokii --savesms [-m] [-l n] [-i]\n" " gnokii --getsmsc message_center_number\n" " gnokii --setdatetime [YYYY [MM [DD [HH [MM]]]]]\n" @@ -185,7 +319,9 @@ int usage(void) " gnokii --identify\n" " gnokii --senddtmf string\n" " gnokii --sendlogo {caller|op} destination logofile [network code]\n" + " [--smsc message_center_number | --smscno message_center_index]\n" " gnokii --sendringtone destination rtttlfile\n" + " [--smsc message_center_number | --smscno message_center_index]\n" " gnokii --setlogo op [logofile] [network code]\n" " gnokii --setlogo startup [logofile]\n" " gnokii --setlogo caller [logofile] [caller group number] [group name]\n" @@ -202,7 +338,7 @@ int usage(void) " gnokii --keysequence\n" )); #ifdef SECURITY - fprintf(stderr, _( + fprintf(stdout, _( " gnokii --entersecuritycode PIN|PIN2|PUK|PUK2\n" " gnokii --getsecuritycodestatus\n" )); @@ -218,15 +354,14 @@ static GSM_Data data; void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame)) { - int count = 0; + int count=0; GSM_Error error; - GSM_ConnectionType connection = GCT_Serial; + GSM_ConnectionType connection=GCT_Serial; GSM_DataClear(&data); - if (!strcasecmp(Connection, "dau9p")) connection = GCT_DAU9P; /* Use only with 6210/7110 for faster connection with such cable */ - if (!strcasecmp(Connection, "infrared")) connection = GCT_Infrared; - if (!strcasecmp(Connection, "irda")) connection = GCT_Irda; + if (!strcmp(Connection, "infrared")) connection=GCT_Infrared; + if (!strcmp(Connection, "irda")) connection=GCT_Irda; /* Initialise the code for the GSM interface. */ @@ -291,18 +426,18 @@ int main(int argc, char *argv[]) static struct option long_options[] = { /* FIXME: these comments are nice, but they would be more usefull as docs for the user */ - /* Display usage. */ + // Display usage. { "help", no_argument, NULL, OPT_HELP }, - /* Display version and build information. */ + // Display version and build information. { "version", no_argument, NULL, OPT_VERSION }, - /* Monitor mode */ + // Monitor mode { "monitor", no_argument, NULL, OPT_MONITOR }, #ifdef SECURITY - /* Enter Security Code mode */ + // Enter Security Code mode { "entersecuritycode", required_argument, NULL, OPT_ENTERSECURITYCODE }, // Get Security Code status @@ -358,7 +493,7 @@ int main(int argc, char *argv[]) // Send SMS message mode { "sendsms", required_argument, NULL, OPT_SENDSMS }, - // Ssve SMS message mode + // Save SMS message mode { "savesms", optional_argument, NULL, OPT_SAVESMS }, // Send logo as SMS message mode @@ -434,8 +569,8 @@ int main(int argc, char *argv[]) { OPT_DELETESMS, 2, 3, 0 }, { OPT_SENDSMS, 1, 10, 0 }, { OPT_SAVESMS, 0, 6, 0 }, - { OPT_SENDLOGO, 3, 4, GAL_XOR }, - { OPT_SENDRINGTONE, 2, 2, 0 }, + { OPT_SENDLOGO, 3, 6, 0 }, + { OPT_SENDRINGTONE, 2, 6, 0 }, { OPT_GETSMSC, 1, 1, 0 }, { OPT_GETWELCOMENOTE, 1, 1, 0 }, { OPT_SETWELCOMENOTE, 1, 1, 0 }, @@ -465,9 +600,6 @@ int main(int argc, char *argv[]) exit(-1); } - /* Introduce yourself */ - short_version(); - /* Handle command line arguments. */ c = getopt_long(argc, argv, "", long_options, NULL); if (c == -1) /* No argument given - we should display usage. */ @@ -483,8 +615,7 @@ int main(int argc, char *argv[]) case OPT_HELP: usage(); case OPT_VERSION: - version(); - exit(0); + return version(); } /* We have to build an array of the arguments which will be passed to the @@ -601,7 +732,7 @@ int main(int argc, char *argv[]) rc = setringtone(nargc, nargv); break; case OPT_SENDRINGTONE: - rc = sendringtone(nargc, nargv); + rc = sendringtone(argc, argv); break; case OPT_GETPROFILE: rc = getprofile(nargc, nargv); @@ -635,23 +766,80 @@ int main(int argc, char *argv[]) exit(-1); } +#define SMSC_SHORTCHAR_SMSC (0xF0) +#define SMSC_SHORTCHAR_SMSCNO (0xF1) +#define SMSC_OPTIONS \ + { "smsc", required_argument, NULL, SMSC_SHORTCHAR_SMSC}, \ + { "smscno", required_argument, NULL, SMSC_SHORTCHAR_SMSCNO} + +/* RETURNS: Whether the options was found as ours (=>rerun getopt_long()) + */ +static bool smsc_options_parse(int option,GSM_SMSMessage *SMS) +{ + switch (option) { + + case SMSC_SHORTCHAR_SMSC: /* SMSC number */ + SMS->MessageCenter.No = 0; + strcpy(SMS->MessageCenter.Number,optarg); + break; + + case SMSC_SHORTCHAR_SMSCNO: /* SMSC number index in phone memory */ + SMS->MessageCenter.No = atoi(optarg); + + if (SMS->MessageCenter.No < 1 || SMS->MessageCenter.No > 5) + usage(); + break; + + default: + return(false); /* option not recognized */ + } + + return(true); /* option was successfuly processed */ +} + +/* RETURNS: Success + */ +bool sendsms_deconcatenated(GSM_SMSMessage *sms,char *buf,size_t buflen,bool useudh) +{ + GSM_Deconcatenate_state SMS_Deconcatenate_state; + GSM_Error error; + + SMS_Deconcatenate_state.first=true; + while (SMS_Deconcatenate(&SMS_Deconcatenate_state,sms,buf,buflen,useudh)) { + /* Send the message. */ + error = GSM->SendSMSMessage(sms); + + if (error == GE_SMSSENDOK) { + fprintf(stdout, _("Send succeeded!\n")); + } else { + fprintf(stdout, _("SMS Send failed (error=%d)\n"), error); + return(false); + } + /* Here the sleep have no meaning. + * If it is required by some backend phone driver, it should be done THERE! + */ + /* sleep(10); */ + } + return(true); +} + /* Send SMS messages. */ int sendsms(int argc, char *argv[]) { GSM_SMSMessage SMS; - GSM_Error error; - // char UDH[GSM_MAX_USER_DATA_HEADER_LENGTH]; /* The maximum length of an uncompressed concatenated short message is 255 * 153 = 39015 default alphabet characters */ - char message_buffer[255 * GSM_MAX_SMS_LENGTH]; + char message_buffer[GSM_MAX_CONCATENATED_SMS_LENGTH]; int input_len, chars_read; - int i; /*, offset, nr_msg, aux;*/ + int i; + bool useudh = false; struct option options[] = { - { "smsc", required_argument, NULL, '1'}, - { "smscno", required_argument, NULL, '2'}, - { "long", required_argument, NULL, '3'}, - { NULL, 0, NULL, 0} + SMSC_OPTIONS, + { "longtext", no_argument, NULL, '3'}, + { "longudh", no_argument, NULL, '4'}, + { "udh", no_argument, NULL, '5'}, + { NULL, 0, NULL, 0} }; input_len = GSM_MAX_SMS_LENGTH; @@ -666,72 +854,60 @@ int sendsms(int argc, char *argv[]) - unset user data header indicator */ - memset(&SMS, 0, sizeof(GSM_SMSMessage)); - - SMS.Type = SMS_Submit; - SMS.DCS.Type = SMS_GeneralDataCoding; - SMS.DCS.u.General.Compressed = false; - SMS.DCS.u.General.Alphabet = SMS_DefaultAlphabet; - SMS.DCS.u.General.Class = 0; + SMS.Type = GST_MO; + SMS.Class = -1; + SMS.Compression = false; + SMS.EightBit = false; SMS.MessageCenter.No = 1; - SMS.Validity.VPF = SMS_RelativeFormat; - SMS.Validity.u.Relative = 4320; /* 4320 minutes == 72 hours */ - SMS.UDH_No = 0; - SMS.Report = false; + SMS.Validity = 4320; /* 4320 minutes == 72 hours */ + SMS.UDHPresent = false; - strcpy(SMS.RemoteNumber.number, argv[0]); - if (SMS.RemoteNumber.number[0] == '+') SMS.RemoteNumber.type = SMS_International; - else SMS.RemoteNumber.type = SMS_Unknown; + strcpy(SMS.Destination, argv[0]); optarg = NULL; optind = 0; while ((i = getopt_long(argc, argv, "r8cC:v:", options, NULL)) != -1) { - switch (i) { // -8 is for 8-bit data, -c for compression. both are not yet implemented. - case '1': /* SMSC number */ - SMS.MessageCenter.No = 0; - strcpy(SMS.MessageCenter.Number, optarg); - if (SMS.MessageCenter.Number[0] == '+') SMS.MessageCenter.Type = SMS_International; - else SMS.MessageCenter.Type = SMS_Unknown; + if (smsc_options_parse(i,&SMS)) + continue; + switch (i) { // -c for compression. not yet implemented. + case '3': /* we send long message in text format */ + input_len = GSM_MAX_CONCATENATED_SMS_LENGTH; + useudh = false; break; - case '2': /* SMSC number index in phone memory */ - SMS.MessageCenter.No = atoi(optarg); - - if (SMS.MessageCenter.No < 1 || SMS.MessageCenter.No > 5) - usage(); - data.MessageCenter = &SMS.MessageCenter; - error = SM_Functions(GOP_GetSMSCenter, &data, &State); - break; - case '3': /* we send long message */ - input_len = atoi(optarg); - if (input_len > 255 * GSM_MAX_SMS_LENGTH) { - fprintf(stderr, _("Input too long!\n")); - exit(-1); - } + case '4': /* we send long message in UDH format */ + input_len = GSM_MAX_CONCATENATED_SMS_LENGTH; + useudh = true; + break; + case '5': /* UDH indication requested */ + SMS.UDHPresent = true; break; case 'r': /* request for delivery report */ - SMS.Report = true; + SMS.Type = GST_DR; break; case 'C': /* class Message */ switch (*optarg) { case '0': - SMS.DCS.u.General.Class = 1; + SMS.Class = 0; break; case '1': - SMS.DCS.u.General.Class = 2; + SMS.Class = 1; break; case '2': - SMS.DCS.u.General.Class = 3; + SMS.Class = 2; break; case '3': - SMS.DCS.u.General.Class = 4; + SMS.Class = 3; break; default: usage(); } break; + case '8': /* 8-bit data */ + SMS.EightBit = true; + break; case 'v': - SMS.Validity.u.Relative = atoi(optarg); + SMS.Validity = atoi(optarg); break; default: usage(); /* Would be better to have an sendsms_usage() here. */ @@ -749,21 +925,24 @@ int sendsms(int argc, char *argv[]) return -1; } + if (SMS.UDHPresent) { +u8 UDHlen = 1 + message_buffer[0]; /* designifify */ + + if (chars_read < UDHlen || sizeof(SMS.UDH) < UDHlen) { + fprintf(stderr, _("Input too short to satisfy UDH!\n")); + return -1; + } + memcpy(SMS.UDH, message_buffer, UDHlen); + chars_read-=UDHlen; + memmove(message_buffer, message_buffer + UDHlen, chars_read); + } + /* Null terminate. */ message_buffer[chars_read] = 0x00; - strncpy(SMS.MessageText, message_buffer, chars_read); - data.SMSMessage = &SMS; - /* Send the message. */ - error = SM_Functions(GOP_SendSMS, &data, &State); - - if (error == GE_SMSSENDOK) { - fprintf(stdout, _("Send succeeded!\n")); - } else { - fprintf(stdout, _("SMS Send failed (error=%d)\n"), error); - } + sendsms_deconcatenated(&SMS,message_buffer,chars_read,useudh); - if (GSM && GSM->Terminate) GSM->Terminate(); + GSM->Terminate(); return 0; } @@ -774,24 +953,24 @@ int savesms(int argc, char *argv[]) GSM_Error error; /* The maximum length of an uncompressed concatenated short message is 255 * 153 = 39015 default alphabet characters */ - char message_buffer[255 * GSM_MAX_SMS_LENGTH]; + char message_buffer[GSM_MAX_CONCATENATED_SMS_LENGTH]; int input_len, chars_read; int i, confirm = -1; int interactive = 0; char ans[8]; /* Defaults */ - SMS.Type = SMS_Deliver; - SMS.DCS.Type = SMS_GeneralDataCoding; - SMS.DCS.u.General.Compressed = false; - SMS.DCS.u.General.Alphabet = SMS_DefaultAlphabet; - SMS.DCS.u.General.Class = 0; + SMS.Type = GST_MO; + SMS.Destination[0] = '\0'; + SMS.Class = -1; + SMS.Compression = false; + SMS.EightBit = false; SMS.MessageCenter.No = 1; - SMS.Validity.VPF = SMS_RelativeFormat; - SMS.Validity.u.Relative = 4320; /* 4320 minutes == 72 hours */ - SMS.UDH_No = 0; - SMS.Status = SMS_Unsent; - SMS.Number = 0; + SMS.Validity = 4320; /* 4320 minutes == 72 hours */ + SMS.UDHPresent = false; + SMS.Status = GSS_NOTSENTREAD; + SMS.Location = 0; + SMS.MemoryType = GMT_SM; input_len = GSM_MAX_SMS_LENGTH; @@ -799,10 +978,10 @@ int savesms(int argc, char *argv[]) while ((i = getopt(argc, argv, "ml:in:s:c:")) != -1) { switch (i) { case 'm': /* mark the message as sent */ - SMS.Status = SMS_Sent; + SMS.Status = GSS_SENTREAD; break; case 'l': /* Specify the location */ - SMS.Number = atoi(optarg); + SMS.Location = atoi(optarg); break; case 'i': /* Ask before overwriting */ interactive = 1; @@ -822,7 +1001,7 @@ int savesms(int argc, char *argv[]) if (interactive) { GSM_SMSMessage aux; - aux.Number = SMS.Number; + aux.Location = SMS.Location; data.SMSMessage = &aux; error = SM_Functions(GOP_GetSMS, &data, &State); switch (error) { @@ -831,8 +1010,8 @@ int savesms(int argc, char *argv[]) while (confirm < 0) { fprintf(stderr, _("Overwrite? (yes/no) ")); GetLine(stdin, ans, 7); - if (!strcmp(ans, _("yes"))) confirm = 1; - else if (!strcmp(ans, _("no"))) confirm = 0; + if (!strcmp(ans, "yes")) confirm = 1; + else if (!strcmp(ans, "no")) confirm = 0; } if (!confirm) { GSM->Terminate(); return 0; } else break; @@ -843,7 +1022,7 @@ int savesms(int argc, char *argv[]) default: /* FIXME: Remove this fprintf when the function is thoroughly tested */ #ifdef DEBUG - fprintf(stderr, _("Location %d empty. Saving\n"), SMS.Number); + fprintf(stderr, _("Location %d empty. Saving\n"), SMS.Location); #endif break; } @@ -864,6 +1043,7 @@ int savesms(int argc, char *argv[]) strncpy (SMS.MessageText, message_buffer, chars_read); SMS.MessageText[chars_read] = 0; + SMS.MessageTextLength=chars_read; error = GSM->SaveSMSMessage(&SMS); @@ -881,7 +1061,7 @@ int savesms(int argc, char *argv[]) /* Get SMSC number */ int getsmsc(char *MessageCenterNumber) { - SMS_MessageCenter MessageCenter; + GSM_MessageCenter MessageCenter; GSM_Data data; GSM_Error error; @@ -904,25 +1084,25 @@ int getsmsc(char *MessageCenterNumber) fprintf(stdout, _("Messages sent as ")); switch (MessageCenter.Format) { - case SMS_Text: + case GSMF_Text: fprintf(stdout, _("Text")); break; - case SMS_VoiceMail: - fprintf(stdout, _("VoiceMail")); + case GSMF_Paging: + fprintf(stdout, _("Paging")); break; - case SMS_Fax: + case GSMF_Fax: fprintf(stdout, _("Fax")); break; - case SMS_Email: -// case GSMF_UCI: + case GSMF_Email: + case GSMF_UCI: fprintf(stdout, _("Email")); break; -/* case GSMF_ERMES: + case GSMF_ERMES: fprintf(stdout, _("ERMES")); break; case GSMF_X400: fprintf(stdout, _("X.400")); - break; */ + break; default: fprintf(stdout, _("Unknown")); break; @@ -932,22 +1112,22 @@ int getsmsc(char *MessageCenterNumber) fprintf(stdout, _("Message validity is ")); switch (MessageCenter.Validity) { - case SMS_V1H: + case GSMV_1_Hour: fprintf(stdout, _("1 hour")); break; - case SMS_V6H: + case GSMV_6_Hours: fprintf(stdout, _("6 hours")); break; - case SMS_V24H: + case GSMV_24_Hours: fprintf(stdout, _("24 hours")); break; - case SMS_V72H: + case GSMV_72_Hours: fprintf(stdout, _("72 hours")); break; - case SMS_V1W: + case GSMV_1_Week: fprintf(stdout, _("1 week")); break; - case SMS_VMax: + case GSMV_Max_Time: fprintf(stdout, _("Maximum time")); break; default: @@ -973,8 +1153,6 @@ int getsmsc(char *MessageCenterNumber) int getsms(int argc, char *argv[]) { int del = 0; - SMS_Folder folder; - SMS_FolderList folderlist; GSM_SMSMessage message; char *memory_type_string; int start_message, end_message, count, mode = 1; @@ -1013,7 +1191,7 @@ int getsms(int argc, char *argv[]) mode = 0; case 'f': if (optarg) { - fprintf(stderr, _("Saving into %s\n"), optarg); + dprintf(_("Saving into %s\n"), optarg); strncpy(filename, optarg, 64); if (strlen(optarg) > 63) { fprintf(stderr, _("Filename too long - will be truncated to 63 characters.\n")); @@ -1028,37 +1206,32 @@ int getsms(int argc, char *argv[]) } } } - data.SMSFolderList = &folderlist; - folder.FolderID = 0; - data.SMSFolder = &folder; + /* Now retrieve the requested entries. */ for (count = start_message; count <= end_message; count ++) { - int offset = 0; - message.Number = count; + message.Location = count; data.SMSMessage = &message; - dprintf("MemoryType (gnokii.c) : %i\n", data.SMSMessage->MemoryType); error = SM_Functions(GOP_GetSMS, &data, &State); switch (error) { case GE_NONE: switch (message.Type) { - case SMS_Text: - fprintf(stdout, _("%d. MO Message "), message.Number); + case GST_MO: + fprintf(stdout, _("%d. Outbox Message "), message.MessageNumber); if (message.Status) fprintf(stdout, _("(sent)\n")); - fprintf(stdout, _("%d. MO Message "), message.Number); - if (message.Status) + else fprintf(stdout, _("(not sent)\n")); fprintf(stdout, _("Text: %s\n\n"), message.MessageText); break; - case SMS_Delivery_Report: - fprintf(stdout, _("%d. Delivery Report "), message.Number); + case GST_DR: + fprintf(stdout, _("%d. Delivery Report "), message.MessageNumber); if (message.Status) fprintf(stdout, _("(read)\n")); else fprintf(stdout, _("(not read)\n")); - fprintf(stdout, _("Sending date/time: %02d/%02d/%04d %02d:%02d:%02d "), \ + fprintf(stdout, _("Sending date/time: %d/%d/%d %d:%02d:%02d "), \ message.Time.Day, message.Time.Month, message.Time.Year, \ message.Time.Hour, message.Time.Minute, message.Time.Second); if (message.Time.Timezone) { @@ -1068,7 +1241,7 @@ int getsms(int argc, char *argv[]) fprintf(stdout,_("%02d00"), message.Time.Timezone); } fprintf(stdout, "\n"); - fprintf(stdout, _("Response date/time: %02d/%02d/%04d %02d:%02d:%02d "), \ + fprintf(stdout, _("Response date/time: %d/%d/%d %d:%02d:%02d "), \ message.SMSCTime.Day, message.SMSCTime.Month, message.SMSCTime.Year, \ message.SMSCTime.Hour, message.SMSCTime.Minute, message.SMSCTime.Second); if (message.SMSCTime.Timezone) { @@ -1078,16 +1251,16 @@ int getsms(int argc, char *argv[]) fprintf(stdout,_("%02d00"),message.SMSCTime.Timezone); } fprintf(stdout, "\n"); - fprintf(stdout, _("Receiver: %s Msg Center: %s\n"), message.RemoteNumber.number, message.MessageCenter.Number); + fprintf(stdout, _("Receiver: %s Msg Center: %s\n"), message.Sender, message.MessageCenter.Number); fprintf(stdout, _("Text: %s\n\n"), message.MessageText); break; default: - fprintf(stdout, _("%d. Inbox Message "), message.Number); + fprintf(stdout, _("%d. Inbox Message "), message.MessageNumber); if (message.Status) fprintf(stdout, _("(read)\n")); else fprintf(stdout, _("(not read)\n")); - fprintf(stdout, _("Date/time: %02d/%02d/%04d %02d:%02d:%02d "), \ + fprintf(stdout, _("Date/time: %d/%d/%d %d:%02d:%02d "), \ message.Time.Day, message.Time.Month, message.Time.Year, \ message.Time.Hour, message.Time.Minute, message.Time.Second); if (message.Time.Timezone) { @@ -1097,39 +1270,36 @@ int getsms(int argc, char *argv[]) fprintf(stdout,_("%02d00"),message.Time.Timezone); } fprintf(stdout, "\n"); - fprintf(stdout, _("Sender: %s Msg Center: %s\n"), message.RemoteNumber.number, message.MessageCenter.Number); - switch (message.UDH[0].Type) { - case SMS_OpLogo: + fprintf(stdout, _("Sender: %s Msg Center: %s\n"), message.Sender, message.MessageCenter.Number); + switch (SMS_DetectUDH(&message)) { + case GSM_OpLogo: fprintf(stdout, _("GSM operator logo for %s (%s) network.\n"), bitmap.netcode, GSM_GetNetworkName(bitmap.netcode)); - if (!strcmp(message.RemoteNumber.number, "+998000005") && !strcmp(message.MessageCenter.Number, "+886935074443")) fprintf(stdout, _("Saved by Logo Express\n")); - if (!strcmp(message.RemoteNumber.number, "+998000002") || !strcmp(message.RemoteNumber.number, "+998000003")) fprintf(stdout, _("Saved by Operator Logo Uploader by Thomas Kessler\n")); - offset = 3; - case SMS_CallerIDLogo: + if (!strcmp(message.Sender, "+998000005") && !strcmp(message.MessageCenter.Number, "+886935074443")) dprintf(_("Saved by Logo Express\n")); + if (!strcmp(message.Sender, "+998000002") || !strcmp(message.Sender, "+998000003")) dprintf(_("Saved by Operator Logo Uploader by Thomas Kessler\n")); + case GSM_CallerIDLogo: fprintf(stdout, ("Logo:\n")); /* put bitmap into bitmap structure */ - GSM_ReadSMSBitmap(message.UDH[0].Type, message.MessageText+2+offset, message.MessageText, &bitmap); + GSM_ReadSMSBitmap(&message, &bitmap); GSM_PrintBitmap(&bitmap); if (*filename) { error = GE_NONE; if ((stat(filename, &buf) == 0)) { fprintf(stdout, _("File %s exists.\n"), filename); - fprintf(stdout, _("Overwrite? (yes/no) ")); + fprintf(stderr, _("Overwrite? (yes/no) ")); GetLine(stdin, ans, 4); - if (!strcmp(ans, _("yes"))) { + if (!strcmp(ans, "yes")) { error = GSM_SaveBitmapFile(filename, &bitmap); } } else error = GSM_SaveBitmapFile(filename, &bitmap); - if (error != GE_NONE) fprintf(stderr, _("Couldn't save logofile %s!\n"), filename); + if (error!=GE_NONE) fprintf(stderr, _("Couldn't save logofile %s!\n"), filename); } break; - case SMS_Ringtone: - fprintf(stdout, _("Ringtone\n")); + case GSM_RingtoneUDH: + fprintf(stdout, ("Ringtone\n")); break; - case SMS_ConcatenatedMessages: - fprintf(stdout, _("Linked (%d/%d):\n"), - message.UDH[0].u.ConcatenatedShortMessage.CurrentNumber, - message.UDH[0].u.ConcatenatedShortMessage.MaximumNumber); - case SMS_NoUDH: + case GSM_ConcatenatedMessages: + fprintf(stdout, _("Linked (%d/%d):\n"),message.UDH[5],message.UDH[4]); + case GSM_NoUDH: fprintf(stdout, _("Text:\n%s\n\n"), message.MessageText); if ((mode != -1) && *filename) { char buf[1024]; @@ -1137,9 +1307,6 @@ int getsms(int argc, char *argv[]) mode = GSM_SaveTextFile(buf, message.MessageText, mode); } break; - case SMS_BusinessCard: - fprintf(stdout, _("Business Card:\n%s"), message.MessageText); - break; default: fprintf(stderr, _("Unknown\n")); break; @@ -1165,7 +1332,7 @@ int getsms(int argc, char *argv[]) fprintf(stderr, _("SMS location %s %d empty.\n"), memory_type_string, count); break; default: - fprintf(stdout, _("GetSMS %s %d failed!(%s)\n\n"), memory_type_string, count, print_error(error)); + fprintf(stdout, _("GetSMS %s %d failed!(%d)\n\n"), memory_type_string, count, error); break; } } @@ -1197,7 +1364,7 @@ int deletesms(int argc, char *argv[]) /* Now delete the requested entries. */ for (count = start_message; count <= end_message; count ++) { - message.Number = count; + message.Location = count; data.SMSMessage = &message; error = SM_Functions(GOP_DeleteSMS, &data, &State); @@ -1328,19 +1495,15 @@ int sendlogo(int argc, char *argv[]) { GSM_SMSMessage SMS; GSM_Bitmap bitmap; - GSM_Error error; - char UserDataHeader[7] = { 0x06, /* UDH Length */ - 0x05, /* IEI: application port addressing scheme, 16 bit address */ - 0x04, /* IEI length */ - 0x15, /* destination address: high byte */ - 0x00, /* destination address: low byte */ - 0x00, /* originator address */ - 0x00}; + char Data[sizeof(bitmap.bitmap) +64/*headers safety*/]; - char Data[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + int current=0, i; - int current=0; + struct option options[] = { + SMSC_OPTIONS, + { NULL, 0, NULL, 0} + }; /* Default settings for SMS message: - no delivery report @@ -1351,23 +1514,36 @@ int sendlogo(int argc, char *argv[]) - validity 3 days - set UserDataHeaderIndicator */ - SMS.Type = SMS_Submit; - SMS.DCS.Type = SMS_GeneralDataCoding; - SMS.DCS.u.General.Compressed = false; - SMS.DCS.u.General.Alphabet = SMS_8bit; - SMS.DCS.u.General.Class = 2; + + SMS.Type = GST_MO; + SMS.Class = 1; + SMS.Compression = false; + SMS.EightBit = true; SMS.MessageCenter.No = 1; - SMS.Validity.VPF = SMS_RelativeFormat; - SMS.Validity.u.Relative = 4320; /* 4320 minutes == 72 hours */ + SMS.Validity = 4320; /* 4320 minutes == 72 hours */ + + optarg = NULL; + optind = 0; + while ((i = getopt_long(argc, argv, "", options, NULL)) != -1) { + if (smsc_options_parse(i,&SMS)) + continue; + switch (i) { + default: + usage(); /* Would be better to have an sendsms_usage() here. */ + } + } + +/* + if (argc!=3 && argc!=4) + usage(); +*/ /* The first argument is the type of the logo. */ if (!strcmp(argv[0], "op")) { - SMS.UDH[0].Type = SMS_OpLogo; - UserDataHeader[4] = 0x82; /* NBS port 0x1582 */ + SMS_SetupUDH(&SMS,GSM_OpLogo); /* error ignored */ fprintf(stdout, _("Sending operator logo.\n")); - } else if (!strcmp(argv[0], "caller")) { - SMS.UDH[0].Type = SMS_CallerIDLogo; - UserDataHeader[4] = 0x83; /* NBS port 0x1583 */ + } else if (!strcmp(argv[0], "caller")) { /* error ignored */ + SMS_SetupUDH(&SMS,GSM_CallerIDLogo); fprintf(stdout, _("Sending caller line identification logo.\n")); } else { fprintf(stderr, _("You should specify what kind of logo to send!\n")); @@ -1375,7 +1551,7 @@ int sendlogo(int argc, char *argv[]) } /* The second argument is the destination, ie the phone number of recipient. */ - SMS.MemoryType = atoi(argv[1]); + strcpy(SMS.Destination,argv[1]); /* The third argument is the bitmap file. */ GSM_ReadBitmapFile(argv[2], &bitmap); @@ -1400,23 +1576,17 @@ int sendlogo(int argc, char *argv[]) } /* Set the logo size */ - current++; + Data[current++] = 0x00; /* RFU by Nokia */ Data[current++] = bitmap.width; Data[current++] = bitmap.height; - Data[current++] = 0x01; - - memcpy(SMS.MessageText, UserDataHeader, 7); - memcpy(SMS.MessageText, Data, current); - memcpy(SMS.MessageText+current, bitmap.bitmap, bitmap.size); + Data[current++] = 0x01; /* depth=number of grayscales */ + memcpy(Data+current,bitmap.bitmap,bitmap.size); + current+=bitmap.size; + /* Send the message. */ - error = GSM->SendSMSMessage(&SMS,current+bitmap.size); - - if (error == GE_SMSSENDOK) - fprintf(stdout, _("Send succeeded!\n")); - else - fprintf(stdout, _("SMS Send failed (error=%d)\n"), error); + sendsms_deconcatenated(&SMS,Data,current,true/*useudh*/); GSM->Terminate(); return 0; @@ -2795,24 +2965,70 @@ int pmon(void) int sendringtone(int argc, char *argv[]) { + GSM_SMSMessage SMS; GSM_Ringtone ringtone; - GSM_Error error; + int i; + int size = GSM_MAX_RINGTONE_PACKAGE_LENGTH; + char Package[GSM_MAX_RINGTONE_PACKAGE_LENGTH]; - if (GSM_ReadRingtoneFile(argv[0], &ringtone)) { + struct option options[] = { + SMSC_OPTIONS, + { NULL, 0, NULL, 0} + }; + + /* Default settings for SMS message: + - no delivery report + - Class Message 1 + - no compression + - 8 bit data + - SMSC no. 1 + - validity 3 days + - set UserDataHeaderIndicator + */ + + SMS.Type = GST_MO; + SMS.Class = 1; + SMS.Compression = false; + SMS.EightBit = true; + SMS.MessageCenter.No = 1; + SMS.Validity = 4320; /* 4320 minutes == 72 hours */ + + SMS_SetupUDH(&SMS,GSM_RingtoneUDH); /* error ignored */ + + optarg = NULL; + optind = 0; + argv[1]=argv[0]; + argv++; + argc--; + while ((i = getopt_long(argc, argv, "", options, NULL)) != -1) { + if (smsc_options_parse(i,&SMS)) + continue; + switch (i) { + default: + usage(); /* Would be better to have an sendsms_usage() here. */ + } + } + argc-=optind; + argv+=optind; + + if (argc!=2) + usage(); + + if (GSM_ReadRingtoneFile(argv[1], &ringtone)) { fprintf(stdout, _("Failed to load ringtone.\n")); return(-1); } + if (strlen(argv[0])+1 > sizeof(SMS.Destination)) { + fprintf(stdout, _("Destination number \"%s\" length too long!\n"), argv[0]); + return(-1); + } + strcpy(SMS.Destination, argv[0]); + GSM_PackRingtone(&ringtone, Package, &size); - error = GSM->SendRingtone(&ringtone,argv[1]); - - if (error == GE_NONE) - fprintf(stdout, _("Send succeeded!\n")); - else - fprintf(stdout, _("SMS Send failed (error=%d)\n"), error); + sendsms_deconcatenated(&SMS,Package,size,true/*useudh*/); GSM->Terminate(); return 0; - } @@ -2835,7 +3051,6 @@ int setringtone(int argc, char *argv[]) GSM->Terminate(); return 0; - } int presskeysequence(void)