Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/12524 )
Change subject: gsm23003: add osmo_imei_str_valid() ...................................................................... Patch Set 3: (2 comments) https://gerrit.osmocom.org/#/c/12524/3/src/gsm/gsm23003.c File src/gsm/gsm23003.c: https://gerrit.osmocom.org/#/c/12524/3/src/gsm/gsm23003.c@83 PS3, Line 83: bool I think it may be interesting to the caller *why* it failed validation. So a simple bool value may be too simple. Maybe return negative error codes and 0 on success? Then the negative error codes could have an enum or #defines differentiating the cause. https://gerrit.osmocom.org/#/c/12524/3/src/gsm/gsm23003.c@93 PS3, Line 93: /* Verify Luhn algorithm (see Wikipedia) : * digit id (i) | 00 01 02 03 04 05 06 07 08 09 10 11 12 13 CHK : * double | x x x x x x x : * do not double | x x x x x x x : */ : : /* Double every second digit and add it to sum */ : for (i = 1; i < 14; i += 2) { : int check = 2 * (imei[i] - '0'); : if (check > 9) : check -= 9; : sum += check; : } the IMEI checksumming function should definitely be a separate function, as it may be useful in other purposes. The osmo_imei_str_valid could then simply call that checksum-generation function and do the compare. -- To view, visit https://gerrit.osmocom.org/12524 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: Id2d2a3a93b033bafc74c62e15297034bf4aafe61 Gerrit-Change-Number: 12524 Gerrit-PatchSet: 3 Gerrit-Owner: osmith <osm...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) Gerrit-Reviewer: Max <msur...@sysmocom.de> Gerrit-Reviewer: Neels Hofmeyr <nhofm...@sysmocom.de> Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com> Gerrit-Reviewer: osmith <osm...@sysmocom.de> Gerrit-Comment-Date: Mon, 14 Jan 2019 12:52:12 +0000 Gerrit-HasComments: Yes Gerrit-HasLabels: No