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 <atcommand.h>
13 #include <helper.h>
14
15 #include <stdio.h>
16 #include <stdarg.h>
17 #include <string.h>
18 #include <strings.h>
19 #include <errno.h>
20
at_sie_blacklisted(char * model)21 static int at_sie_blacklisted (char* model) {
22 if (strcmp(model,"SF65") == 0) return 1;
23 return 0;
24 }
25
at_sie_supported()26 int at_sie_supported () {
27 char* vendor = at_get_vendor();
28 char* model = at_get_model();
29 int retval = 1;
30
31 if (at_sie_blacklisted(model) || strcasecmp(vendor,"SIEMENS"))
32 retval = 0;
33
34 mem_realloc(vendor,0);
35 mem_realloc(model,0);
36 return retval;
37 }
38
at_sie_pref_op_read(unsigned int index1,unsigned int index2)39 char* at_sie_pref_op_read (unsigned int index1,
40 unsigned int index2)
41 {
42 char* parmlist;
43
44 if (!at_sie_supported()) return NULL;
45
46 parmlist = mem_alloc(numlen(index1)+1+numlen(index2)+1,1);
47 if (index2 > index1)
48 sprintf(parmlist,"%d,%d",index1,index2);
49 else
50 sprintf(parmlist,"%d",index1);
51 at_command_send(AT_SIE_PREF_OP_READ,parmlist);
52 mem_realloc(parmlist,0);
53 return AT_SIE_PREF_OP_READ;
54 }
55
at_sie_password(const char * lock,const char * oldpin,const char * newpin)56 char* at_sie_password (const char* lock,
57 const char* oldpin,
58 const char* newpin)
59 {
60 char* parmlist;
61
62 if (!at_sie_supported())
63 return at_gen_password(lock,oldpin,newpin);
64
65 if (str_len(lock) == 0 ||
66 (oldpin == NULL && newpin == NULL))
67 return NULL;
68 parmlist = mem_alloc(1+strlen(lock)+3+str_len(oldpin)+3
69 +str_len(newpin)+1,1);
70 if (oldpin == NULL) {
71 //there is no pin set, yet
72 sprintf(parmlist,"\"%s\",,\"%s\"",lock,newpin);
73 } else {
74 if (newpin == NULL) {
75 //delete the pin
76 sprintf(parmlist,"\"%s\",\"%s\"",lock,oldpin);
77 } else {
78 sprintf(parmlist,"\"%s\",\"%s\",\"%s\"",lock,oldpin,newpin);
79 }
80 }
81 at_command_send(AT_SIE_PASSWORD,parmlist);
82 mem_realloc(parmlist,0);
83 return AT_SIE_PASSWORD;
84 }
85
at_sie_lock(const char * lock,int mode,const char * password,uint8_t class)86 char* at_sie_lock (const char* lock, int mode,
87 const char* password, uint8_t class)
88 {
89 char* parmlist;
90
91 if (str_len(lock) == 0) return NULL;
92
93 if (!at_sie_supported())
94 return at_gen_lock(lock,mode,password,class);
95
96 parmlist = mem_alloc(1+strlen(lock)+1
97 +1+numlen(mode)
98 +2+str_len(password)+1
99 +1+numlen(class)+1,1);
100 if (class > 0)
101 if (str_len(password))
102 sprintf(parmlist,"\"%s\",%d,\"%s\",%d",lock,mode,password,class);
103 else
104 sprintf(parmlist,"\"%s\",%d,,%d",lock,mode,class);
105 else
106 if (str_len(password))
107 sprintf(parmlist,"\"%s\",%d,\"%s\"",lock,mode,password);
108 else
109 sprintf(parmlist,"\"%s\",%d",lock,mode);
110 at_command_send(AT_SIE_LOCK,parmlist);
111 mem_realloc(parmlist,0);
112 return AT_SIE_LOCK;
113 }
114
at_sie_binary_write(const char * ftype,unsigned int slot,int part,int total)115 char* at_sie_binary_write (const char* ftype,
116 unsigned int slot,
117 int part, int total)
118 {
119 char* parmlist;
120
121 if (str_len(ftype) == 0) return NULL;
122 if (!at_sie_supported()) return NULL;
123
124 parmlist = mem_alloc(1+strlen(ftype)+2+numlen(slot)
125 +1+numlen(part)+1+numlen(total)
126 +1,
127 1);
128 if (part < 0 || total < 0) {
129 sprintf(parmlist,"\"%s\",%d",ftype,slot);
130 } else if (part == 0 || total == 0) {
131 sprintf(parmlist,"\"%s\",%d,%d",ftype,slot,part);
132 } else {
133 sprintf(parmlist,"\"%s\",%d,%d,%d",ftype,slot,part,total);
134 }
135 at_command_send(AT_SIE_BIN_WRITE,parmlist);
136 mem_realloc(parmlist,0);
137 return AT_SIE_BIN_WRITE;
138 }
139
at_sie_binary_read(const char * ftype,unsigned int slot)140 char* at_sie_binary_read (const char* ftype, unsigned int slot) {
141 char* parmlist;
142
143 if (str_len(ftype) == 0) return NULL;
144 if (!at_sie_supported()) return NULL;
145
146 parmlist = mem_alloc(1+strlen(ftype)+2+numlen(slot)+1, 1);
147 sprintf(parmlist,"\"%s\",%d",ftype,slot);
148 at_command_send(AT_SIE_BIN_READ,parmlist);
149 mem_realloc(parmlist,0);
150 return AT_SIE_BIN_READ;
151 }
152
at_sie_phonebook_vcf_read(unsigned int slot,int type)153 char* at_sie_phonebook_vcf_read (unsigned int slot, int type) {
154 char* parmlist;
155
156 if (!at_sie_supported()) return NULL;
157
158 if (type > 3 || type < 0) {
159 type = -1;
160 parmlist = mem_alloc(numlen(slot)+1,1);
161 sprintf(parmlist,"%d",slot);
162 } else {
163 parmlist = mem_alloc(numlen(slot)+1+numlen(type)+1,1);
164 sprintf(parmlist,"%d,%d",slot,type);
165 }
166 at_command_send(AT_SIE_PB_VCF_READ,parmlist);
167 mem_realloc(parmlist,0);
168 return AT_SIE_PB_VCF_READ;
169 }
170
at_sie_phonebook_read_sorted(unsigned int slot_low,unsigned int slot_high)171 char* at_sie_phonebook_read_sorted (unsigned int slot_low,
172 unsigned int slot_high)
173 {
174 char* parmlist;
175
176 if (!at_sie_supported()) return NULL;
177
178 parmlist = mem_alloc(numlen(slot_low)+1
179 +numlen(slot_high)+1, 1);
180 sprintf(parmlist,"%d,%d",slot_low,slot_high);
181 at_command_send(AT_SIE_PB_READ_SORTED,parmlist);
182 mem_realloc(parmlist,0);
183 return AT_SIE_PB_READ_SORTED;
184 }
185
at_sie_phonebook_select(const char * mem)186 char* at_sie_phonebook_select (const char* mem) {
187 char* parmlist;
188
189 if (mem == NULL) return NULL;
190
191 if (!at_sie_supported())
192 return at_gen_phonebook_select(mem);
193
194 parmlist = mem_alloc(1+strlen(mem)+2, 1);
195 sprintf(parmlist,"\"%s\"",mem);
196 at_command_send(AT_SIE_PB_SELECT,parmlist);
197 mem_realloc(parmlist,0);
198 return AT_SIE_PB_SELECT;
199 }
200
at_sie_sms_slot_read(unsigned int slot)201 char* at_sie_sms_slot_read (unsigned int slot) {
202 char* parmlist;
203
204 if (!at_sie_supported()) return NULL;
205
206 parmlist = mem_alloc(numlen(slot)+1,1);
207 sprintf(parmlist,"%d",slot);
208 at_command_send(AT_SIE_SMS_SLOT_READ,parmlist);
209 mem_realloc(parmlist,0);
210 return AT_SIE_SMS_SLOT_READ;
211 }
212
at_sie_sms_list_read(unsigned int list_id)213 char* at_sie_sms_list_read (unsigned int list_id) {
214 char* parmlist;
215
216 if (!at_sie_supported()) return NULL;
217
218 parmlist = mem_alloc(numlen(list_id)+1,1);
219 sprintf(parmlist,"%d",list_id);
220 at_command_send(AT_SIE_SMS_LIST_READ,parmlist);
221 mem_realloc(parmlist,0);
222 return AT_SIE_SMS_LIST_READ;
223 }
224