Skip to content

Commit 8c0c7f1

Browse files
zinonglihedger
andauthored
LFRFID: Show ISO-3166 Country Names For Pet Chips (#4091)
* Country list header and printf * off load country list to asset * lint * Field specific getters * check string length before cutting * lfrfid: minor iso3166 cleanup --------- Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
1 parent 013c5ff commit 8c0c7f1

File tree

5 files changed

+413
-4
lines changed

5 files changed

+413
-4
lines changed

applications/main/lfrfid/application.fam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ App(
77
icon="A_125khz_14",
88
stack_size=2 * 1024,
99
order=20,
10+
resources="resources",
1011
fap_libs=["assets"],
1112
fap_icon="icon.png",
1213
fap_category="RFID",
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
Filetype: Flipper LFRFID resources
2+
Version: 1
3+
# country code: 2-letter name 3-letter name full name
4+
0004: AF AFG Afghanistan
5+
0248: AX ALA Åland Islands
6+
0008: AL ALB Albania
7+
0012: DZ DZA Algeria
8+
0016: AS ASM American Samoa
9+
0020: AD AND Andorra
10+
0024: AO AGO Angola
11+
0660: AI AIA Anguilla
12+
0010: AQ ATA Antarctica
13+
0028: AG ATG Antigua and Barbuda
14+
0032: AR ARG Argentina
15+
0051: AM ARM Armenia
16+
0533: AW ABW Aruba
17+
0036: AU AUS Australia
18+
0040: AT AUT Austria
19+
0031: AZ AZE Azerbaijan
20+
0044: BS BHS Bahamas
21+
0048: BH BHR Bahrain
22+
0050: BD BGD Bangladesh
23+
0052: BB BRB Barbados
24+
0112: BY BLR Belarus
25+
0056: BE BEL Belgium
26+
0084: BZ BLZ Belize
27+
0204: BJ BEN Benin
28+
0060: BM BMU Bermuda
29+
0064: BT BTN Bhutan
30+
0068: BO BOL Bolivia, Plurinational State of
31+
0535: BQ BES Bonaire, Sint Eustatius and Saba
32+
0070: BA BIH Bosnia and Herzegovina
33+
0072: BW BWA Botswana
34+
0074: BV BVT Bouvet Island
35+
0076: BR BRA Brazil
36+
0086: IO IOT British Indian Ocean Territory
37+
0096: BN BRN Brunei Darussalam
38+
0100: BG BGR Bulgaria
39+
0854: BF BFA Burkina Faso
40+
0108: BI BDI Burundi
41+
0132: CV CPV Cabo Verde
42+
0116: KH KHM Cambodia
43+
0120: CM CMR Cameroon
44+
0124: CA CAN Canada
45+
0136: KY CYM Cayman Islands
46+
0140: CF CAF Central African Republic
47+
0148: TD TCD Chad
48+
0152: CL CHL Chile
49+
0156: CN CHN China
50+
0162: CX CXR Christmas Island
51+
0166: CC CCK Cocos (Keeling) Islands
52+
0170: CO COL Colombia
53+
0174: KM COM Comoros
54+
0178: CG COG Congo
55+
0180: CD COD Congo, Democratic Republic of the
56+
0184: CK COK Cook Islands
57+
0188: CR CRI Costa Rica
58+
0384: CI CIV Côte d'Ivoire
59+
0191: HR HRV Croatia
60+
0192: CU CUB Cuba
61+
0531: CW CUW Curaçao
62+
0196: CY CYP Cyprus
63+
0203: CZ CZE Czechia
64+
0208: DK DNK Denmark
65+
0262: DJ DJI Djibouti
66+
0212: DM DMA Dominica
67+
0214: DO DOM Dominican Republic
68+
0218: EC ECU Ecuador
69+
0818: EG EGY Egypt
70+
0222: SV SLV El Salvador
71+
0226: GQ GNQ Equatorial Guinea
72+
0232: ER ERI Eritrea
73+
0233: EE EST Estonia
74+
0748: SZ SWZ Eswatini
75+
0231: ET ETH Ethiopia
76+
0238: FK FLK Falkland Islands (Malvinas)
77+
0234: FO FRO Faroe Islands
78+
0242: FJ FJI Fiji
79+
0246: FI FIN Finland
80+
0250: FR FRA France
81+
0254: GF GUF French Guiana
82+
0258: PF PYF French Polynesia
83+
0260: TF ATF French Southern Territories
84+
0266: GA GAB Gabon
85+
0270: GM GMB Gambia
86+
0268: GE GEO Georgia
87+
0276: DE DEU Germany
88+
0288: GH GHA Ghana
89+
0292: GI GIB Gibraltar
90+
0300: GR GRC Greece
91+
0304: GL GRL Greenland
92+
0308: GD GRD Grenada
93+
0312: GP GLP Guadeloupe
94+
0316: GU GUM Guam
95+
0320: GT GTM Guatemala
96+
0831: GG GGY Guernsey
97+
0324: GN GIN Guinea
98+
0624: GW GNB Guinea-Bissau
99+
0328: GY GUY Guyana
100+
0332: HT HTI Haiti
101+
0334: HM HMD Heard Island and McDonald Islands
102+
0336: VA VAT Holy See
103+
0340: HN HND Honduras
104+
0344: HK HKG Hong Kong
105+
0348: HU HUN Hungary
106+
0352: IS ISL Iceland
107+
0356: IN IND India
108+
0360: ID IDN Indonesia
109+
0364: IR IRN Iran, Islamic Republic of
110+
0368: IQ IRQ Iraq
111+
0372: IE IRL Ireland
112+
0833: IM IMN Isle of Man
113+
0376: IL ISR Israel
114+
0380: IT ITA Italy
115+
0388: JM JAM Jamaica
116+
0392: JP JPN Japan
117+
0832: JE JEY Jersey
118+
0400: JO JOR Jordan
119+
0398: KZ KAZ Kazakhstan
120+
0404: KE KEN Kenya
121+
0296: KI KIR Kiribati
122+
0408: KP PRK Korea, Democratic People's Republic of
123+
0410: KR KOR Korea, Republic of
124+
0414: KW KWT Kuwait
125+
0417: KG KGZ Kyrgyzstan
126+
0418: LA LAO Lao People's Democratic Republic
127+
0428: LV LVA Latvia
128+
0422: LB LBN Lebanon
129+
0426: LS LSO Lesotho
130+
0430: LR LBR Liberia
131+
0434: LY LBY Libya
132+
0438: LI LIE Liechtenstein
133+
0440: LT LTU Lithuania
134+
0442: LU LUX Luxembourg
135+
0446: MO MAC Macao
136+
0450: MG MDG Madagascar
137+
0454: MW MWI Malawi
138+
0458: MY MYS Malaysia
139+
0462: MV MDV Maldives
140+
0466: ML MLI Mali
141+
0470: MT MLT Malta
142+
0584: MH MHL Marshall Islands
143+
0474: MQ MTQ Martinique
144+
0478: MR MRT Mauritania
145+
0480: MU MUS Mauritius
146+
0175: YT MYT Mayotte
147+
0484: MX MEX Mexico
148+
0583: FM FSM Micronesia, Federated States of
149+
0498: MD MDA Moldova, Republic of
150+
0492: MC MCO Monaco
151+
0496: MN MNG Mongolia
152+
0499: ME MNE Montenegro
153+
0500: MS MSR Montserrat
154+
0504: MA MAR Morocco
155+
0508: MZ MOZ Mozambique
156+
0104: MM MMR Myanmar
157+
0516: NA NAM Namibia
158+
0520: NR NRU Nauru
159+
0524: NP NPL Nepal
160+
0528: NL NLD Netherlands, Kingdom of the
161+
0540: NC NCL New Caledonia
162+
0554: NZ NZL New Zealand
163+
0558: NI NIC Nicaragua
164+
0562: NE NER Niger
165+
0566: NG NGA Nigeria
166+
0570: NU NIU Niue
167+
0574: NF NFK Norfolk Island
168+
0807: MK MKD North Macedonia
169+
0580: MP MNP Northern Mariana Islands
170+
0578: NO NOR Norway
171+
0512: OM OMN Oman
172+
0586: PK PAK Pakistan
173+
0585: PW PLW Palau
174+
0275: PS PSE Palestine, State of
175+
0591: PA PAN Panama
176+
0598: PG PNG Papua New Guinea
177+
0600: PY PRY Paraguay
178+
0604: PE PER Peru
179+
0608: PH PHL Philippines
180+
0612: PN PCN Pitcairn
181+
0616: PL POL Poland
182+
0620: PT PRT Portugal
183+
0630: PR PRI Puerto Rico
184+
0634: QA QAT Qatar
185+
0638: RE REU Réunion
186+
0642: RO ROU Romania
187+
0643: RU RUS Russian Federation
188+
0646: RW RWA Rwanda
189+
0652: BL BLM Saint Barthélemy
190+
0654: SH SHN Saint Helena, Ascension and Tristan da Cunha
191+
0659: KN KNA Saint Kitts and Nevis
192+
0662: LC LCA Saint Lucia
193+
0663: MF MAF Saint Martin (French part)
194+
0666: PM SPM Saint Pierre and Miquelon
195+
0670: VC VCT Saint Vincent and the Grenadines
196+
0882: WS WSM Samoa
197+
0674: SM SMR San Marino
198+
0678: ST STP Sao Tome and Principe
199+
0682: SA SAU Saudi Arabia
200+
0686: SN SEN Senegal
201+
0688: RS SRB Serbia
202+
0690: SC SYC Seychelles
203+
0694: SL SLE Sierra Leone
204+
0702: SG SGP Singapore
205+
0534: SX SXM Sint Maarten (Dutch part)
206+
0703: SK SVK Slovakia
207+
0705: SI SVN Slovenia
208+
0090: SB SLB Solomon Islands
209+
0706: SO SOM Somalia
210+
0710: ZA ZAF South Africa
211+
0239: GS SGS South Georgia and the South Sandwich Islands
212+
0728: SS SSD South Sudan
213+
0724: ES ESP Spain
214+
0144: LK LKA Sri Lanka
215+
0729: SD SDN Sudan
216+
0740: SR SUR Suriname
217+
0744: SJ SJM Svalbard and Jan Mayen
218+
0752: SE SWE Sweden
219+
0756: CH CHE Switzerland
220+
0760: SY SYR Syrian Arab Republic
221+
0158: TW TWN Taiwan, Province of China
222+
0762: TJ TJK Tajikistan
223+
0834: TZ TZA Tanzania, United Republic of
224+
0764: TH THA Thailand
225+
0626: TL TLS Timor-Leste
226+
0768: TG TGO Togo
227+
0772: TK TKL Tokelau
228+
0776: TO TON Tonga
229+
0780: TT TTO Trinidad and Tobago
230+
0788: TN TUN Tunisia
231+
0792: TR TUR Türkiye
232+
0795: TM TKM Turkmenistan
233+
0796: TC TCA Turks and Caicos Islands
234+
0798: TV TUV Tuvalu
235+
0800: UG UGA Uganda
236+
0804: UA UKR Ukraine
237+
0784: AE ARE United Arab Emirates
238+
0826: GB GBR United Kingdom of Great Britain and Northern Ireland
239+
0840: US USA United States of America
240+
0581: UM UMI United States Minor Outlying Islands
241+
0858: UY URY Uruguay
242+
0860: UZ UZB Uzbekistan
243+
0548: VU VUT Vanuatu
244+
0862: VE VEN Venezuela, Bolivarian Republic of
245+
0704: VN VNM Viet Nam
246+
0092: VG VGB Virgin Islands (British)
247+
0850: VI VIR Virgin Islands (U.S.)
248+
0876: WF WLF Wallis and Futuna
249+
0732: EH ESH Western Sahara
250+
0887: YE YEM Yemen
251+
0894: ZM ZMB Zambia
252+
0716: ZW ZWE Zimbabwe

lib/lfrfid/protocols/protocol_fdx_b.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <bit_lib/bit_lib.h>
66
#include "lfrfid_protocols.h"
77
#include <furi_hal_rtc.h>
8+
#include <tools/iso_3166.h>
89

910
#define FDX_B_ENCODED_BIT_SIZE (128)
1011
#define FDX_B_ENCODED_BYTE_SIZE (((FDX_B_ENCODED_BIT_SIZE) / 8))
@@ -287,15 +288,21 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) {
287288
uint8_t user_info = bit_lib_get_bits(protocol->data, 55, 5);
288289
uint8_t replacement_number = bit_lib_get_bits(protocol->data, 60, 3);
289290
bool animal_flag = bit_lib_get_bit(protocol->data, 63);
291+
Storage* storage = furi_record_open(RECORD_STORAGE);
292+
FuriString* country_full_name = furi_string_alloc();
293+
bool country_found = iso_3166_get_full_name(storage, country_code, country_full_name);
294+
furi_record_close(RECORD_STORAGE);
290295

291296
furi_string_printf(
292297
result,
293298
"ID: %03hu-%012llu\n"
294299
"Country Code: %hu\n"
300+
"Country: %s\n"
295301
"Temperature: ",
296302
country_code,
297303
national_code,
298-
country_code);
304+
country_code,
305+
(country_found) ? furi_string_get_cstr(country_full_name) : "Unknown");
299306

300307
float temperature;
301308
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
@@ -320,6 +327,8 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) {
320327
reserved,
321328
user_info,
322329
replacement_number);
330+
331+
furi_string_free(country_full_name);
323332
}
324333

325334
void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result) {
@@ -328,14 +337,18 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result
328337

329338
// 10 bit of country code
330339
uint16_t country_code = protocol_fdx_b_get_country_code(protocol->data);
331-
340+
Storage* storage = furi_record_open(RECORD_STORAGE);
341+
FuriString* country_two_letter = furi_string_alloc();
342+
bool country_found = iso_3166_get_two_letter(storage, country_code, country_two_letter);
343+
furi_record_close(RECORD_STORAGE);
332344
furi_string_printf(
333345
result,
334346
"ID: %03hu-%012llu\n"
335-
"Country: %hu; Temp.: ",
347+
"Country: %hu %s; Temp.: ",
336348
country_code,
337349
national_code,
338-
country_code);
350+
country_code,
351+
(country_found) ? furi_string_get_cstr(country_two_letter) : "Unknown");
339352

340353
float temperature;
341354
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
@@ -348,6 +361,8 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result
348361
} else {
349362
furi_string_cat(result, "---");
350363
}
364+
365+
furi_string_free(country_two_letter);
351366
}
352367

353368
bool protocol_fdx_b_write_data(ProtocolFDXB* protocol, void* data) {

0 commit comments

Comments
 (0)