summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/service/gsmdata.c
Unidiff
Diffstat (limited to 'gammu/emb/common/service/gsmdata.c') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmdata.c366
1 files changed, 366 insertions, 0 deletions
diff --git a/gammu/emb/common/service/gsmdata.c b/gammu/emb/common/service/gsmdata.c
new file mode 100644
index 0000000..94e9b7b
--- a/dev/null
+++ b/gammu/emb/common/service/gsmdata.c
@@ -0,0 +1,366 @@
1/* (c) 2002-2004 by Marcin Wiacek */
2
3#include <string.h>
4
5#include "gsmdata.h"
6#include "../misc/coding/coding.h"
7
8/* SNIFFS, specs somewhere in http://www.wapforum.org */
9void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, int *Length, GSM_MMSIndicator Indicator)
10{
11 unsigned char buffer[200];
12 int i;
13
14 strcpy(Buffer+(*Length),"\xE6\x06\"");
15 (*Length)=(*Length)+3;
16 strcpy(Buffer+(*Length),"application/vnd.wap.mms-message");
17 (*Length)=(*Length)+31;
18 Buffer[(*Length)++] = 0x00;
19
20 strcpy(Buffer+(*Length),"\xAF\x84\x8C\x82\x98");
21 (*Length)=(*Length)+5;
22
23 i = strlen(Indicator.Address);
24 while (Indicator.Address[i] != '/' && i!=0) i--;
25 strcpy(Buffer+(*Length),Indicator.Address+i+1);
26 (*Length)=(*Length)+strlen(Indicator.Address+i+1);
27 Buffer[(*Length)++] = 0x00;
28
29 strcpy(Buffer+(*Length),"\x8D\x90\x89");
30 (*Length)=(*Length)+3;
31
32 sprintf(buffer,"%s/TYPE=PLMN",Indicator.Sender);
33 Buffer[(*Length)++] = strlen(buffer);
34 Buffer[(*Length)++] = 0x80;
35 strcpy(Buffer+(*Length),buffer);
36 (*Length)=(*Length)+strlen(buffer);
37 Buffer[(*Length)++] = 0x00;
38
39 Buffer[(*Length)++] = 0x96;
40 strcpy(Buffer+(*Length),Indicator.Title);
41 (*Length)=(*Length)+strlen(Indicator.Title);
42 Buffer[(*Length)++] = 0x00;
43
44 strcpy(Buffer+(*Length),"\x8A\x80\x8E\x02\x47\xBB\x88\x05\x81\x03\x02\xA3");
45 (*Length)=(*Length)+12;
46 Buffer[(*Length)++] = 0x00;
47
48 Buffer[(*Length)++] = 0x83;
49 strcpy(Buffer+(*Length),Indicator.Address);
50 (*Length)=(*Length)+strlen(Indicator.Address);
51 Buffer[(*Length)++] = 0x00;
52}
53
54/* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */
55static void AddWAPSMSParameterText(unsigned char *Buffer, int *Length, unsigned char ID, char *Text, int Len)
56{
57 int i;
58
59 Buffer[(*Length)++] = 0x87; //PARM with attributes
60 Buffer[(*Length)++] = ID;
61 Buffer[(*Length)++] = 0x11; //VALUE
62 Buffer[(*Length)++] = 0x03; //Inline string
63 for (i=0;i<Len;i++) {
64 Buffer[(*Length)++] = Text[i]; //Text
65 }
66 Buffer[(*Length)++] = 0x00; //END Inline string
67 Buffer[(*Length)++] = 0x01; //END PARMeter
68}
69
70/* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */
71static void AddWAPSMSParameterInt(unsigned char *Buffer, int *Length, unsigned char ID, unsigned char Value)
72{
73 Buffer[(*Length)++] = 0x87; //PARM with attributes
74 Buffer[(*Length)++] = ID;
75 Buffer[(*Length)++] = Value;
76 Buffer[(*Length)++] = 0x01; //END PARMeter
77}
78
79/* http://forum.nokia.com : OTA MMS Settings 1.0, OTA Settings 7.0
80 * http://www.wapforum.org : Wireless Datagram Protocol
81 */
82void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, int *Length, GSM_WAPSettings *settings, bool MMS)
83{
84 int i;
85 unsigned char buffer[400];
86
87 Buffer[(*Length)++] = 0x01; //Push ID
88 Buffer[(*Length)++] = 0x06; //PDU Type (push)
89 Buffer[(*Length)++] = 0x2C; //Headers length (content type + headers)
90 strcpy(Buffer+(*Length),"\x1F\x2A");
91 (*Length)=(*Length)+2; //Value length
92 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-settings");
93 (*Length)=(*Length)+39; //MIME-Type
94 Buffer[(*Length)++] = 0x00; //end inline string
95 strcpy(Buffer+(*Length),"\x81\xEA");
96 (*Length)=(*Length)+2; //charset UTF-8 short int.
97 strcpy(Buffer+(*Length),"\x01\x01");
98 (*Length)=(*Length)+2; //version WBXML 1.1
99 Buffer[(*Length)++] = 0x6A; //charset UTF-8
100 Buffer[(*Length)++] = 0x00; //string table length
101
102 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content
103 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
104 Buffer[(*Length)++] = 0x06; //TYPE=ADDRESS
105 Buffer[(*Length)++] = 0x01; //END PARMeter
106 switch (settings->Bearer) {
107 case WAPSETTINGS_BEARER_GPRS:
108 /* Bearer */
109 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x49);
110 /* PPP_LOGINTYPE (manual login or not) */
111 if (settings->ManualLogin) {
112 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
113 } else {
114 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
115 }
116 /* PPP_AUTHTYPE*/
117 if (settings->IsNormalAuthentication) {
118 /* OTA_CSD_AUTHTYPE_PAP */
119 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
120 } else {
121 /* OTA_CSD_AUTHTYPE_CHAP */
122 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
123 }
124 /* GPRS_ACCESSPOINTNAME */
125 AddWAPSMSParameterText(Buffer, Length, 0x1C, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
126 /* PROXY */
127 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
128 /* PPP_AUTHNAME (user) */
129 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
130 /* PPP_AUTHSECRET (password) */
131 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
132 break;
133 case WAPSETTINGS_BEARER_DATA:
134 /* Bearer */
135 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x45);
136 /* CSD_DIALSTRING */
137 AddWAPSMSParameterText(Buffer, Length, 0x21, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
138 /* PROXY */
139 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
140 /* PPP_LOGINTYPE (manual login or not) */
141 if (settings->ManualLogin) {
142 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
143 } else {
144 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
145 }
146 /* PPP_AUTHTYPE*/
147 if (settings->IsNormalAuthentication) {
148 /* OTA_CSD_AUTHTYPE_PAP */
149 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
150 } else {
151 /* OTA_CSD_AUTHTYPE_CHAP */
152 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
153 }
154 /* CSD_CALLTYPE (type of call) */
155 if (settings->IsISDNCall) {
156 /* ISDN */
157 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x73);
158 } else {
159 /* analogue */
160 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x72);
161 }
162 /* CSD_CALLSPEED (speed of call) */
163 switch (settings->Speed) {
164 case WAPSETTINGS_SPEED_AUTO:
165 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6A);
166 break;
167 case WAPSETTINGS_SPEED_9600:
168 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6B);
169 break;
170 case WAPSETTINGS_SPEED_14400:
171 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6C);
172 }
173 /* PPP_AUTHNAME (user) */
174 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
175 /* PPP_AUTHSECRET (password) */
176 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
177 break;
178#ifdef DEVELOP
179 case WAPSETTINGS_BEARER_SMS:
180 /* Bearer */
181 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41);
182 /* PROXY */
183 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Server), UnicodeLength(settings->Server));
184 /* SMS_SMSC_ADDRESS */
185 // .....
186 break;
187 case WAPSETTINGS_BEARER_USSD:
188 /* FIXME */
189 /* Bearer */
190 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41);
191 /* PROXY */
192 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Service), UnicodeLength(settings->Service));
193 /* USSD_SERVICE_CODE */
194 /* FIXME */
195 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Code), UnicodeLength(settings->Code));
196#else
197 case WAPSETTINGS_BEARER_SMS:
198 case WAPSETTINGS_BEARER_USSD:
199 break;
200#endif
201 }
202 /* PORT */
203 if (settings->IsSecurity) {
204 if (settings->IsContinuous) {
205 /* Port = 9203. Continuous */
206 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x63);
207 } else {
208 /* Port = 9202. Temporary */
209 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x62);
210 }
211 } else {
212 if (settings->IsContinuous) {
213 /* Port = 9201. Continuous */
214 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x61);
215 } else {
216 /* Port = 9200. Temporary */
217 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x60);
218 }
219 }
220 Buffer[(*Length)++] = 0x01; //END PARMeter
221
222 /* URL */
223 Buffer[(*Length)++] = 0x86; //CHARACTERISTIC-LIST with attributes
224 if (MMS) {
225 Buffer[(*Length)++] = 0x7C; //TYPE = MMSURL
226 } else {
227 Buffer[(*Length)++] = 0x07; //TYPE = URL
228 }
229 Buffer[(*Length)++] = 0x11; //VALUE
230 Buffer[(*Length)++] = 0x03; //Inline string
231 sprintf(buffer,"%s",DecodeUnicodeString(settings->HomePage));
232 for (i=0;i<(int)strlen(buffer);i++) {
233 Buffer[(*Length)++] = buffer[i];//Text
234 }
235 Buffer[(*Length)++] = 0x00; //END Inline string
236 Buffer[(*Length)++] = 0x01; //END PARMeter
237
238 /* ISP_NAME (name) */
239 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
240 Buffer[(*Length)++] = 0x08; //TYPE=NAME
241 Buffer[(*Length)++] = 0x01; //END PARMeter
242 /* Settings name */
243 AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(settings->Title), UnicodeLength(settings->Title));
244 Buffer[(*Length)++] = 0x01; //END PARMeter
245 Buffer[(*Length)++] = 0x01; //END PARMeter
246}
247
248/* http://forum.nokia.com: OTA Settings 7.0 */
249void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark)
250{
251 unsigned charbuffer[100];
252 bool UnicodeCoding = false;
253
254 EncodeUTF8QuotedPrintable(buffer,bookmark->Title);
255 if (UnicodeLength(bookmark->Title)!=strlen(buffer)) UnicodeCoding = true;
256
257 Buffer[(*Length)++] = 0x01; //Push ID
258 Buffer[(*Length)++] = 0x06; //PDU Type (push)
259 Buffer[(*Length)++] = 0x2D; //Headers length (content type + headers)
260 strcpy(Buffer+(*Length),"\x1F\x2B");
261 (*Length)=(*Length)+2; //Value length
262 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-bookmarks");
263 (*Length)=(*Length)+40; //MIME-Type
264 Buffer[(*Length)++] = 0x00; //end inline string
265 strcpy(Buffer+(*Length),"\x81\xEA");
266 (*Length)=(*Length)+2; //charset UTF-8 short int.
267
268 /* Block from sniffs. UNKNOWN */
269 if (!UnicodeCoding) {
270 Buffer[(*Length)++] = 0x00;
271 Buffer[(*Length)++] = 0x01;
272 } else {
273 strcpy(Buffer+(*Length),"\x01\x01\x87\x68");
274 (*Length)=(*Length)+4;
275 }
276 Buffer[(*Length)++] = 0x00;
277
278 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content
279 /* URL */
280 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
281 Buffer[(*Length)++] = 0x7F; //TYPE = BOOKMARK
282 Buffer[(*Length)++] = 0x01; //END PARMeter
283 if (!UnicodeCoding) {
284 /* TITLE */
285 AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(bookmark->Title), UnicodeLength(bookmark->Title));
286 /* URL */
287 AddWAPSMSParameterText(Buffer, Length, 0x17, DecodeUnicodeString(bookmark->Address), UnicodeLength(bookmark->Address));
288 } else {
289 /* TITLE */
290 AddWAPSMSParameterText(Buffer, Length, 0x15, bookmark->Title, UnicodeLength(bookmark->Title)*2+1);
291 /* URL */
292 AddWAPSMSParameterText(Buffer, Length, 0x17, bookmark->Address, UnicodeLength(bookmark->Address)*2+1);
293 }
294 Buffer[(*Length)++] = 0x01; //END PARMeter
295 Buffer[(*Length)++] = 0x01; //END PARMeter
296}
297
298void GSM_EncodeMMSFile(GSM_EncodeMultiPartMMSInfo *Info, unsigned char *Buffer, int *Length)
299{
300 int i;
301
302 strcpy(Buffer+(*Length),"\x8C\x80\x98\x4F");
303 (*Length)=(*Length)+4;
304
305 /* Unique MMS ID ? */
306 strcpy(Buffer+(*Length),"123456789");
307 (*Length)=(*Length)+9;
308 Buffer[(*Length)++] = 0x00;
309
310 strcpy(Buffer+(*Length),"\x8D\x90\x89");
311 (*Length)=(*Length)+3;
312
313 strcpy(Buffer+(*Length),"\x01\x81\x86\x81\x96");
314 (*Length)=(*Length)+5;
315
316 if (UnicodeLength(Info->Subject) != 0) {
317 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Subject));
318 (*Length)=(*Length)+UnicodeLength(Info->Subject);
319 Buffer[(*Length)++] = 0x00;
320 }
321
322 for (i=0;i<Info->EntriesNum;i++) {
323 switch(Info->Entries[i].ID) {
324 case MMS_Text:
325 strcpy(Buffer+(*Length),"\x84\xA3\x01\x04\x04\x03\x83\x81\xEA");
326 (*Length)=(*Length)+9;
327
328 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Entries[i].Buffer));
329 (*Length)=(*Length)+UnicodeLength(Info->Entries[i].Buffer);
330 break;
331 default:
332 break;
333 }
334 }
335}
336
337void GSM_ClearMultiPartMMSInfo(GSM_EncodeMultiPartMMSInfo *Info)
338{
339 Info->EntriesNum= 0;
340 Info->Subject[0]= 0x00;
341 Info->Subject[1]= 0x00;
342 Info->Source[0] = 0x00;
343 Info->Source[1] = 0x00;
344 Info->Destination[0] = 0x00;
345 Info->Destination[1] = 0x00;
346}
347
348GSM_Error GSM_EncodeURLFile(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark)
349{
350 *Length+=sprintf(Buffer+(*Length), "BEGIN:VBKM%c%c",13,10);
351 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10);
352 *Length+=sprintf(Buffer+(*Length), "TITLE:%s%c%c",DecodeUnicodeString(bookmark->Title),13,10);
353 *Length+=sprintf(Buffer+(*Length), "URL:%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
354 *Length+=sprintf(Buffer+(*Length), "BEGIN:ENV%c%c",13,10);
355 *Length+=sprintf(Buffer+(*Length), "X-IRMC-URL;QUOTED-PRINTABLE:=%c%c",13,10);
356 *Length+=sprintf(Buffer+(*Length), "[InternetShortcut] =%c%c",13,10);
357 *Length+=sprintf(Buffer+(*Length), "URL=%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
358 *Length+=sprintf(Buffer+(*Length), "END:ENV%c%c",13,10);
359 *Length+=sprintf(Buffer+(*Length), "END:VBKM%c%c",13,10);
360
361 return ERR_NONE;
362}
363
364/* How should editor hadle tabs in this file? Add editor commands here.
365 * vim: noexpandtab sw=8 ts=8 sts=8:
366 */