diff options
author | laforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede> | 2006-10-14 12:34:38 +0000 |
---|---|---|
committer | laforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede> | 2006-10-14 12:34:38 +0000 |
commit | e404cccecd20a2418c2429cd182c18218e54bd28 (patch) | |
tree | 5a15b5ca51874f0f8e96ccc4ee0457a66de3cec7 /src/rfid_protocol.c | |
parent | 6e87a007525b313dcf2da194977bb1abdf62026f (diff) |
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
Diffstat (limited to 'src/rfid_protocol.c')
-rw-r--r-- | src/rfid_protocol.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/rfid_protocol.c b/src/rfid_protocol.c index b24243a..1a4262a 100644 --- a/src/rfid_protocol.c +++ b/src/rfid_protocol.c @@ -1,5 +1,5 @@ /* librfid - layer 3 protocol handler - * (C) 2005 by Harald Welte <laforge@gnumonks.org> + * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org> */ /* @@ -24,7 +24,11 @@ #include <librfid/rfid_layer2.h> #include <librfid/rfid_protocol.h> -static struct rfid_protocol *rfid_protocol_list; +static const struct rfid_protocol *rfid_protocols[] = { + [RFID_PROTOCOL_MIFARE_CLASSIC] = &rfid_protocol_mfcl, + [RFID_PROTOCOL_MIFARE_UL] = &rfid_protocol_mful, + [RFID_PROTOCOL_TCL] = &rfid_protocol_tcl, +}; struct rfid_protocol_handle * rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id) @@ -32,13 +36,12 @@ rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id) struct rfid_protocol *p; struct rfid_protocol_handle *ph = NULL; - for (p = rfid_protocol_list; p; p = p->next) { - if (p->id == id) { - ph = p->fn.init(l2h); - break; - } - } + if (id >= ARRAY_SIZE(rfid_protocols)) + return NULL; + + p = rfid_protocols[id]; + ph = p->fn.init(l2h); if (!ph) return NULL; @@ -103,15 +106,6 @@ rfid_protocol_close(struct rfid_protocol_handle *ph) return 0; } -int -rfid_protocol_register(struct rfid_protocol *p) -{ - p->next = rfid_protocol_list; - rfid_protocol_list = p; - - return 0; -} - char *rfid_protocol_name(struct rfid_protocol_handle *ph) { return ph->proto->name; |