From e404cccecd20a2418c2429cd182c18218e54bd28 Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 14 Oct 2006 12:34:38 +0000 Subject: Prepare RFID compilation in firmware mode - switch from linked lists to static arrays - remove all non-handle dynamic allocations (at the expense of stack) - declare all proto/reader/asic/layer2 structures as const - wrap all handle allocations in macros that expand to references to static structures in case of firmware mode - update copyright notices - add skeleton code for openpcd-inside-firmware driver - update TODO with remaining TODO for firmware mode git-svn-id: https://svn.gnumonks.org/trunk/librfid@1903 e0336214-984f-0b4b-a45f-81c69e1f0ede --- src/rfid_layer2.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/rfid_layer2.c') diff --git a/src/rfid_layer2.c b/src/rfid_layer2.c index a6ee43f..ff6d2b0 100644 --- a/src/rfid_layer2.c +++ b/src/rfid_layer2.c @@ -24,19 +24,24 @@ #include #include -static struct rfid_layer2 *rfid_layer2_list; +static const struct rfid_layer2 *rfid_layer2s[] = { + [RFID_LAYER2_ISO14443A] = &rfid_layer2_iso14443a, + [RFID_LAYER2_ISO14443B] = &rfid_layer2_iso14443b, + [RFID_LAYER2_ISO15693] = &rfid_layer2_iso15693, +}; struct rfid_layer2_handle * rfid_layer2_init(struct rfid_reader_handle *rh, unsigned int id) { struct rfid_layer2 *p; - for (p = rfid_layer2_list; p; p = p->next) - if (p->id == id) - return p->fn.init(rh); + if (id >= ARRAY_SIZE(rfid_layer2s)) { + DEBUGP("unable to find matching layer2 protocol\n"); + return NULL; + } - DEBUGP("unable to find matching layer2 protocol\n"); - return NULL; + p = rfid_layer2s[id]; + return p->fn.init(rh); } int @@ -79,15 +84,6 @@ rfid_layer2_close(struct rfid_layer2_handle *ph) return ph->l2->fn.close(ph); } -int -rfid_layer2_register(struct rfid_layer2 *p) -{ - p->next = rfid_layer2_list; - rfid_layer2_list = p; - - return 0; -} - int rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname, void *optval, unsigned int *optlen) -- cgit v1.2.3