1 /***************************************************************************
2  *   copyright           : (C) 2002 by Hendrik Sattler                     *
3  *   mail                : post@hendrik-sattler.de                         *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  ***************************************************************************/
11 
12 #include "scmxx.h"
13 #include "helper.h"
14 #include "atcommand.h"
15 #include "ttyaccess.h"
16 #include "tty_bluetooth.h"
17 #include "gtincl.h"
18 #include "options.h"
19 #include "scmxx_opt.h"
20 #include "config.h"
21 
22 #include <locale.h>
23 #include <string.h>
24 #include <stdlib.h>
25 
main(int argc,char ** argv)26 int main (int argc, char** argv) {
27   char* supported_phones[] = {
28     "S25",
29     "S35i", "M35i", "MC35i", "C35i", "TC35",
30     "SL42", "SLIN", "SL45", "SLIK",
31     "C45",  "ME45", "S45",  "S45i",
32     "M50",  "MT50", "M50I",
33     "S55",
34     //there are even some phones from north america
35     "S46",
36     NULL
37   };
38 
39   unsigned int i = 0;
40   char* vendor;
41   char* model;
42 
43   int cfargc = 0;
44   char** files;
45   struct args_t* args;
46   struct tty_access* tty_funcs;
47   char* temp;
48 
49   //start setup
50   //init global vars
51   helper_init();
52 
53   //init local vars
54   vendor = NULL;
55   model = NULL;
56 
57   //setting locale of this program
58   setlocale(LC_ALL,"");
59 
60   //init the gettext stuff
61   scmxx_gettext_init();
62 
63   //the arguments must be parsed early...
64   args_init();
65   scmxx_use_envvars();
66   cfargc = scmxx_conffile_parse("config");
67   files = scmxx_args_parse(argc,argv);
68   args = scmxx_get_args();
69   verbosity_set(args->verbose);
70   if (argc <= 1 && cfargc <= 0) args->help = 1;
71 
72   //...because we must set the output charset as early as possible
73   //It also configures gettext to the new value.
74   charset_init(args->system_charset,!(args->help||args->version));
75 
76   if (args->help || args->version) {
77     if (args->help) {
78       help(argv[0],args_type_list,args_list,_("[files...]"));
79     }
80     if (args->version) {
81       printf("%s\n",PACKAGE_VERSION);
82     }
83     exit(EXIT_SUCCESS);
84   }
85 
86   /* maybe the user wants bluetooth  */
87   if (strncmp(args->port.device,"bt://",5) == 0 ||
88       strncmp(args->port.device,"bluetooth://",12) == 0) {
89     if (strncmp(args->port.device,"bt://[",6) != 0 &&
90 	strncmp(args->port.device,"bluetooth://[",13) != 0)
91       errexit("%s\n",_("Malformed bluetooth address"));
92     args->port.type = TTY_TYPE_BLUETOOTH;
93     args->port.device = strchr(args->port.device,(int)'[')+1;
94     temp = strchr(args->port.device,(int)']');
95     if (temp == NULL) errexit("%s\n",_("Malformed bluetooth address"));
96     args->port.channel = BTCHAN_RFCOMM;
97     *temp = 0;
98     if (*(temp+1) == ':') {
99       temp += 2;
100       if (str_len(temp)) args->port.channel = atoi(temp);
101     }
102     args->reset = 0;
103   }
104 
105   //now open the port
106   tty_funcs = tty_open(&args->port);
107 
108   at_init((struct at_hw_access*)tty_funcs,args->pin);
109 
110   /* Now perform initial phone setup
111    */
112   //testing the device
113   if (phone_init(args->reset,tty_funcs)) {
114     print_verbose(0,"%s\n",_("OK, a modem device is present."));
115   } else {
116     errexit("%s\n",_("cannot communicate with device."));
117   }
118   //disabling command echo
119   command_echo(0);
120 
121   //enabling advanced error response
122   //not needed everywhere but this reduces code duplication
123   verbose_errors(1);
124 
125   //changing to GSM charset
126   set_charset("GSM");
127 
128   /* Check for registered phones and print a warning on unknown ones
129    */
130   if (!args->info) {
131     vendor = at_get_vendor();
132     model = at_get_model();
133     if (vendor!=NULL) {
134       if (!strcasecmp(vendor,"SIEMENS")) {
135 	print_verbose(0,_("Detected %s %s\n"),vendor,model);
136 	for (i=0; supported_phones[i] != NULL; ++i) {
137 	  print_verbose(3,_("Comparing to registered model %s\n"),supported_phones[i]);
138 	  if (!strcmp(model,supported_phones[i])) {
139 	    break;
140 	  }
141 	}
142 	if (supported_phones[i] == NULL) {
143 	  print_warning("%s\n",
144 			_("this model was not confirmed to be working with this software."));
145 	}
146       } else {
147 	print_warning("%s\n",
148 		      _("phones from this vendor were not confirmed to be working with this software!"));
149       }
150     }
151     mem_realloc(vendor,0);
152     mem_realloc(model,0);
153   }
154 
155   if (args->time || args->smsc || args->dial || args->hangup ||
156       args->info || args->meminfo || args->lockinfo ||
157       args->lock != NULL) {
158     if ((args->smsc || args->dial) &&
159 	str_len(args->myparams.number) == 0)
160       errexit("%s\n",_("you must define a number with the --number option."));
161     if (args->time) set_time();
162     if (args->smsc) set_smsc(args->myparams.number);
163     if (args->lock != NULL) {
164       if (args->state_change > 0) lock_enable(args->lock,args->pin);
165       else if (args->state_change < 0) lock_disable(args->lock,args->pin);
166     }
167     if (args->info || args->meminfo || args->lockinfo)
168       info(args->myFILE,args->info,args->meminfo,args->lockinfo);
169     if (args->dial) dial(args->myparams.number,1);
170     if (args->hangup) hangup();
171     exit(EXIT_SUCCESS);
172   }
173 
174   switch(args->scmxx_ftype) {
175   default:
176     errexit("%s\n",_("you must specifiy a valid memory type."));
177     break;
178   case SCMXX_FTYPE_BINARY:
179     file_transfer_manage(args->scmxx_action,files,
180 			 args->myFILE,args->myPIPE,
181 			 args->myparams.mem,
182 			 args->myparams.slot);
183     break;
184   case SCMXX_FTYPE_PBOOK:
185     pbook_manage(args->scmxx_action,args->myFILE,
186 		 files,&args->myparams);
187     break;
188   case SCMXX_FTYPE_SMS:
189     sms_manage(args->scmxx_action,files,
190 	       args->myFILE,args->myPIPE,
191 	       &args->myparams,&args->mysmsopts);
192     break;
193   }
194   tty_funcs->close();
195   exit(EXIT_SUCCESS);
196 }
197