aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/countries.rs481
-rw-r--r--src/lib.rs98
-rw-r--r--src/structs.rs50
3 files changed, 593 insertions, 36 deletions
diff --git a/src/countries.rs b/src/countries.rs
new file mode 100644
index 000000000..fa1e8cace
--- /dev/null
+++ b/src/countries.rs
@@ -0,0 +1,481 @@
1#![allow(unused)]
2
3pub struct Country {
4 pub code: [u8; 2],
5 pub rev: u16,
6}
7
8/// AF Afghanistan
9pub const AFGHANISTAN: Country = Country { code: *b"AF", rev: 0 };
10/// AL Albania
11pub const ALBANIA: Country = Country { code: *b"AL", rev: 0 };
12/// DZ Algeria
13pub const ALGERIA: Country = Country { code: *b"DZ", rev: 0 };
14/// AS American_Samoa
15pub const AMERICAN_SAMOA: Country = Country { code: *b"AS", rev: 0 };
16/// AO Angola
17pub const ANGOLA: Country = Country { code: *b"AO", rev: 0 };
18/// AI Anguilla
19pub const ANGUILLA: Country = Country { code: *b"AI", rev: 0 };
20/// AG Antigua_and_Barbuda
21pub const ANTIGUA_AND_BARBUDA: Country = Country { code: *b"AG", rev: 0 };
22/// AR Argentina
23pub const ARGENTINA: Country = Country { code: *b"AR", rev: 0 };
24/// AM Armenia
25pub const ARMENIA: Country = Country { code: *b"AM", rev: 0 };
26/// AW Aruba
27pub const ARUBA: Country = Country { code: *b"AW", rev: 0 };
28/// AU Australia
29pub const AUSTRALIA: Country = Country { code: *b"AU", rev: 0 };
30/// AT Austria
31pub const AUSTRIA: Country = Country { code: *b"AT", rev: 0 };
32/// AZ Azerbaijan
33pub const AZERBAIJAN: Country = Country { code: *b"AZ", rev: 0 };
34/// BS Bahamas
35pub const BAHAMAS: Country = Country { code: *b"BS", rev: 0 };
36/// BH Bahrain
37pub const BAHRAIN: Country = Country { code: *b"BH", rev: 0 };
38/// 0B Baker_Island
39pub const BAKER_ISLAND: Country = Country { code: *b"0B", rev: 0 };
40/// BD Bangladesh
41pub const BANGLADESH: Country = Country { code: *b"BD", rev: 0 };
42/// BB Barbados
43pub const BARBADOS: Country = Country { code: *b"BB", rev: 0 };
44/// BY Belarus
45pub const BELARUS: Country = Country { code: *b"BY", rev: 0 };
46/// BE Belgium
47pub const BELGIUM: Country = Country { code: *b"BE", rev: 0 };
48/// BZ Belize
49pub const BELIZE: Country = Country { code: *b"BZ", rev: 0 };
50/// BJ Benin
51pub const BENIN: Country = Country { code: *b"BJ", rev: 0 };
52/// BM Bermuda
53pub const BERMUDA: Country = Country { code: *b"BM", rev: 0 };
54/// BT Bhutan
55pub const BHUTAN: Country = Country { code: *b"BT", rev: 0 };
56/// BO Bolivia
57pub const BOLIVIA: Country = Country { code: *b"BO", rev: 0 };
58/// BA Bosnia_and_Herzegovina
59pub const BOSNIA_AND_HERZEGOVINA: Country = Country { code: *b"BA", rev: 0 };
60/// BW Botswana
61pub const BOTSWANA: Country = Country { code: *b"BW", rev: 0 };
62/// BR Brazil
63pub const BRAZIL: Country = Country { code: *b"BR", rev: 0 };
64/// IO British_Indian_Ocean_Territory
65pub const BRITISH_INDIAN_OCEAN_TERRITORY: Country = Country { code: *b"IO", rev: 0 };
66/// BN Brunei_Darussalam
67pub const BRUNEI_DARUSSALAM: Country = Country { code: *b"BN", rev: 0 };
68/// BG Bulgaria
69pub const BULGARIA: Country = Country { code: *b"BG", rev: 0 };
70/// BF Burkina_Faso
71pub const BURKINA_FASO: Country = Country { code: *b"BF", rev: 0 };
72/// BI Burundi
73pub const BURUNDI: Country = Country { code: *b"BI", rev: 0 };
74/// KH Cambodia
75pub const CAMBODIA: Country = Country { code: *b"KH", rev: 0 };
76/// CM Cameroon
77pub const CAMEROON: Country = Country { code: *b"CM", rev: 0 };
78/// CA Canada
79pub const CANADA: Country = Country { code: *b"CA", rev: 0 };
80/// CA Canada Revision 950
81pub const CANADA_REV950: Country = Country { code: *b"CA", rev: 950 };
82/// CV Cape_Verde
83pub const CAPE_VERDE: Country = Country { code: *b"CV", rev: 0 };
84/// KY Cayman_Islands
85pub const CAYMAN_ISLANDS: Country = Country { code: *b"KY", rev: 0 };
86/// CF Central_African_Republic
87pub const CENTRAL_AFRICAN_REPUBLIC: Country = Country { code: *b"CF", rev: 0 };
88/// TD Chad
89pub const CHAD: Country = Country { code: *b"TD", rev: 0 };
90/// CL Chile
91pub const CHILE: Country = Country { code: *b"CL", rev: 0 };
92/// CN China
93pub const CHINA: Country = Country { code: *b"CN", rev: 0 };
94/// CX Christmas_Island
95pub const CHRISTMAS_ISLAND: Country = Country { code: *b"CX", rev: 0 };
96/// CO Colombia
97pub const COLOMBIA: Country = Country { code: *b"CO", rev: 0 };
98/// KM Comoros
99pub const COMOROS: Country = Country { code: *b"KM", rev: 0 };
100/// CG Congo
101pub const CONGO: Country = Country { code: *b"CG", rev: 0 };
102/// CD Congo,_The_Democratic_Republic_Of_The
103pub const CONGO_THE_DEMOCRATIC_REPUBLIC_OF_THE: Country = Country { code: *b"CD", rev: 0 };
104/// CR Costa_Rica
105pub const COSTA_RICA: Country = Country { code: *b"CR", rev: 0 };
106/// CI Cote_D'ivoire
107pub const COTE_DIVOIRE: Country = Country { code: *b"CI", rev: 0 };
108/// HR Croatia
109pub const CROATIA: Country = Country { code: *b"HR", rev: 0 };
110/// CU Cuba
111pub const CUBA: Country = Country { code: *b"CU", rev: 0 };
112/// CY Cyprus
113pub const CYPRUS: Country = Country { code: *b"CY", rev: 0 };
114/// CZ Czech_Republic
115pub const CZECH_REPUBLIC: Country = Country { code: *b"CZ", rev: 0 };
116/// DK Denmark
117pub const DENMARK: Country = Country { code: *b"DK", rev: 0 };
118/// DJ Djibouti
119pub const DJIBOUTI: Country = Country { code: *b"DJ", rev: 0 };
120/// DM Dominica
121pub const DOMINICA: Country = Country { code: *b"DM", rev: 0 };
122/// DO Dominican_Republic
123pub const DOMINICAN_REPUBLIC: Country = Country { code: *b"DO", rev: 0 };
124/// AU G'Day mate!
125pub const DOWN_UNDER: Country = Country { code: *b"AU", rev: 0 };
126/// EC Ecuador
127pub const ECUADOR: Country = Country { code: *b"EC", rev: 0 };
128/// EG Egypt
129pub const EGYPT: Country = Country { code: *b"EG", rev: 0 };
130/// SV El_Salvador
131pub const EL_SALVADOR: Country = Country { code: *b"SV", rev: 0 };
132/// GQ Equatorial_Guinea
133pub const EQUATORIAL_GUINEA: Country = Country { code: *b"GQ", rev: 0 };
134/// ER Eritrea
135pub const ERITREA: Country = Country { code: *b"ER", rev: 0 };
136/// EE Estonia
137pub const ESTONIA: Country = Country { code: *b"EE", rev: 0 };
138/// ET Ethiopia
139pub const ETHIOPIA: Country = Country { code: *b"ET", rev: 0 };
140/// FK Falkland_Islands_(Malvinas)
141pub const FALKLAND_ISLANDS_MALVINAS: Country = Country { code: *b"FK", rev: 0 };
142/// FO Faroe_Islands
143pub const FAROE_ISLANDS: Country = Country { code: *b"FO", rev: 0 };
144/// FJ Fiji
145pub const FIJI: Country = Country { code: *b"FJ", rev: 0 };
146/// FI Finland
147pub const FINLAND: Country = Country { code: *b"FI", rev: 0 };
148/// FR France
149pub const FRANCE: Country = Country { code: *b"FR", rev: 0 };
150/// GF French_Guina
151pub const FRENCH_GUINA: Country = Country { code: *b"GF", rev: 0 };
152/// PF French_Polynesia
153pub const FRENCH_POLYNESIA: Country = Country { code: *b"PF", rev: 0 };
154/// TF French_Southern_Territories
155pub const FRENCH_SOUTHERN_TERRITORIES: Country = Country { code: *b"TF", rev: 0 };
156/// GA Gabon
157pub const GABON: Country = Country { code: *b"GA", rev: 0 };
158/// GM Gambia
159pub const GAMBIA: Country = Country { code: *b"GM", rev: 0 };
160/// GE Georgia
161pub const GEORGIA: Country = Country { code: *b"GE", rev: 0 };
162/// DE Germany
163pub const GERMANY: Country = Country { code: *b"DE", rev: 0 };
164/// E0 European_Wide Revision 895
165pub const EUROPEAN_WIDE_REV895: Country = Country { code: *b"E0", rev: 895 };
166/// GH Ghana
167pub const GHANA: Country = Country { code: *b"GH", rev: 0 };
168/// GI Gibraltar
169pub const GIBRALTAR: Country = Country { code: *b"GI", rev: 0 };
170/// GR Greece
171pub const GREECE: Country = Country { code: *b"GR", rev: 0 };
172/// GD Grenada
173pub const GRENADA: Country = Country { code: *b"GD", rev: 0 };
174/// GP Guadeloupe
175pub const GUADELOUPE: Country = Country { code: *b"GP", rev: 0 };
176/// GU Guam
177pub const GUAM: Country = Country { code: *b"GU", rev: 0 };
178/// GT Guatemala
179pub const GUATEMALA: Country = Country { code: *b"GT", rev: 0 };
180/// GG Guernsey
181pub const GUERNSEY: Country = Country { code: *b"GG", rev: 0 };
182/// GN Guinea
183pub const GUINEA: Country = Country { code: *b"GN", rev: 0 };
184/// GW Guinea-bissau
185pub const GUINEA_BISSAU: Country = Country { code: *b"GW", rev: 0 };
186/// GY Guyana
187pub const GUYANA: Country = Country { code: *b"GY", rev: 0 };
188/// HT Haiti
189pub const HAITI: Country = Country { code: *b"HT", rev: 0 };
190/// VA Holy_See_(Vatican_City_State)
191pub const HOLY_SEE_VATICAN_CITY_STATE: Country = Country { code: *b"VA", rev: 0 };
192/// HN Honduras
193pub const HONDURAS: Country = Country { code: *b"HN", rev: 0 };
194/// HK Hong_Kong
195pub const HONG_KONG: Country = Country { code: *b"HK", rev: 0 };
196/// HU Hungary
197pub const HUNGARY: Country = Country { code: *b"HU", rev: 0 };
198/// IS Iceland
199pub const ICELAND: Country = Country { code: *b"IS", rev: 0 };
200/// IN India
201pub const INDIA: Country = Country { code: *b"IN", rev: 0 };
202/// ID Indonesia
203pub const INDONESIA: Country = Country { code: *b"ID", rev: 0 };
204/// IR Iran,_Islamic_Republic_Of
205pub const IRAN_ISLAMIC_REPUBLIC_OF: Country = Country { code: *b"IR", rev: 0 };
206/// IQ Iraq
207pub const IRAQ: Country = Country { code: *b"IQ", rev: 0 };
208/// IE Ireland
209pub const IRELAND: Country = Country { code: *b"IE", rev: 0 };
210/// IL Israel
211pub const ISRAEL: Country = Country { code: *b"IL", rev: 0 };
212/// IT Italy
213pub const ITALY: Country = Country { code: *b"IT", rev: 0 };
214/// JM Jamaica
215pub const JAMAICA: Country = Country { code: *b"JM", rev: 0 };
216/// JP Japan
217pub const JAPAN: Country = Country { code: *b"JP", rev: 0 };
218/// JE Jersey
219pub const JERSEY: Country = Country { code: *b"JE", rev: 0 };
220/// JO Jordan
221pub const JORDAN: Country = Country { code: *b"JO", rev: 0 };
222/// KZ Kazakhstan
223pub const KAZAKHSTAN: Country = Country { code: *b"KZ", rev: 0 };
224/// KE Kenya
225pub const KENYA: Country = Country { code: *b"KE", rev: 0 };
226/// KI Kiribati
227pub const KIRIBATI: Country = Country { code: *b"KI", rev: 0 };
228/// KR Korea,_Republic_Of
229pub const KOREA_REPUBLIC_OF: Country = Country { code: *b"KR", rev: 1 };
230/// 0A Kosovo
231pub const KOSOVO: Country = Country { code: *b"0A", rev: 0 };
232/// KW Kuwait
233pub const KUWAIT: Country = Country { code: *b"KW", rev: 0 };
234/// KG Kyrgyzstan
235pub const KYRGYZSTAN: Country = Country { code: *b"KG", rev: 0 };
236/// LA Lao_People's_Democratic_Repubic
237pub const LAO_PEOPLES_DEMOCRATIC_REPUBIC: Country = Country { code: *b"LA", rev: 0 };
238/// LV Latvia
239pub const LATVIA: Country = Country { code: *b"LV", rev: 0 };
240/// LB Lebanon
241pub const LEBANON: Country = Country { code: *b"LB", rev: 0 };
242/// LS Lesotho
243pub const LESOTHO: Country = Country { code: *b"LS", rev: 0 };
244/// LR Liberia
245pub const LIBERIA: Country = Country { code: *b"LR", rev: 0 };
246/// LY Libyan_Arab_Jamahiriya
247pub const LIBYAN_ARAB_JAMAHIRIYA: Country = Country { code: *b"LY", rev: 0 };
248/// LI Liechtenstein
249pub const LIECHTENSTEIN: Country = Country { code: *b"LI", rev: 0 };
250/// LT Lithuania
251pub const LITHUANIA: Country = Country { code: *b"LT", rev: 0 };
252/// LU Luxembourg
253pub const LUXEMBOURG: Country = Country { code: *b"LU", rev: 0 };
254/// MO Macao
255pub const MACAO: Country = Country { code: *b"MO", rev: 0 };
256/// MK Macedonia,_Former_Yugoslav_Republic_Of
257pub const MACEDONIA_FORMER_YUGOSLAV_REPUBLIC_OF: Country = Country { code: *b"MK", rev: 0 };
258/// MG Madagascar
259pub const MADAGASCAR: Country = Country { code: *b"MG", rev: 0 };
260/// MW Malawi
261pub const MALAWI: Country = Country { code: *b"MW", rev: 0 };
262/// MY Malaysia
263pub const MALAYSIA: Country = Country { code: *b"MY", rev: 0 };
264/// MV Maldives
265pub const MALDIVES: Country = Country { code: *b"MV", rev: 0 };
266/// ML Mali
267pub const MALI: Country = Country { code: *b"ML", rev: 0 };
268/// MT Malta
269pub const MALTA: Country = Country { code: *b"MT", rev: 0 };
270/// IM Man,_Isle_Of
271pub const MAN_ISLE_OF: Country = Country { code: *b"IM", rev: 0 };
272/// MQ Martinique
273pub const MARTINIQUE: Country = Country { code: *b"MQ", rev: 0 };
274/// MR Mauritania
275pub const MAURITANIA: Country = Country { code: *b"MR", rev: 0 };
276/// MU Mauritius
277pub const MAURITIUS: Country = Country { code: *b"MU", rev: 0 };
278/// YT Mayotte
279pub const MAYOTTE: Country = Country { code: *b"YT", rev: 0 };
280/// MX Mexico
281pub const MEXICO: Country = Country { code: *b"MX", rev: 0 };
282/// FM Micronesia,_Federated_States_Of
283pub const MICRONESIA_FEDERATED_STATES_OF: Country = Country { code: *b"FM", rev: 0 };
284/// MD Moldova,_Republic_Of
285pub const MOLDOVA_REPUBLIC_OF: Country = Country { code: *b"MD", rev: 0 };
286/// MC Monaco
287pub const MONACO: Country = Country { code: *b"MC", rev: 0 };
288/// MN Mongolia
289pub const MONGOLIA: Country = Country { code: *b"MN", rev: 0 };
290/// ME Montenegro
291pub const MONTENEGRO: Country = Country { code: *b"ME", rev: 0 };
292/// MS Montserrat
293pub const MONTSERRAT: Country = Country { code: *b"MS", rev: 0 };
294/// MA Morocco
295pub const MOROCCO: Country = Country { code: *b"MA", rev: 0 };
296/// MZ Mozambique
297pub const MOZAMBIQUE: Country = Country { code: *b"MZ", rev: 0 };
298/// MM Myanmar
299pub const MYANMAR: Country = Country { code: *b"MM", rev: 0 };
300/// NA Namibia
301pub const NAMIBIA: Country = Country { code: *b"NA", rev: 0 };
302/// NR Nauru
303pub const NAURU: Country = Country { code: *b"NR", rev: 0 };
304/// NP Nepal
305pub const NEPAL: Country = Country { code: *b"NP", rev: 0 };
306/// NL Netherlands
307pub const NETHERLANDS: Country = Country { code: *b"NL", rev: 0 };
308/// AN Netherlands_Antilles
309pub const NETHERLANDS_ANTILLES: Country = Country { code: *b"AN", rev: 0 };
310/// NC New_Caledonia
311pub const NEW_CALEDONIA: Country = Country { code: *b"NC", rev: 0 };
312/// NZ New_Zealand
313pub const NEW_ZEALAND: Country = Country { code: *b"NZ", rev: 0 };
314/// NI Nicaragua
315pub const NICARAGUA: Country = Country { code: *b"NI", rev: 0 };
316/// NE Niger
317pub const NIGER: Country = Country { code: *b"NE", rev: 0 };
318/// NG Nigeria
319pub const NIGERIA: Country = Country { code: *b"NG", rev: 0 };
320/// NF Norfolk_Island
321pub const NORFOLK_ISLAND: Country = Country { code: *b"NF", rev: 0 };
322/// MP Northern_Mariana_Islands
323pub const NORTHERN_MARIANA_ISLANDS: Country = Country { code: *b"MP", rev: 0 };
324/// NO Norway
325pub const NORWAY: Country = Country { code: *b"NO", rev: 0 };
326/// OM Oman
327pub const OMAN: Country = Country { code: *b"OM", rev: 0 };
328/// PK Pakistan
329pub const PAKISTAN: Country = Country { code: *b"PK", rev: 0 };
330/// PW Palau
331pub const PALAU: Country = Country { code: *b"PW", rev: 0 };
332/// PA Panama
333pub const PANAMA: Country = Country { code: *b"PA", rev: 0 };
334/// PG Papua_New_Guinea
335pub const PAPUA_NEW_GUINEA: Country = Country { code: *b"PG", rev: 0 };
336/// PY Paraguay
337pub const PARAGUAY: Country = Country { code: *b"PY", rev: 0 };
338/// PE Peru
339pub const PERU: Country = Country { code: *b"PE", rev: 0 };
340/// PH Philippines
341pub const PHILIPPINES: Country = Country { code: *b"PH", rev: 0 };
342/// PL Poland
343pub const POLAND: Country = Country { code: *b"PL", rev: 0 };
344/// PT Portugal
345pub const PORTUGAL: Country = Country { code: *b"PT", rev: 0 };
346/// PR Pueto_Rico
347pub const PUETO_RICO: Country = Country { code: *b"PR", rev: 0 };
348/// QA Qatar
349pub const QATAR: Country = Country { code: *b"QA", rev: 0 };
350/// RE Reunion
351pub const REUNION: Country = Country { code: *b"RE", rev: 0 };
352/// RO Romania
353pub const ROMANIA: Country = Country { code: *b"RO", rev: 0 };
354/// RU Russian_Federation
355pub const RUSSIAN_FEDERATION: Country = Country { code: *b"RU", rev: 0 };
356/// RW Rwanda
357pub const RWANDA: Country = Country { code: *b"RW", rev: 0 };
358/// KN Saint_Kitts_and_Nevis
359pub const SAINT_KITTS_AND_NEVIS: Country = Country { code: *b"KN", rev: 0 };
360/// LC Saint_Lucia
361pub const SAINT_LUCIA: Country = Country { code: *b"LC", rev: 0 };
362/// PM Saint_Pierre_and_Miquelon
363pub const SAINT_PIERRE_AND_MIQUELON: Country = Country { code: *b"PM", rev: 0 };
364/// VC Saint_Vincent_and_The_Grenadines
365pub const SAINT_VINCENT_AND_THE_GRENADINES: Country = Country { code: *b"VC", rev: 0 };
366/// WS Samoa
367pub const SAMOA: Country = Country { code: *b"WS", rev: 0 };
368/// MF Sanit_Martin_/_Sint_Marteen
369pub const SANIT_MARTIN_SINT_MARTEEN: Country = Country { code: *b"MF", rev: 0 };
370/// ST Sao_Tome_and_Principe
371pub const SAO_TOME_AND_PRINCIPE: Country = Country { code: *b"ST", rev: 0 };
372/// SA Saudi_Arabia
373pub const SAUDI_ARABIA: Country = Country { code: *b"SA", rev: 0 };
374/// SN Senegal
375pub const SENEGAL: Country = Country { code: *b"SN", rev: 0 };
376/// RS Serbia
377pub const SERBIA: Country = Country { code: *b"RS", rev: 0 };
378/// SC Seychelles
379pub const SEYCHELLES: Country = Country { code: *b"SC", rev: 0 };
380/// SL Sierra_Leone
381pub const SIERRA_LEONE: Country = Country { code: *b"SL", rev: 0 };
382/// SG Singapore
383pub const SINGAPORE: Country = Country { code: *b"SG", rev: 0 };
384/// SK Slovakia
385pub const SLOVAKIA: Country = Country { code: *b"SK", rev: 0 };
386/// SI Slovenia
387pub const SLOVENIA: Country = Country { code: *b"SI", rev: 0 };
388/// SB Solomon_Islands
389pub const SOLOMON_ISLANDS: Country = Country { code: *b"SB", rev: 0 };
390/// SO Somalia
391pub const SOMALIA: Country = Country { code: *b"SO", rev: 0 };
392/// ZA South_Africa
393pub const SOUTH_AFRICA: Country = Country { code: *b"ZA", rev: 0 };
394/// ES Spain
395pub const SPAIN: Country = Country { code: *b"ES", rev: 0 };
396/// LK Sri_Lanka
397pub const SRI_LANKA: Country = Country { code: *b"LK", rev: 0 };
398/// SR Suriname
399pub const SURINAME: Country = Country { code: *b"SR", rev: 0 };
400/// SZ Swaziland
401pub const SWAZILAND: Country = Country { code: *b"SZ", rev: 0 };
402/// SE Sweden
403pub const SWEDEN: Country = Country { code: *b"SE", rev: 0 };
404/// CH Switzerland
405pub const SWITZERLAND: Country = Country { code: *b"CH", rev: 0 };
406/// SY Syrian_Arab_Republic
407pub const SYRIAN_ARAB_REPUBLIC: Country = Country { code: *b"SY", rev: 0 };
408/// TW Taiwan,_Province_Of_China
409pub const TAIWAN_PROVINCE_OF_CHINA: Country = Country { code: *b"TW", rev: 0 };
410/// TJ Tajikistan
411pub const TAJIKISTAN: Country = Country { code: *b"TJ", rev: 0 };
412/// TZ Tanzania,_United_Republic_Of
413pub const TANZANIA_UNITED_REPUBLIC_OF: Country = Country { code: *b"TZ", rev: 0 };
414/// TH Thailand
415pub const THAILAND: Country = Country { code: *b"TH", rev: 0 };
416/// TG Togo
417pub const TOGO: Country = Country { code: *b"TG", rev: 0 };
418/// TO Tonga
419pub const TONGA: Country = Country { code: *b"TO", rev: 0 };
420/// TT Trinidad_and_Tobago
421pub const TRINIDAD_AND_TOBAGO: Country = Country { code: *b"TT", rev: 0 };
422/// TN Tunisia
423pub const TUNISIA: Country = Country { code: *b"TN", rev: 0 };
424/// TR Turkey
425pub const TURKEY: Country = Country { code: *b"TR", rev: 0 };
426/// TM Turkmenistan
427pub const TURKMENISTAN: Country = Country { code: *b"TM", rev: 0 };
428/// TC Turks_and_Caicos_Islands
429pub const TURKS_AND_CAICOS_ISLANDS: Country = Country { code: *b"TC", rev: 0 };
430/// TV Tuvalu
431pub const TUVALU: Country = Country { code: *b"TV", rev: 0 };
432/// UG Uganda
433pub const UGANDA: Country = Country { code: *b"UG", rev: 0 };
434/// UA Ukraine
435pub const UKRAINE: Country = Country { code: *b"UA", rev: 0 };
436/// AE United_Arab_Emirates
437pub const UNITED_ARAB_EMIRATES: Country = Country { code: *b"AE", rev: 0 };
438/// GB United_Kingdom
439pub const UNITED_KINGDOM: Country = Country { code: *b"GB", rev: 0 };
440/// US United_States
441pub const UNITED_STATES: Country = Country { code: *b"US", rev: 0 };
442/// US United_States Revision 4
443pub const UNITED_STATES_REV4: Country = Country { code: *b"US", rev: 4 };
444/// Q1 United_States Revision 931
445pub const UNITED_STATES_REV931: Country = Country { code: *b"Q1", rev: 931 };
446/// Q2 United_States_(No_DFS)
447pub const UNITED_STATES_NO_DFS: Country = Country { code: *b"Q2", rev: 0 };
448/// UM United_States_Minor_Outlying_Islands
449pub const UNITED_STATES_MINOR_OUTLYING_ISLANDS: Country = Country { code: *b"UM", rev: 0 };
450/// UY Uruguay
451pub const URUGUAY: Country = Country { code: *b"UY", rev: 0 };
452/// UZ Uzbekistan
453pub const UZBEKISTAN: Country = Country { code: *b"UZ", rev: 0 };
454/// VU Vanuatu
455pub const VANUATU: Country = Country { code: *b"VU", rev: 0 };
456/// VE Venezuela
457pub const VENEZUELA: Country = Country { code: *b"VE", rev: 0 };
458/// VN Viet_Nam
459pub const VIET_NAM: Country = Country { code: *b"VN", rev: 0 };
460/// VG Virgin_Islands,_British
461pub const VIRGIN_ISLANDS_BRITISH: Country = Country { code: *b"VG", rev: 0 };
462/// VI Virgin_Islands,_U.S.
463pub const VIRGIN_ISLANDS_US: Country = Country { code: *b"VI", rev: 0 };
464/// WF Wallis_and_Futuna
465pub const WALLIS_AND_FUTUNA: Country = Country { code: *b"WF", rev: 0 };
466/// 0C West_Bank
467pub const WEST_BANK: Country = Country { code: *b"0C", rev: 0 };
468/// EH Western_Sahara
469pub const WESTERN_SAHARA: Country = Country { code: *b"EH", rev: 0 };
470/// Worldwide Locale Revision 983
471pub const WORLD_WIDE_XV_REV983: Country = Country { code: *b"XV", rev: 983 };
472/// Worldwide Locale (passive Ch12-14)
473pub const WORLD_WIDE_XX: Country = Country { code: *b"XX", rev: 0 };
474/// Worldwide Locale (passive Ch12-14) Revision 17
475pub const WORLD_WIDE_XX_REV17: Country = Country { code: *b"XX", rev: 17 };
476/// YE Yemen
477pub const YEMEN: Country = Country { code: *b"YE", rev: 0 };
478/// ZM Zambia
479pub const ZAMBIA: Country = Country { code: *b"ZM", rev: 0 };
480/// ZW Zimbabwe
481pub const ZIMBABWE: Country = Country { code: *b"ZW", rev: 0 };
diff --git a/src/lib.rs b/src/lib.rs
index 3609ecaeb..698c52f49 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,12 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait, concat_bytes, const_slice_from_raw_parts)] 3#![feature(type_alias_impl_trait, concat_bytes, const_slice_from_raw_parts)]
4#![deny(unused_must_use)]
5
4// This mod MUST go first, so that the others see its macros. 6// This mod MUST go first, so that the others see its macros.
5pub(crate) mod fmt; 7pub(crate) mod fmt;
6 8
9mod countries;
7mod structs; 10mod structs;
8 11
9use core::cell::Cell; 12use core::cell::Cell;
@@ -206,14 +209,67 @@ pub struct Control<'a> {
206 209
207impl<'a> Control<'a> { 210impl<'a> Control<'a> {
208 pub async fn init(&mut self) { 211 pub async fn init(&mut self) {
212 const CHUNK_SIZE: usize = 1024;
213
209 let clm = unsafe { slice::from_raw_parts(0x10140000 as *const u8, 4752) }; 214 let clm = unsafe { slice::from_raw_parts(0x10140000 as *const u8, 4752) };
210 215
211 let mut buf = [0; 8 + 12 + 1024]; 216 info!("Downloading CLM...");
212 buf[0..8].copy_from_slice(b"clmload\x00"); 217
213 buf[8..20].copy_from_slice(b"\x02\x10\x02\x00\x00\x04\x00\x00\x00\x00\x00\x00"); 218 let mut offs = 0;
214 buf[20..].copy_from_slice(&clm[..1024]); 219 for chunk in clm.chunks(CHUNK_SIZE) {
215 self.ioctl(2, 263, 0, &buf).await; 220 let mut flag = DOWNLOAD_FLAG_HANDLER_VER;
216 info!("IOCTL done"); 221 if offs == 0 {
222 flag |= DOWNLOAD_FLAG_BEGIN;
223 }
224 offs += chunk.len();
225 if offs == clm.len() {
226 flag |= DOWNLOAD_FLAG_END;
227 }
228
229 let header = DownloadHeader {
230 flag,
231 dload_type: DOWNLOAD_TYPE_CLM,
232 len: chunk.len() as _,
233 crc: 0,
234 };
235 let mut buf = [0; 8 + 12 + CHUNK_SIZE];
236 buf[0..8].copy_from_slice(b"clmload\x00");
237 buf[8..20].copy_from_slice(&header.to_bytes());
238 buf[20..][..chunk.len()].copy_from_slice(&chunk);
239 self.ioctl(2, 263, 0, &buf[..8 + 12 + chunk.len()]).await;
240 }
241
242 info!("Configuring misc stuff...");
243
244 self.set_iovar_u32("bus:txglom", 0).await;
245 self.set_iovar_u32("apsta", 1).await;
246 self.set_iovar("cur_etheraddr", &[02, 03, 04, 05, 06, 07]).await;
247
248 let country = countries::WORLD_WIDE_XX;
249 let country_info = CountryInfo {
250 country_abbrev: [country.code[0], country.code[1], 0, 0],
251 country_code: [country.code[0], country.code[1], 0, 0],
252 rev: if country.rev == 0 { -1 } else { country.rev as _ },
253 };
254 self.set_iovar("country", &country_info.to_bytes()).await;
255
256 info!("INIT DONE");
257 }
258
259 async fn set_iovar_u32(&mut self, name: &str, val: u32) {
260 self.set_iovar(name, &val.to_le_bytes()).await
261 }
262
263 async fn set_iovar(&mut self, name: &str, val: &[u8]) {
264 info!("set {} = {:02x}", name, val);
265
266 let mut buf = [0; 64];
267 buf[..name.len()].copy_from_slice(name.as_bytes());
268 buf[name.len()] = 0;
269 buf[name.len() + 1..][..val.len()].copy_from_slice(val);
270
271 let total_len = name.len() + 1 + val.len();
272 self.ioctl(2, 263, 0, &buf[..total_len]).await;
217 } 273 }
218 274
219 async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &[u8]) { 275 async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &[u8]) {
@@ -255,6 +311,7 @@ pub struct Runner<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> {
255 /// - strap to set to gSPI mode on boot. 311 /// - strap to set to gSPI mode on boot.
256 dio: Flex<'a, DIO>, 312 dio: Flex<'a, DIO>,
257 313
314 ioctl_seq: u8,
258 backplane_window: u32, 315 backplane_window: u32,
259} 316}
260 317
@@ -271,6 +328,8 @@ pub async fn new<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin>(
271 cs, 328 cs,
272 clk, 329 clk,
273 dio, 330 dio,
331
332 ioctl_seq: 0,
274 backplane_window: 0xAAAA_AAAA, 333 backplane_window: 0xAAAA_AAAA,
275 }; 334 };
276 335
@@ -397,7 +456,6 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
397 } 456 }
398 457
399 pub async fn run(mut self) -> ! { 458 pub async fn run(mut self) -> ! {
400 let mut old_irq = 0;
401 let mut buf = [0; 2048]; 459 let mut buf = [0; 2048];
402 loop { 460 loop {
403 // Send stuff 461 // Send stuff
@@ -408,10 +466,6 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
408 466
409 // Receive stuff 467 // Receive stuff
410 let irq = self.read16(FUNC_BUS, REG_BUS_INTERRUPT); 468 let irq = self.read16(FUNC_BUS, REG_BUS_INTERRUPT);
411 if irq != old_irq {
412 info!("irq: {:04x}", irq);
413 }
414 old_irq = irq;
415 469
416 if irq & IRQ_F2_PACKET_AVAILABLE != 0 { 470 if irq & IRQ_F2_PACKET_AVAILABLE != 0 {
417 let mut status = 0xFFFF_FFFF; 471 let mut status = 0xFFFF_FFFF;
@@ -421,7 +475,6 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
421 475
422 if status & STATUS_F2_PKT_AVAILABLE != 0 { 476 if status & STATUS_F2_PKT_AVAILABLE != 0 {
423 let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; 477 let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT;
424 info!("got len {}", len);
425 478
426 let cmd = cmd_word(false, true, FUNC_WLAN, 0, len); 479 let cmd = cmd_word(false, true, FUNC_WLAN, 0, len);
427 480
@@ -435,7 +488,7 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
435 } 488 }
436 self.cs.set_high(); 489 self.cs.set_high();
437 490
438 info!("rxd packet {:02x}", &buf[..len as usize]); 491 info!("rx {:02x}", &buf[..(len as usize).min(48)]);
439 492
440 self.rx(&buf[..len as usize]); 493 self.rx(&buf[..len as usize]);
441 } 494 }
@@ -466,15 +519,17 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
466 519
467 let channel = sdpcm_header.channel_and_flags & 0x0f; 520 let channel = sdpcm_header.channel_and_flags & 0x0f;
468 521
522 let payload = &packet[sdpcm_header.header_length as _..];
523
469 match channel { 524 match channel {
470 0 => { 525 0 => {
471 if packet.len() < SdpcmHeader::SIZE + CdcHeader::SIZE { 526 if payload.len() < CdcHeader::SIZE {
472 warn!("control packet too short, len={}", packet.len()); 527 warn!("payload too short, len={}", payload.len());
473 return; 528 return;
474 } 529 }
475 530
476 let cdc_header = 531 let cdc_header =
477 CdcHeader::from_bytes(packet[SdpcmHeader::SIZE..][..CdcHeader::SIZE].try_into().unwrap()); 532 CdcHeader::from_bytes(payload[..CdcHeader::SIZE].try_into().unwrap());
478 533
479 if cdc_header.id == self.state.ioctl_id.get() { 534 if cdc_header.id == self.state.ioctl_id.get() {
480 assert_eq!(cdc_header.status, 0); // todo propagate error 535 assert_eq!(cdc_header.status, 0); // todo propagate error
@@ -490,10 +545,13 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
490 545
491 let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len(); 546 let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len();
492 547
548 let seq = self.ioctl_seq;
549 self.ioctl_seq = self.ioctl_seq.wrapping_add(1);
550
493 let sdpcm_header = SdpcmHeader { 551 let sdpcm_header = SdpcmHeader {
494 len: total_len as u16, 552 len: total_len as u16, // TODO does this len need to be rounded up to u32?
495 len_inv: !total_len as u16, 553 len_inv: !total_len as u16,
496 sequence: 0x02, // todo 554 sequence: seq,
497 channel_and_flags: 0, // control channel 555 channel_and_flags: 0, // control channel
498 next_length: 0, 556 next_length: 0,
499 header_length: SdpcmHeader::SIZE as _, 557 header_length: SdpcmHeader::SIZE as _,
@@ -515,7 +573,9 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
515 buf[SdpcmHeader::SIZE..][..CdcHeader::SIZE].copy_from_slice(&cdc_header.to_bytes()); 573 buf[SdpcmHeader::SIZE..][..CdcHeader::SIZE].copy_from_slice(&cdc_header.to_bytes());
516 buf[SdpcmHeader::SIZE + CdcHeader::SIZE..][..data.len()].copy_from_slice(data); 574 buf[SdpcmHeader::SIZE + CdcHeader::SIZE..][..data.len()].copy_from_slice(data);
517 575
518 info!("txing {:02x}", &buf[..total_len]); 576 let total_len = (total_len + 3) & !3; // round up to 4byte
577
578 info!("tx {:02x}", &buf[..total_len.min(48)]);
519 579
520 let cmd = cmd_word(true, true, FUNC_WLAN, 0, total_len as _); 580 let cmd = cmd_word(true, true, FUNC_WLAN, 0, total_len as _);
521 self.cs.set_low(); 581 self.cs.set_low();
diff --git a/src/structs.rs b/src/structs.rs
index fe5e89a37..bce9ab9ff 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -1,3 +1,19 @@
1macro_rules! impl_bytes {
2 ($t:ident) => {
3 impl $t {
4 pub const SIZE: usize = core::mem::size_of::<Self>();
5
6 pub fn to_bytes(&self) -> [u8; Self::SIZE] {
7 unsafe { core::mem::transmute(*self) }
8 }
9
10 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self {
11 unsafe { core::mem::transmute(*bytes) }
12 }
13 }
14 };
15}
16
1#[derive(Clone, Copy)] 17#[derive(Clone, Copy)]
2#[repr(C)] 18#[repr(C)]
3pub struct SdpcmHeader { 19pub struct SdpcmHeader {
@@ -18,6 +34,7 @@ pub struct SdpcmHeader {
18 /// Reserved 34 /// Reserved
19 pub reserved: [u8; 2], 35 pub reserved: [u8; 2],
20} 36}
37impl_bytes!(SdpcmHeader);
21 38
22#[derive(Clone, Copy)] 39#[derive(Clone, Copy)]
23#[repr(C)] 40#[repr(C)]
@@ -29,6 +46,7 @@ pub struct CdcHeader {
29 pub id: u16, 46 pub id: u16,
30 pub status: u32, 47 pub status: u32,
31} 48}
49impl_bytes!(CdcHeader);
32 50
33#[derive(Clone, Copy)] 51#[derive(Clone, Copy)]
34#[repr(C)] 52#[repr(C)]
@@ -40,32 +58,30 @@ pub struct BdcHeader {
40 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers. 58 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers.
41 pub data_offset: u8, 59 pub data_offset: u8,
42} 60}
61impl_bytes!(BdcHeader);
43 62
44#[derive(Clone, Copy)] 63#[derive(Clone, Copy)]
45#[repr(C)] 64#[repr(C)]
46pub struct DownloadHeader { 65pub struct DownloadHeader {
47 pub flag: u16, 66 pub flag: u16, //
48 pub dload_type: u16, 67 pub dload_type: u16,
49 pub len: u32, 68 pub len: u32,
50 pub crc: u32, 69 pub crc: u32,
51} 70}
71impl_bytes!(DownloadHeader);
52 72
53macro_rules! impl_bytes { 73pub const DOWNLOAD_FLAG_NO_CRC: u16 = 0x0001;
54 ($t:ident) => { 74pub const DOWNLOAD_FLAG_BEGIN: u16 = 0x0002;
55 impl $t { 75pub const DOWNLOAD_FLAG_END: u16 = 0x0004;
56 pub const SIZE: usize = core::mem::size_of::<Self>(); 76pub const DOWNLOAD_FLAG_HANDLER_VER: u16 = 0x1000;
57 77
58 pub fn to_bytes(&self) -> [u8; Self::SIZE] { 78pub const DOWNLOAD_TYPE_CLM: u16 = 2;
59 unsafe { core::mem::transmute(*self) }
60 }
61 79
62 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self { 80#[derive(Clone, Copy)]
63 unsafe { core::mem::transmute(*bytes) } 81#[repr(C)]
64 } 82pub struct CountryInfo {
65 } 83 pub country_abbrev: [u8; 4],
66 }; 84 pub rev: i32,
85 pub country_code: [u8; 4],
67} 86}
68impl_bytes!(SdpcmHeader); 87impl_bytes!(CountryInfo);
69impl_bytes!(CdcHeader);
70impl_bytes!(BdcHeader);
71impl_bytes!(DownloadHeader);