Not yet working stack checking (symbol STACKCHECK)
[gnokii.git] / common / gsm-networks.c
1 /*
2
3   G N O K I I
4
5   A Linux/Unix toolset and driver for Nokia mobile phones.
6
7   Released under the terms of the GNU GPL, see file COPYING for more details.
8         
9   This file implements GSM networks searching.
10
11 */
12
13 #include "config.h"
14
15 #include <string.h>
16
17 #include "gsm-common.h"
18 #include "gsm-networks.h"
19 #include "gsm-coding.h"
20
21 static GSM_Country GSM_Countries[] =
22 {
23   { "202", "Greece" },
24   { "204", "Netherlands" },
25   { "206", "Belgium" },
26   { "208", "France" },
27   { "213", "Andorra" },
28   { "214", "Spain" },
29   { "216", "Hungary" },
30   { "218", "Bosnia Herzegovina" },
31   { "219", "Croatia" },
32   { "220", "Yugoslavia" },
33   { "222", "Italy" },
34   { "226", "Romania" },
35   { "228", "Switzerland" },
36   { "230", "Czech Republic" },
37   { "231", "Slovak Republic" },
38   { "232", "Austria" },
39   { "234", "United Kingdom" },
40   { "238", "Denmark" },
41   { "240", "Sweden" },
42   { "242", "Norway" },
43   { "244", "Finland" },
44   { "246", "Lithuania" },
45   { "247", "Latvia" },
46   { "248", "Estonia" },
47   { "250", "Russia" },
48   { "255", "Ukraine" },
49   { "259", "Moldova" },
50   { "260", "Poland" },
51   { "262", "Germany" },
52   { "266", "Gibraltar" },
53   { "268", "Portugal" },
54   { "270", "Luxembourg" },
55   { "272", "Ireland" },
56   { "274", "Iceland" },
57   { "276", "Albania" },
58   { "278", "Malta" },
59   { "280", "Cyprus" },
60   { "282", "Georgia" },
61   { "283", "Armenia" },
62   { "284", "Bulgaria" },
63   { "286", "Turkey" },
64   { "290", "Greenland" },
65   { "293", "Slovenia" },
66   { "294", "Macedonia" },
67   { "302", "Canada" },
68   { "310", "Papua New Guinea" },
69   { "310", "U.S.A." },
70   { "340", "French West Indies" },
71   { "400", "Azerbaijan" },
72   { "404", "India" },
73   { "410", "Pakistan" },
74   { "413", "Sri Lanka" },
75   { "415", "Lebanon" },
76   { "416", "Jordan" },
77   { "417", "Syria" },
78   { "418", "Iraq" },
79   { "419", "Kuwait" },
80   { "420", "Saudi Arabia" },
81   { "422", "Oman" },
82   { "424", "United Arab Emirates" },
83   { "425", "Israel" },
84   { "426", "Bahrain" },
85   { "427", "Qatar" },
86   { "432", "Iran" },
87   { "434", "Uzbekistan" },
88   { "437", "Kyrgyz Republic" },
89   { "452", "Vietnam" },
90   { "454", "Hong Kong" },
91   { "455", "Macau" },
92   { "456", "Cambodia" },
93   { "457", "Lao" },
94   { "460", "China" },
95   { "466", "Taiwan" },
96   { "470", "Bangladesh" },
97   { "502", "Malaysia" },
98   { "505", "Australia" },
99   { "510", "Indonesia" },
100   { "515", "Philippines" },
101   { "520", "Thailand" },
102   { "525", "Singapore" },
103   { "528", "Brunei Darussalam" },
104   { "530", "New Zealand" },
105   { "542", "Fiji" },
106   { "546", "New Caledonia" },
107   { "547", "French Polynesia" },
108   { "602", "Egypt" },
109   { "603", "Algeria" },
110   { "604", "Morocco" },
111   { "605", "Tunisia" },
112   { "608", "Senegal" },
113   { "611", "Guinea" },
114   { "612", "Cote d'Ivoire" },
115   { "615", "Togo" },
116   { "617", "Mauritius" },
117   { "618", "Liberia" },
118   { "620", "Ghana" },
119   { "624", "Cameroon" },
120   { "625", "Cape Verde" },
121   { "633", "Seychelles" },
122   { "634", "Mozambique" },
123   { "634", "Sudan" },
124   { "635", "Rwanda" },
125   { "636", "Ethiopia" },
126   { "640", "Tanzania" },
127   { "641", "Uganda" },
128   { "645", "Zambia" },
129   { "646", "Madagascar" },
130   { "647", "Reunion" },
131   { "648", "Zimbabwe" },
132   { "649", "Namibia" },
133   { "650", "Malawi" },
134   { "651", "Lesotho" },
135   { "652", "Botswana" },
136   { "655", "South Africa" },
137   { "730", "Chile" },
138   { "734", "Venezuela" },
139
140   { "undefined", "unknown" }
141 };
142
143 GSM_Network GSM_Networks[] =
144 {
145   { "202 01", "Cosmote" },
146   { "202 05", "PANAFON" },
147   { "202 10", "TELESTET" },
148   { "204 04", "LIBERTEL" },
149   { "204 08", "KPN Telecom" },
150   { "204 12", "Telfort" },
151   { "204 16", "BEN" },
152   { "204 20", "Dutchtone NV" },
153   { "206 01", "PROXIMUS" },
154   { "206 10", "Mobistar" },
155   { "208 01", "ITINERIS" },
156   { "208 10", "SFR" },
157   { "208 20", "Bouygues Telecom" },
158   { "213 03", "MOBILAND" },
159   { "214 01", "Airtel GSM 900-Spain" },
160   { "214 03", "Retevision Movil" },
161   { "214 07", "MOVISTAR" },
162   { "216 01", "Pannon GSM" },
163   { "216 70", "Vodafone" },
164   { "216 30", "Westel 900" },
165   { "218 90", "GSMBIH" },
166   { "219 01", "CRONET" },
167   { "219 10", "VIP" },
168   { "220 01", "MOBTEL" },
169   { "220 02", "ProMonte GSM" },
170   { "222 01", "Telecom Italia Mobile" },
171   { "222 10", "OMNITEL" },
172   { "222 88", "Wind Telecomunicazioni SpA" },
173   { "226 01", "CONNEX GSM" },
174   { "226 10", "DIALOG" },
175   { "228 01", "NATEL International" },
176   { "228 02", "diAx Mobile AG" },
177   { "230 01", "Paegas" },
178   { "230 02", "EuroTel" },
179   { "230 03", "Oskar" },
180   { "231 01", "Globtel" },
181   { "231 02", "EuroTel GSM" },
182   { "232 01", "A1" },
183   { "232 03", "max.mobil." },
184   { "232 05", "ONE" },
185   { "232 07", "tele.ring" },
186   { "234 10", "Cellnet" },
187   { "234 15", "Vodafone" },
188   { "234 30", "One 2 One" },
189   { "234 33", "ORANGE" },
190   { "234 50", "Jersey Telecoms GSM" },
191   { "234 55", "Guernsey Telecoms GSM" },
192   { "234 58", "PRONTO GSM" },
193   { "238 01", "TDK-MOBIL" },
194   { "238 02", "SONOFON" },
195   { "238 20", "TELIA DK" },
196   { "238 30", "Mobilix" },
197   { "240 01", "Telia AB" },
198   { "240 07", "COMVIQ" },
199   { "240 08", "EUROPOLITAN" },
200   { "242 01", "Telenor Mobil" },
201   { "242 02", "NetCom GSM" },
202   { "244 03", "Telia City (Finland)" },
203   { "244 05", "Radiolinja" },
204   { "244 09", "Finnet" },
205   { "244 91", "Sonera" },
206   { "246 01", "OMNITEL" },
207   { "246 02", "Bite GSM" },
208   { "247 01", "LMT LV" },
209   { "247 02", "BALTCOM GSM" },
210   { "248 01", "EMT GSM" },
211   { "248 02", "Radiolinja Eesti AS" },
212   { "248 03", "Q GSM" },
213   { "250 01", "Mobile Telesystems" },
214   { "250 02", "North-West GSM" },
215   { "250 05", "Siberian Cellular Systems 900" },
216   { "250 07", "BM Telecom" },
217   { "250 10", "Don Telecom" },
218   { "250 12", "FECS-900" },
219   { "250 13", "Kuban GSM" },
220   { "250 39", "Uraltel" },
221   { "250 44", "North Caucasian GSM" },
222   { "250 99", "BeeLine" },
223   { "255 01", "UMC" },
224   { "255 02", "WellCOM" },
225   { "255 03", "Kyivstar" },
226   { "255 05", "Golden Telecom" },
227   { "259 01", "VOXTEL" },
228   { "260 01", "PLUS GSM" },
229   { "260 02", "ERA GSM" },
230   { "260 03", "IDEA Centertel" },
231   { "262 01", "D1 TELEKOM" },
232   { "262 02", "D2 PRIVAT" },
233   { "262 03", "E-Plus" },
234   { "262 07", "Interkom" },
235   { "266 01", "Gibtel GSM" },
236   { "268 01", "TELECEL" },
237   { "268 03", "OPTIMUS" },
238   { "268 06", "TMN" },
239   { "270 01", "LUXGSM" },
240   { "270 77", "TANGO" },
241   { "272 01", "EIRCELL-GSM" },
242   { "272 02", "Digifone" },
243   { "274 01", "Landssiminn GSM 900" },
244   { "274 02", "TAL hf" },
245   { "276 01", "AMC" },
246   { "278 01", "Vodafone Malta Limited" },
247   { "280 01", "CYTAGSM" },
248   { "282 01", "Geocell Limited" },
249   { "282 02", "Magti GSM" },
250   { "283 01", "ArmGSM" },
251   { "284 01", "M-TEL GSM BG" },
252   { "286 01", "Turkcell" },
253   { "286 02", "TELSIM GSM" },
254   { "288 01", "Faroese Telecom" },
255   { "290 01", "Tele Greenland" },
256   { "293 40", "SI.MOBIL d. d." },
257   { "293 41", "MOBITEL" },
258   { "294 01", "MobiMak" },
259   { "302 37", "Microcell Connexions Inc" },
260   { "310 01", "Cellnet" },
261   { "310 02", "Sprint Spectrum" },
262   { "310 11", "Wireless 2000 Telephone Co." },
263   { "310 15", "BellSouth Mobility DCS" },
264   { "310 16", "Omnipoint" },
265   { "310 17", "Pac Bell" },
266   { "310 26", "VOICESTREAM" },
267   { "310 27", "Powertel" },
268   { "310 31", "AERIAL" },
269   { "310 77", "Iowa Wireless Services LP" },
270   { "340 01", "AMERIS" },
271   { "400 01", "AZERCELL GSM" },
272   { "400 02", "Bakcell GSM 2000" },
273
274   { "404 01", "AIRCELL"},\r
275   { "404 02", "Evergrowth"},\r
276   { "404 03", "Bharthi Telenet"},\r
277   { "404 05", "Fascel"},\r
278   { "404 07", "Tata Cell"},\r //TATA Cellular
279   { "404 08", "Koshika"},
280   { "404 09", "Reliance"},\r
281   { "404 10", "AIRTEL"},\r //AirTel
282   { "404 11", "Essar"},\r //Essar Cellphone
283   { "404 12", "Escotel"},\r
284   { "404 14", "Spice"},\r //Modicom
285   { "404 15", "AIRCELL"},\r //Essar Cellphone
286   { "404 18", "Reliance"},\r
287   { "404 19", "Escotel"},\r
288   { "404 20", "Orange"},\r //Max Touch
289   { "404 21", "BPL Mobile"},\r //BPL - Mobile
290   { "404 22", "Birla AT&T"},\r
291   { "404 24", "Birla AT&T"},\r
292   { "404 26", "Koshika"},\r
293   { "404 27", "BPL Mobile"},\r //BPL USWEST Cellular
294   { "404 30", "Usha"},\r //Command
295   { "404 31", "AIRCELL"},\r //?
296   { "404 31", "Command"},\r //?
297   { "404 32", "Koshika"},\r
298   { "404 34", "Koshika"},\r
299   { "404 36", "Reliance"},\r
300   { "404 40", "SkyCell"},\r
301   { "404 41", "RPG"}, //RPG Cellular
302   { "404 42", "AIRCELL"},\r //AIRCEL
303   { "404 43", "BPL Mobile"},\r
304   { "404 44", "Spice"},\r
305   { "404 45", "AIRTEL-blr"},\r
306   { "404 46", "BPL Moibile"},\r
307   { "404 49", "AIRTEL"},
308   { "404 50", "Reliance"},\r
309   { "404 52", "Reliance"},
310   { "404 56", "Escotel"},
311   { "404 60", "AIRCELL"},\r
312   { "404 67", "Reliance"},
313   { "404 70", "Hexacom"},\r
314   { "404 78", "RPG"},\r
315   { "404 85", "Reliance"},\r
316 \r
317   { "410 01", "Mobilink" },
318   { "413 02", "DIALOG GSM" },
319   { "415 01", "CELLIS" },
320   { "415 03", "LIBANCELL" },
321   { "416 01", "Fastlink" },
322   { "417 09", "MOBILE SYRIA" },
323   { "419 02", "MTCNet" },
324   { "420 01", "Al Jawwal" },
325   { "420 07", "E.A.E" },
326   { "422 02", "GTO" },
327   { "424 02", "UAE-ETISALAT" },
328   { "425 01", "Partner Communications Company Ltd" },
329   { "426 01", "BHR MOBILE PLUS" },
330   { "427 01", "QATARNET" },
331   { "432 11", "TCI" },
332   { "434 04", "Daewoo Unitel" },
333   { "434 05", "Coscom" },
334   { "437 01", "Bitel" },
335   { "454 00", "TCSL GSM" },
336   { "454 04", "HKGHT" },
337   { "454 06", "SMARTONE GSM" },
338   { "454 10", "New World PCS" },
339   { "454 12", "PEOPLES" },
340   { "454 16", "SUNDAY" },
341   { "455 01", "TELEMOVEL+ GSM900-Macau" },
342   { "456 01", "MobiTel" },
343   { "456 02", "SAMART-GSM" },
344   { "457 01", "Lao Shinawatra Telecom" },
345   { "460 00", "China Telecom GSM" },
346   { "460 01", "CU-GSM" },
347   { "466 01", "Far EasTone Telecoms 900" },
348   { "466 06", "TUNTEX GSM 1800" },
349   { "466 88", "KG Telecom" },
350   { "466 92", "Chunghwa GSM" },
351   { "466 93", "MobiTai" },
352   { "466 97", "TWNGSM" },
353   { "466 99", "TransAsia" },
354   { "470 01", "GrameenPhone Ltd" },
355   { "470 19", "Mobile 2000" },
356   { "502 12", "Maxis Mobile" },
357   { "502 13", "TM Touch" },
358   { "502 16", "DiGi 1800" },
359   { "502 17", "ADAM" },
360   { "502 19", "CELCOM" },
361   { "505 01", "MobileNet" },
362   { "505 02", "OPTUS" },
363   { "505 03", "VODAFONE" },
364   { "505 08", "One.Tel" },
365   { "510 01", "SATELINDO" },
366   { "510 10", "TELKOMSEL" },
367   { "510 11", "Excelcom" },
368   { "515 01", "ISLACOM" },
369   { "515 02", "Globe Telecom" },
370   { "520 01", "AIS GSM" },
371   { "520 10", "WCS" },
372   { "520 18", "Worldphone 1800" },
373   { "520 23", "HELLO" },
374   { "525 01", "SingTel Mobile" },
375   { "525 02", "ST-PCN" },
376   { "525 03", "MOBILEONE" },
377   { "528 11", "DSTCom" },
378   { "530 01", "Vodafone New Zealand Limited" },
379   { "542 01", "Vodafone" },
380   { "546 01", "Mobilis" },
381   { "547 20", "VINI" },
382   { "602 01", "MobiNil" },
383   { "602 02", "Tunicell" },
384   { "603 01", "ALGERIAN MOBILE NETWORK" },
385   { "604 01", "I A M" },
386   { "608 01", "ALIZE" },
387   { "611 02", "Lagui" },
388   { "612 03", "IVOIRIS" },
389   { "612 05", "Telecel" },
390   { "615 01", "TOGO CELL" },
391   { "617 01", "Cellplus Mobile Comms" },
392   { "618 01", "Omega" },
393   { "620 01", "SPACEFON" },
394   { "625 01", "CVMOVEL" },
395   { "633 01", "Seychelles Cellular Services" },
396   { "633 10", "AIRTEL" },
397   { "634 01", "MobiTel" },
398   { "635 10", "Rwandacell" },
399   { "636 01", "ETMTN" },
400   { "640 01", "TRITEL" },
401   { "641 10", "MTN-Uganda" },
402   { "642 02", "ANTARIS" },
403   { "643 01", "T.D.M GSM 900" },
404   { "645 01", "ZAMCELL" },
405   { "646 01", "Madacom" },
406   { "646 03", "Sacel Madagascar S.A." },
407   { "647 10", "SRR" },
408   { "648 01", "NET*ONE" },
409   { "648 03", "Telecel" },
410   { "649 01", "MTC" },
411   { "650 01", "Callpoint 900" },
412   { "651 01", "Vodacom Lesotho (Pty) Ltd" },
413   { "655 01", "Vodacom" },
414   { "655 10", "MTN" },
415   { "680 38", "NPI Wireless" },
416   { "730 01", "Entel Telefonia Movi" },
417   { "730 10", "Entel PCS" },
418   { "734 01", "Infonet" },
419
420   { "undefined", "unknown" }
421 };
422
423 char *GSM_GetNetworkName(char *NetworkCode)
424 {
425
426   int index=0;
427
428   while ( strcmp(GSM_Networks[index].Code, NetworkCode) &&
429           strcmp(GSM_Networks[index].Code, "undefined") )
430     index++;
431
432   return GSM_Networks[index].Name;
433 }
434
435 char *GSM_GetNetworkCode(char *NetworkName)
436 {
437
438   int index=0;
439
440   while ( strcmp(GSM_Networks[index].Name, NetworkName) &&
441           strcmp(GSM_Networks[index].Code, "undefined") )
442     index++;
443
444   return GSM_Networks[index].Code;
445 }
446
447 char *GSM_GetCountryName(char *CountryCode)
448 {
449
450   int index=0;
451
452   while ( strncmp(GSM_Countries[index].Code, CountryCode, 3) &&
453           strcmp(GSM_Countries[index].Code, "undefined") )
454     index++;
455
456   return GSM_Countries[index].Name;
457 }
458
459 static char *GSM_GetCountryCode(char *CountryName)
460 {
461
462   int index=0;
463
464   while ( strcmp(GSM_Countries[index].Name, CountryName) &&
465           strcmp(GSM_Countries[index].Code, "undefined") )
466     index++;
467
468   return GSM_Countries[index].Code;
469 }
470
471 void EncodeNetworkCode(unsigned char* buffer, unsigned char* output)
472 {
473     EncodeBCD (buffer, output, 6, false);
474     buffer[1]=buffer[1] | 0xf0;
475 }
476
477 void DecodeNetworkCode(unsigned char* buffer, unsigned char* output)
478 {
479     DecodeBCD (output, buffer, 3);
480     output[6]=output[5];
481     output[5]=output[4];
482     output[4]=output[3];
483     output[3]=' ';
484 }