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