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