From 939c3035191fb6ad89099e5d0249b91a11f9a479 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Fri, 27 Dec 2019 17:30:59 +0100 Subject: Change GPIO Pin --- src/main.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 90a9efb..ff8b8de 100644 --- a/src/main.c +++ b/src/main.c @@ -125,6 +125,7 @@ along with /* VMC commands */ #define VMC_CMD_START 0x02 #define VMC_CMD_END 0x03 +#define VMC_CMD_RESET 0x10 /** * Acknowledgement @@ -135,6 +136,8 @@ along with * Request for configuration. */ #define VMC_CONF 0x11 +#define VMC_READER_CONF 0x00 +#define VMC_SETUP_MAX_MIN_PRICES 0x01 /** * Machine is polling for something. @@ -192,7 +195,11 @@ along with /* Session Commands */ /* Refer to the mdb interface specifications v4.2 p.131 */ #define READER_BEGIN_SESSION "03" +<<<<<<< Updated upstream #define READER_FUNDS_AVAILABLE "000A" +======= +#define READER_FUNDS_AVAILABLE "00A0" +>>>>>>> Stashed changes #define READER_END_SESSION "07" /* Vend Commands */ @@ -796,6 +803,11 @@ cleanup_payment (struct PaymentActivity *pa) nfc_abort_command (pa->pnd); nfc_close (pa->pnd); } + if (NULL != cancelbutton_task) + { + GNUNET_SCHEDULER_cancel (cancelbutton_task); + cancelbutton_task = NULL; + } if (NULL != pa->po) TALER_MERCHANT_proposal_cancel (pa->po); if (NULL != pa->cpo) @@ -895,6 +907,11 @@ shutdown_task (void *cls) { cleanup_payment (payment_activity); payment_activity = NULL; + } + if (NULL != cancelbutton_task) + { + GNUNET_SCHEDULER_cancel (cancelbutton_task); + cancelbutton_task = NULL; } if (NULL != keyboard_task) { @@ -947,7 +964,11 @@ shutdown_task (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open /gpio/unexport for cancel button\n"); } +<<<<<<< Updated upstream (void) write (cancelButton.cancelbuttonfd, "17", 2); +======= + (void) write (cancelButton.cancelbuttonfd, "23", 2); +>>>>>>> Stashed changes close (cancelButton.cancelbuttonfd); } /* free the allocated productes read from config file */ @@ -2043,14 +2064,64 @@ handle_command (const char *hex, break; } case VMC_CONF: +<<<<<<< Updated upstream GNUNET_log (GNUNET_ERROR_TYPE_INFO, +======= + { + unsigned int subcmd; + + if (4 > hex_len) + { + GNUNET_break_op (0); + return; + } + if (1 != sscanf (&hex[2], + "%2X", + &subcmd)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received non-HEX input `%.*s'\n", + (int) hex_len - 2, + &hex[2]); + GNUNET_break_op (0); + return; + } + switch (subcmd) + { + case VMC_READER_CONF: + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, +>>>>>>> Stashed changes "Received request for configuration via MDB\n"); - mdb.cmd = &readerConfigData; - break; + mdb.cmd = &readerConfigData; + break; + + } + case VMC_SETUP_MAX_MIN_PRICES: + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received max and min prices via MDB\n"); + break; + } + default: + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unknown MDB sub-command %X of command %X\n", + subcmd, + cmd); + break; + } + break; + } case VMC_POLL: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received POLL from MDB (ignored)\n"); break; + case VMC_CMD_RESET: + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received RESET from MDB (ignored)\n"); + break; + } case VMC_READER: { unsigned int subcmd; @@ -2592,25 +2663,44 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open /gpio/export for cancel button\n"); } +<<<<<<< Updated upstream (void) write (cancelButton.cancelbuttonfd, "17", 2); close (cancelButton.cancelbuttonfd); cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/direction", +======= + (void) write (cancelButton.cancelbuttonfd, "23", 2); + close (cancelButton.cancelbuttonfd); + + cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio23/direction", +>>>>>>> Stashed changes O_WRONLY); if (0 > cancelButton.cancelbuttonfd) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, +<<<<<<< Updated upstream "Unable to open /gpio/gpio17/direction for cancel button\n"); +======= + "Unable to open /gpio/gpio23/direction for cancel button\n"); +>>>>>>> Stashed changes } (void) write (cancelButton.cancelbuttonfd, "in", 2); close (cancelButton.cancelbuttonfd); +<<<<<<< Updated upstream cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/value", +======= + cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio23/value", +>>>>>>> Stashed changes O_RDONLY); if (0 > cancelButton.cancelbuttonfd) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, +<<<<<<< Updated upstream "Unable to open /gpio/gpio17/value for cancel button\n"); +======= + "Unable to open /gpio/gpio23/value for cancel button\n"); +>>>>>>> Stashed changes } -- cgit v1.2.3 From eb731a9402f75c02138975caea6838602c6ddecf Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Fri, 27 Dec 2019 17:35:58 +0100 Subject: Solved merge conflicts --- src/main.c | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/main.c b/src/main.c index ff8b8de..1ff0255 100644 --- a/src/main.c +++ b/src/main.c @@ -195,11 +195,7 @@ along with /* Session Commands */ /* Refer to the mdb interface specifications v4.2 p.131 */ #define READER_BEGIN_SESSION "03" -<<<<<<< Updated upstream -#define READER_FUNDS_AVAILABLE "000A" -======= #define READER_FUNDS_AVAILABLE "00A0" ->>>>>>> Stashed changes #define READER_END_SESSION "07" /* Vend Commands */ @@ -964,11 +960,7 @@ shutdown_task (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open /gpio/unexport for cancel button\n"); } -<<<<<<< Updated upstream - (void) write (cancelButton.cancelbuttonfd, "17", 2); -======= (void) write (cancelButton.cancelbuttonfd, "23", 2); ->>>>>>> Stashed changes close (cancelButton.cancelbuttonfd); } /* free the allocated productes read from config file */ @@ -2064,9 +2056,6 @@ handle_command (const char *hex, break; } case VMC_CONF: -<<<<<<< Updated upstream - GNUNET_log (GNUNET_ERROR_TYPE_INFO, -======= { unsigned int subcmd; @@ -2091,7 +2080,6 @@ handle_command (const char *hex, case VMC_READER_CONF: { GNUNET_log (GNUNET_ERROR_TYPE_INFO, ->>>>>>> Stashed changes "Received request for configuration via MDB\n"); mdb.cmd = &readerConfigData; break; @@ -2663,44 +2651,25 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open /gpio/export for cancel button\n"); } -<<<<<<< Updated upstream - (void) write (cancelButton.cancelbuttonfd, "17", 2); - close (cancelButton.cancelbuttonfd); - - cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/direction", -======= (void) write (cancelButton.cancelbuttonfd, "23", 2); close (cancelButton.cancelbuttonfd); cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio23/direction", ->>>>>>> Stashed changes O_WRONLY); if (0 > cancelButton.cancelbuttonfd) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, -<<<<<<< Updated upstream - "Unable to open /gpio/gpio17/direction for cancel button\n"); -======= "Unable to open /gpio/gpio23/direction for cancel button\n"); ->>>>>>> Stashed changes } (void) write (cancelButton.cancelbuttonfd, "in", 2); close (cancelButton.cancelbuttonfd); -<<<<<<< Updated upstream - cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/value", -======= cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio23/value", ->>>>>>> Stashed changes O_RDONLY); if (0 > cancelButton.cancelbuttonfd) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, -<<<<<<< Updated upstream - "Unable to open /gpio/gpio17/value for cancel button\n"); -======= "Unable to open /gpio/gpio23/value for cancel button\n"); ->>>>>>> Stashed changes } -- cgit v1.2.3 From 4e42412ea244052fce5982705d6f8e533cef46ca Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 14:45:55 +0100 Subject: Added checksum comparsion --- src/main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 1ff0255..9c4edac 100644 --- a/src/main.c +++ b/src/main.c @@ -182,6 +182,9 @@ along with /* Reader commands */ +/* Reader Not Acknowledge */ +#define READER_NACK "FF" + /* Config Data */ /* Refer to the mdb interface specifications v4.2 p.288 */ #define READER_CONFIG "01" @@ -195,7 +198,7 @@ along with /* Session Commands */ /* Refer to the mdb interface specifications v4.2 p.131 */ #define READER_BEGIN_SESSION "03" -#define READER_FUNDS_AVAILABLE "00A0" +#define READER_FUNDS_AVAILABLE "000A" #define READER_END_SESSION "07" /* Vend Commands */ @@ -574,6 +577,10 @@ static struct MdbCommand revalueApproved; */ static struct MdbCommand revalueAmount; +/** + * Send NACK + */ +static struct MdbCommand readerNACK; /** * Terminate session. */ @@ -1880,6 +1887,8 @@ handle_command (const char *hex, size_t hex_len) { unsigned int cmd; + unsigned int tmp = 0; + uint32_t chkSum; /* if the received command is 0 or not a multiple of 2 we cannot parse it */ if (0 == hex_len) @@ -1894,7 +1903,7 @@ handle_command (const char *hex, return; } /* convert the received 2 bytes from ASCII to hex */ - if (1 != sscanf (hex, + if (1 != sscanf (hex, "%2X", &cmd)) { @@ -1905,7 +1914,39 @@ handle_command (const char *hex, GNUNET_break_op (0); return; } - /* parse the first byte (cmd) and the second byte (subcmd) */ + + /* Calculate the checksum and check it */ + if (2 < hex_len) + { + chkSum = cmd; + + for( size_t offset = 1; offset < ((hex_len / 2)); offset++ ){ + chkSum += tmp; + if (1 != sscanf (hex + (2 * offset), + "%2X", + &tmp)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received non-HEX input `%.*s'\n", + (int) hex_len, + hex); + GNUNET_break_op (0); + return; + } + } + if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) + { + mdb.cmd = &denyVend; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received command with wrong checksum `%.*s'\n", + (int) hex_len, + hex); + return; + + } + } + + /* parse the first byte (cmd) and the second byte (subcmd) */ switch (cmd) { case VMC_VEND: @@ -2892,6 +2933,11 @@ main (int argc, READER_REVALUE_LIMIT, READER_REVALUE_LIMIT_AMOUNT); + readerNACK = setup_mdb_cmd ("Reader NACK", + READER_NACK, + NULL); + + ret = GNUNET_PROGRAM_run (argc, argv, "taler-mdb", -- cgit v1.2.3 From a301dbd81c13c52aeda5989a04a4997827130077 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 15:41:11 +0100 Subject: empty products parsed sold out when -s enabled --- src/main.c | 10 +++++++- taler.conf | 78 +++++++++++++++++++++++++++++++------------------------------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/main.c b/src/main.c index 9c4edac..e1b2f1b 100644 --- a/src/main.c +++ b/src/main.c @@ -1999,7 +1999,7 @@ handle_command (const char *hex, if (product == products[i].number) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Product %u selected on NFC\n", + "Product %u selected on MDB\n", product); if ( (sold_out_enabled) && (products[i].sold_out) ) @@ -2396,6 +2396,14 @@ read_products (void *cls, "description"); return; } + if (sold_out_enabled) + { + if(0 == strcmp (tmpProduct.description, + "empty")) + { + tmpProduct.sold_out = GNUNET_YES; + } + } if (GNUNET_OK != TALER_config_get_denom (cls, section, diff --git a/taler.conf b/taler.conf index 8f382dd..4edf87f 100644 --- a/taler.conf +++ b/taler.conf @@ -1,9 +1,9 @@ [taler] -currency = TESTKUDOS +currency = EUR [taler-mdb] -backend-base-url = http://backend.test.taler.net/ -backend-authorization = ApiKey sandbox +backend-base-url = http://backend.euro.taler.net/ +backend-authorization = ApiKey Sandbox # taler url for success message (see taler documentation) fulfillment-url = taler://fulfillment-success # alternative url (see taler documentation) @@ -22,149 +22,149 @@ FRAMEBUFFER_DEVICE = /dev/fb1 FRAMEBUFFER_BACKLIGHT = /sys/class/backlight/soc:backlight/brightness #Products +#If sold out is enabled, products with description "empty" will be registered as sold out. #machine number 55 [product-21] description = empty -price = TESTKUDOS:0.1 +price = EUR:0.0 number = 46 #machine number 54 [product-20] description = empty -price = TESTKUDOS:0.1 +price = EUR:0.0 number = 45 #machine number 53 [product-19] description = empty -price = TESTKUDOS:0.1 +price = EUR:0.0 number = 44 #machine number 52 [product-18] -description = empty -price = TESTKUDOS:0.1 +description = T-Shirt M +price = EUR:5.0 number = 43 #machine number 51 [product-17] -description = empty -price = TESTKUDOS:0.1 +description = T-Shirt S +price = EUR:5.0 number = 42 #machine number 50 [product-16] -description = empty -price = TESTKUDOS:0.1 +description = Electronic Kit +price = EUR:10.0 number = 41 #machine number 45 [product-15] description = Snickers -price = TESTKUDOS:0.1 +price = EUR:0.3 number = 36 #machine number 44 [product-14] -description = empty -price = TESTKUDOS:0.1 +description = Electronic Kit +price = EUR:7.0 number = 35 #machine number 43 [product-13] -description = Twix -price = TESTKUDOS:0.1 +description = empty +price = EUR:0.0 key = d number = 34 #machine number 42 [product-12] description = Screwdriver -price = TESTKUDOS:0.1 +price = EUR:15.0 key = h number = 33 #machine number 41 [product-11] -description = empty -price = TESTKUDOS:0.1 +description = Twix +price = EUR:0.3 key = j number = 32 #machine number 40 [product-10] description = Mars -price = TESTKUDOS:0.1 +price = EUR:0.3 key = k -number = 30 +number = 31 #machine number 34 [product-9] -description = empty -price = TESTKUDOS:0.1 +description = Book GRM - Brainfuck +price = EUR:25.0 key = l number = 25 #machine number 30 [product-8] description = Meter -price = TESTKUDOS:0.1 +price = EUR:10.0 key = w number = 21 #machine number 25 [product-7] -description = empty -price = TESTKUDOS:0.1 +description = NFC TAG +price = EUR:1.0 key = e number = 16 #machine number 24 [product-6] description = Knive -price = TESTKUDOS:0.1 +price = EUR:25.0 key = r number = 15 #machine number 23 [product-5] -description = empty -price = TESTKUDOS:0.1 +description = Electronic Kit +price = EUR:5.0 key = t number = 14 #machine number 22 [product-4] description = empty -price = TESTKUDOS:0.1 +price = EUR:0.0 key = z number = 13 #machine number 21 [product-3] description = empty -price = TESTKUDOS:0.1 +price = EUR:0.0 key = u number = 12 #machine number 20 [product-2] description = Gummy bears -price = TESTKUDOS:0.1 +price = EUR:0.3 key = i -number = 10 +number = 11 #machine number 14 -[produt-1] +[product-1] description = Sword -price = TESTKUDOS:0.1 -key = o -number = 5 +price = EUR:0.05 +number = 5 #machine number 10 [product-0] description = Umbrella -price = TESTKUDOS:0.1 +price = EUR:10.0 key = p number = 1 -- cgit v1.2.3 From c6d1cce6b5b06d6cbe470963655f3282c3399b16 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 16:08:21 +0100 Subject: fix --- src/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index e1b2f1b..a5d1df3 100644 --- a/src/main.c +++ b/src/main.c @@ -1642,7 +1642,7 @@ read_keyboard_command (void *cls) if (((char) input) == products[i].key) { if ( (sold_out_enabled) && - (products[i].sold_out) ) + (GNUNET_YES == products[i].sold_out) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Product %s sold out, denying vend\n", @@ -2002,7 +2002,7 @@ handle_command (const char *hex, "Product %u selected on MDB\n", product); if ( (sold_out_enabled) && - (products[i].sold_out) ) + (GNUNET_YES == products[i].sold_out) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Product %s sold out, denying vend\n", @@ -2403,6 +2403,10 @@ read_products (void *cls, { tmpProduct.sold_out = GNUNET_YES; } + else + { + tmpProduct.sold_out = GNUNET_NO; + } } if (GNUNET_OK != TALER_config_get_denom (cls, -- cgit v1.2.3 From dfbf7d7788be411a0bd158f237c6f3f82af1f39f Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 17:44:40 +0100 Subject: Added message for display of VM --- src/main.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index a5d1df3..c1e6abb 100644 --- a/src/main.c +++ b/src/main.c @@ -216,8 +216,13 @@ along with /* Cancelled Command */ #define READER_CANCELLED "08" -/* Unused reader commands */ +/* Display Request for Sold Out product */ #define READER_DISPLAY_REQUEST "02" +#define READER_DISPLAY_REQUEST_TIME "32" +#define READER_DISPLAY_SOLD_OUT "202020202020202020204175737665726b617566742020202020202020202020" +#define READER_DISPLAY_INTERNAL_ERROR "202020496e7465726e616c204572726f72202d2054727920416761696e202020i" + +/* Unused reader commands */ #define READER_SESSION_CANCEL_REQUEST "04" #define READER_REVALUE_DENIED "0E" @@ -581,6 +586,16 @@ static struct MdbCommand revalueAmount; * Send NACK */ static struct MdbCommand readerNACK; + +/** + * Display Request for Sold Out + */ +static struct MdbCommand readerDisplaySoldOut; + +/** + * Display Request for Error Message + */ +static struct MdbCommand readerDisplayInternalError; /** * Terminate session. */ @@ -1647,7 +1662,7 @@ read_keyboard_command (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Product %s sold out, denying vend\n", products[i].description); - mdb.cmd = &denyVend; + mdb.cmd = &readerDisplaySoldOut; run_mdb_event_loop (); start_read_keyboard (); return; @@ -1866,6 +1881,11 @@ handle_ack () mdb.session_running = GNUNET_NO; mdb.cmd = &endSession; } + if (&readerDisplaySoldOut == mdb.last_cmd) + mdb.cmd = &denyVend; + if (&readerDisplayInternalError == mdb.last_cmd) + mdb.cmd = &denyVend; + mdb.last_cmd = NULL; /* Cause the write-task to be re-scheduled now */ if (NULL != mdb.wtask) @@ -1936,7 +1956,7 @@ handle_command (const char *hex, } if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) { - mdb.cmd = &denyVend; + mdb.cmd = &readerDisplayInternalError; GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received command with wrong checksum `%.*s'\n", (int) hex_len, @@ -2007,7 +2027,7 @@ handle_command (const char *hex, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Product %s sold out, denying vend\n", products[i].description); - mdb.cmd = &denyVend; + mdb.cmd = &readerDisplaySoldOut; return; } payment_activity = launch_payment (&products[i]); @@ -2949,6 +2969,15 @@ main (int argc, READER_NACK, NULL); + readerDisplaySoldOut = setup_mdb_cmd ("Display Sold Out", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_SOLD_OUT); + + readerDisplayInternalError = setup_mdb_cmd ("Display Communication Error", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_INTERNAL_ERROR); ret = GNUNET_PROGRAM_run (argc, argv, -- cgit v1.2.3 From b68e8d82b83d0850a794e40a4802dab555c48ae6 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 17:46:19 +0100 Subject: Changed product name --- taler.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taler.conf b/taler.conf index 4edf87f..397e1f9 100644 --- a/taler.conf +++ b/taler.conf @@ -109,7 +109,7 @@ number = 25 #machine number 30 [product-8] -description = Meter +description = Ruler price = EUR:10.0 key = w number = 21 -- cgit v1.2.3 From 22b5964470d94535e27164e84f762a149c1ad680 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 20:39:43 +0100 Subject: Dont test checksum for cmds smaller than or equal 2 bytes --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index c1e6abb..e98a68b 100644 --- a/src/main.c +++ b/src/main.c @@ -1936,7 +1936,7 @@ handle_command (const char *hex, } /* Calculate the checksum and check it */ - if (2 < hex_len) + if (4 < hex_len) { chkSum = cmd; -- cgit v1.2.3 From 71b28cbb4f3466f1a2690cf4ea4bf6bb69f1b48c Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sat, 28 Dec 2019 21:45:41 +0100 Subject: Calculate checksum just for products --- src/main.c | 59 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/main.c b/src/main.c index e98a68b..b85578f 100644 --- a/src/main.c +++ b/src/main.c @@ -1935,37 +1935,6 @@ handle_command (const char *hex, return; } - /* Calculate the checksum and check it */ - if (4 < hex_len) - { - chkSum = cmd; - - for( size_t offset = 1; offset < ((hex_len / 2)); offset++ ){ - chkSum += tmp; - if (1 != sscanf (hex + (2 * offset), - "%2X", - &tmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received non-HEX input `%.*s'\n", - (int) hex_len, - hex); - GNUNET_break_op (0); - return; - } - } - if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) - { - mdb.cmd = &readerDisplayInternalError; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Received command with wrong checksum `%.*s'\n", - (int) hex_len, - hex); - return; - - } - } - /* parse the first byte (cmd) and the second byte (subcmd) */ switch (cmd) { @@ -1994,6 +1963,34 @@ handle_command (const char *hex, { case VMC_VEND_REQUEST: { + + /* Calculate the checksum and check it */ + chkSum = cmd; + + for( size_t offset = 1; offset < ((hex_len / 2)); offset++ ){ + chkSum += tmp; + if (1 != sscanf (hex + (2 * offset), + "%2X", + &tmp)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received non-HEX input `%.*s'\n", + (int) hex_len, + hex); + GNUNET_break_op (0); + return; + } + } + if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) + { + mdb.cmd = &readerDisplayInternalError; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received command with wrong checksum `%.*s'\n", + (int) hex_len, + hex); + break; + + } unsigned int product; GNUNET_break (GNUNET_YES == mdb.session_running); -- cgit v1.2.3 From 8c3dd6adc49436abf582d0a5271de5d99dda480f Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 14:21:21 +0100 Subject: Commented Code --- src/main.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/src/main.c b/src/main.c index b85578f..14062c6 100644 --- a/src/main.c +++ b/src/main.c @@ -23,8 +23,6 @@ along with * @author Christian Grothoff * @author Dominik Hofer * -* TODO: -* - comment code mdb incl. doxygen struct members (hofer) */ #include "config.h" #include @@ -231,8 +229,14 @@ along with */ struct MdbBlock { + /** + * Data containing a mdb command or the data of an mdb command + */ uint8_t *bin; - + + /** + * Size of the data referenced by *bin + */ size_t bin_size; }; @@ -242,10 +246,19 @@ struct MdbBlock */ struct MdbCommand { - const char *name; + /** + * Name of the command for the logging + */ + const char *name; + /** + * Data block containing the information about the mdb command + */ struct MdbBlock cmd; - + + /** + * Data block containing the information about the mdb command data + */ struct MdbBlock data; }; @@ -364,19 +377,40 @@ struct PaymentActivity */ struct MdbHandle { - + + /** + * Buffer to save the received data from UART + */ uint8_t rxBuffer[MAX_SIZE_RX_BUFFER]; + /** + * Buffer to save the data to send via UART + */ uint8_t txBuffer[MAX_SIZE_TX_BUFFER]; + /** + * Reference to scheduler task to read from UART + */ struct GNUNET_SCHEDULER_Task *rtask; - + + /** + * Reference to scheduler task to write to UART + */ struct GNUNET_SCHEDULER_Task *wtask; + /** + * Reference to the mdb cmd which will be sent next + */ const struct MdbCommand *cmd; - + + /** + * Reference to the mdb cmd which was sent last + */ const struct MdbCommand *last_cmd; + /** + * Current read offset in @e rxBuffer. + */ size_t rx_off; /** @@ -390,12 +424,24 @@ struct MdbHandle */ size_t tx_len; + /** + * Time out to wait for an acknoweledge received via the mdb bus + */ struct GNUNET_TIME_Absolute ack_timeout; + /** + * Backup of the config data to restore the configuration of the UART before closing it + */ struct termios uart_opts_backup; + /** + * Indicates if a vend session is running or not + */ int session_running; + /** + * File descriptor to the UART device file + */ int uartfd; }; @@ -437,6 +483,16 @@ struct Display struct fb_fix_screeninfo fix_info; }; +/** + * Handle for the Cancel Button + */ +struct CancelButton +{ + /** + * File descriptor to read the state of the cancel button gpio pin + */ + int cancelbuttonfd; +}; /** * DLL of pending refund operations. */ @@ -486,10 +542,13 @@ static int global_ret; static int in_shutdown; /** - * Refenence to the keyboard task + * Reference to the keyboard task */ static struct GNUNET_SCHEDULER_Task *keyboard_task; +/** + * Reference to the cancel button task + */ static struct GNUNET_SCHEDULER_Task *cancelbutton_task; /** @@ -626,10 +685,7 @@ static char backlight_on = '1'; */ static char backlight_off = '0'; -struct CancelButton -{ - int cancelbuttonfd; -}; + static struct CancelButton cancelButton; /** * Name of the UART device with the MDB (i.e. /dev/ttyAMA0). -- cgit v1.2.3 From c5eacc36540381bc9423e6ee888707c6d95cb3d3 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 14:56:05 +0100 Subject: Added Error message backend not reachable --- src/main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 14062c6..507dcef 100644 --- a/src/main.c +++ b/src/main.c @@ -219,6 +219,7 @@ along with #define READER_DISPLAY_REQUEST_TIME "32" #define READER_DISPLAY_SOLD_OUT "202020202020202020204175737665726b617566742020202020202020202020" #define READER_DISPLAY_INTERNAL_ERROR "202020496e7465726e616c204572726f72202d2054727920416761696e202020i" +#define READER_DISPLAY_BACKEND_NOT_REACHABLE "20202020204261636b656e64206e6f7420726561636861626c65202020202020" /* Unused reader commands */ #define READER_SESSION_CANCEL_REQUEST "04" @@ -655,6 +656,12 @@ static struct MdbCommand readerDisplaySoldOut; * Display Request for Error Message */ static struct MdbCommand readerDisplayInternalError; + +/** + * Display Request for Error Message + */ +static struct MdbCommand readerDisplayBackendNotReachable; + /** * Terminate session. */ @@ -1340,7 +1347,7 @@ check_payment_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Backend request to /check-payment failed: %u\n", http_status); - mdb.cmd = &denyVend; + mdb.cmd = &readerDisplayBackendNotReachable; run_mdb_event_loop (); cleanup_payment (pa); GNUNET_assert (payment_activity == pa); @@ -1941,7 +1948,8 @@ handle_ack () mdb.cmd = &denyVend; if (&readerDisplayInternalError == mdb.last_cmd) mdb.cmd = &denyVend; - + if (&readerDisplayBackendNotReachable == mdb.last_cmd) + mdb.cmd = &denyVend; mdb.last_cmd = NULL; /* Cause the write-task to be re-scheduled now */ if (NULL != mdb.wtask) @@ -3031,7 +3039,10 @@ main (int argc, READER_DISPLAY_REQUEST, READER_DISPLAY_REQUEST_TIME READER_DISPLAY_INTERNAL_ERROR); - + readerDisplayBackendNotReachable = setup_mdb_cmd ("Display Backend not reachable", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_BACKEND_NOT_REACHABLE); ret = GNUNET_PROGRAM_run (argc, argv, "taler-mdb", -- cgit v1.2.3 From 5b222ba440264d7667ce1b1c71b4aa89be91b558 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 15:47:42 +0100 Subject: Added new product to conf file --- taler.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taler.conf b/taler.conf index 397e1f9..7d925de 100644 --- a/taler.conf +++ b/taler.conf @@ -38,8 +38,8 @@ number = 45 #machine number 53 [product-19] -description = empty -price = EUR:0.0 +description = Hackerspace Passport +price = EUR:1.0 number = 44 #machine number 52 -- cgit v1.2.3 From 76317ca0f43da6fd28923fbd537090d48c3d31f3 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 15:48:17 +0100 Subject: Changed Ausverkauft to Sold Out --- src/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 507dcef..54da007 100644 --- a/src/main.c +++ b/src/main.c @@ -217,7 +217,7 @@ along with /* Display Request for Sold Out product */ #define READER_DISPLAY_REQUEST "02" #define READER_DISPLAY_REQUEST_TIME "32" -#define READER_DISPLAY_SOLD_OUT "202020202020202020204175737665726b617566742020202020202020202020" +#define READER_DISPLAY_SOLD_OUT "202020202020202050726f6475637420736f6c64206f75742020202020202020" #define READER_DISPLAY_INTERNAL_ERROR "202020496e7465726e616c204572726f72202d2054727920416761696e202020i" #define READER_DISPLAY_BACKEND_NOT_REACHABLE "20202020204261636b656e64206e6f7420726561636861626c65202020202020" @@ -1446,7 +1446,7 @@ proposal_cb (void *cls, "Failed to setup order with backend: %u/%d\n", http_status, (int) ec); - mdb.cmd = &denyVend; + mdb.cmd = &readerDisplayBackendNotReachable; run_mdb_event_loop (); cleanup_payment (pa); GNUNET_assert (payment_activity == pa); @@ -3039,10 +3039,11 @@ main (int argc, READER_DISPLAY_REQUEST, READER_DISPLAY_REQUEST_TIME READER_DISPLAY_INTERNAL_ERROR); + readerDisplayBackendNotReachable = setup_mdb_cmd ("Display Backend not reachable", - READER_DISPLAY_REQUEST, - READER_DISPLAY_REQUEST_TIME - READER_DISPLAY_BACKEND_NOT_REACHABLE); + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_BACKEND_NOT_REACHABLE); ret = GNUNET_PROGRAM_run (argc, argv, "taler-mdb", -- cgit v1.2.3 From 9992e8510a279db915884b616be5339675dcdc75 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 18:39:29 +0100 Subject: Increased poll timeout for backend --- src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 54da007..2ce84c5 100644 --- a/src/main.c +++ b/src/main.c @@ -69,7 +69,8 @@ along with */ #define _(s) (s) -#define BACKEND_POLL_TIMEOUT GNUNET_TIME_UNIT_MINUTES +/* FIXME Adjusted Time out because low internet connection at 36C3 */ +#define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_MINUTES, 5) #define NFC_FAILURE_RETRY_FREQ GNUNET_TIME_UNIT_SECONDS -- cgit v1.2.3 From 2cc7b72a47890e42a5d8e2a69716ac6fcf5666cc Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Sun, 29 Dec 2019 18:52:06 +0100 Subject: Some little comments --- src/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 2ce84c5..dd80fb6 100644 --- a/src/main.c +++ b/src/main.c @@ -1741,6 +1741,11 @@ read_keyboard_command (void *cls) start_read_keyboard (); } +/** + * @brief Read the state of the cancel button GPIO pin + * + * @param cls closure + */ static void cancel_button_pressed (void *cls) { @@ -1812,17 +1817,19 @@ start_read_keyboard () NULL); } +/** + * @brief Wait for cancel button during payment activity + */ static void start_read_cancel_button () { struct GNUNET_DISK_FileHandle fh = { cancelButton.cancelbuttonfd }; GNUNET_assert (NULL == cancelbutton_task); - cancelbutton_task = GNUNET_SCHEDULER_add_read_file ( - GNUNET_TIME_UNIT_FOREVER_REL, - &fh, - &cancel_button_pressed, - NULL); + cancelbutton_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, + &fh, + &cancel_button_pressed, + NULL); } /** -- cgit v1.2.3 From 57c757d1d5ec3604525739b5eb4aa1ce3d560542 Mon Sep 17 00:00:00 2001 From: Dominik Hofer Date: Mon, 30 Dec 2019 15:28:15 +0100 Subject: sold out resetted when machine open --- src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.c b/src/main.c index dd80fb6..9eadbf4 100644 --- a/src/main.c +++ b/src/main.c @@ -2268,6 +2268,19 @@ handle_command (const char *hex, cleanup_payment (payment_activity); payment_activity = NULL; } + for (unsigned int i = 0; i < products_length; i++) + { + if ( (sold_out_enabled) && + (0 != strcmp (products[i].description, + "empty")) && + (GNUNET_YES == products[i].sold_out) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Resetting sold out state of product %s\n", + products[i].description); + products[i].sold_out = GNUNET_NO; + } + } break; case VMC_READER_ENABLE: GNUNET_log (GNUNET_ERROR_TYPE_INFO, -- cgit v1.2.3 From dca6cd094d195666aaed42b558d56f15f4f8c9af Mon Sep 17 00:00:00 2001 From: Boss Marco Date: Thu, 2 Jan 2020 20:01:36 +0100 Subject: fix --- src/main.c | 300 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 156 insertions(+), 144 deletions(-) diff --git a/src/main.c b/src/main.c index 9eadbf4..fb15fc7 100644 --- a/src/main.c +++ b/src/main.c @@ -70,7 +70,8 @@ along with #define _(s) (s) /* FIXME Adjusted Time out because low internet connection at 36C3 */ -#define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_MINUTES, 5) +#define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, 5) #define NFC_FAILURE_RETRY_FREQ GNUNET_TIME_UNIT_SECONDS @@ -218,9 +219,12 @@ along with /* Display Request for Sold Out product */ #define READER_DISPLAY_REQUEST "02" #define READER_DISPLAY_REQUEST_TIME "32" -#define READER_DISPLAY_SOLD_OUT "202020202020202050726f6475637420736f6c64206f75742020202020202020" -#define READER_DISPLAY_INTERNAL_ERROR "202020496e7465726e616c204572726f72202d2054727920416761696e202020i" -#define READER_DISPLAY_BACKEND_NOT_REACHABLE "20202020204261636b656e64206e6f7420726561636861626c65202020202020" +#define READER_DISPLAY_SOLD_OUT \ + "202020202020202050726f6475637420736f6c64206f75742020202020202020" +#define READER_DISPLAY_INTERNAL_ERROR \ + "202020496e7465726e616c204572726f72202d2054727920416761696e202020i" +#define READER_DISPLAY_BACKEND_NOT_REACHABLE \ + "20202020204261636b656e64206e6f7420726561636861626c65202020202020" /* Unused reader commands */ #define READER_SESSION_CANCEL_REQUEST "04" @@ -231,12 +235,12 @@ along with */ struct MdbBlock { - /** + /** * Data containing a mdb command or the data of an mdb command */ uint8_t *bin; - - /** + + /** * Size of the data referenced by *bin */ size_t bin_size; @@ -248,18 +252,18 @@ struct MdbBlock */ struct MdbCommand { - /** - * Name of the command for the logging + /** + * Name of the command for the logging */ - const char *name; + const char *name; /** * Data block containing the information about the mdb command */ struct MdbBlock cmd; - - /** - * Data block containing the information about the mdb command data + + /** + * Data block containing the information about the mdb command data */ struct MdbBlock data; }; @@ -379,38 +383,38 @@ struct PaymentActivity */ struct MdbHandle { - - /** + + /** * Buffer to save the received data from UART */ uint8_t rxBuffer[MAX_SIZE_RX_BUFFER]; - /** + /** * Buffer to save the data to send via UART */ uint8_t txBuffer[MAX_SIZE_TX_BUFFER]; - /** - * Reference to scheduler task to read from UART + /** + * Reference to scheduler task to read from UART */ struct GNUNET_SCHEDULER_Task *rtask; - - /** - * Reference to scheduler task to write to UART + + /** + * Reference to scheduler task to write to UART */ struct GNUNET_SCHEDULER_Task *wtask; - /** - * Reference to the mdb cmd which will be sent next + /** + * Reference to the mdb cmd which will be sent next */ const struct MdbCommand *cmd; - - /** - * Reference to the mdb cmd which was sent last + + /** + * Reference to the mdb cmd which was sent last */ const struct MdbCommand *last_cmd; - /** + /** * Current read offset in @e rxBuffer. */ size_t rx_off; @@ -426,23 +430,23 @@ struct MdbHandle */ size_t tx_len; - /** + /** * Time out to wait for an acknoweledge received via the mdb bus */ struct GNUNET_TIME_Absolute ack_timeout; - /** + /** * Backup of the config data to restore the configuration of the UART before closing it */ struct termios uart_opts_backup; - /** - * Indicates if a vend session is running or not + /** + * Indicates if a vend session is running or not */ int session_running; - /** - * File descriptor to the UART device file + /** + * File descriptor to the UART device file */ int uartfd; @@ -490,8 +494,8 @@ struct Display */ struct CancelButton { - /** - * File descriptor to read the state of the cancel button gpio pin + /** + * File descriptor to read the state of the cancel button gpio pin */ int cancelbuttonfd; }; @@ -644,7 +648,7 @@ static struct MdbCommand revalueApproved; static struct MdbCommand revalueAmount; /** - * Send NACK + * Send NACK */ static struct MdbCommand readerNACK; @@ -885,11 +889,11 @@ cleanup_payment (struct PaymentActivity *pa) nfc_abort_command (pa->pnd); nfc_close (pa->pnd); } - if (NULL != cancelbutton_task) - { - GNUNET_SCHEDULER_cancel (cancelbutton_task); - cancelbutton_task = NULL; - } + if (NULL != cancelbutton_task) + { + GNUNET_SCHEDULER_cancel (cancelbutton_task); + cancelbutton_task = NULL; + } if (NULL != pa->po) TALER_MERCHANT_proposal_cancel (pa->po); if (NULL != pa->cpo) @@ -990,7 +994,7 @@ shutdown_task (void *cls) cleanup_payment (payment_activity); payment_activity = NULL; } - if (NULL != cancelbutton_task) + if (NULL != cancelbutton_task) { GNUNET_SCHEDULER_cancel (cancelbutton_task); cancelbutton_task = NULL; @@ -1755,26 +1759,32 @@ cancel_button_pressed (void *cls) read (cancelButton.cancelbuttonfd, &value, 1); lseek (cancelButton.cancelbuttonfd, 0, SEEK_SET); - if ( '1' == value ) + if (NULL != payment_activity) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Cancel button pressed, canceling current order\n"); - if (GNUNET_NO == payment_activity->paid) + if ('1' == value) { - mdb.cmd = &denyVend; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Cancel button pressed, canceling current order\n"); + if (GNUNET_NO == payment_activity->paid) + { + /* The current payment was not paid already, deny it */ + mdb.cmd = &denyVend; + } + else + { + /* The order was paid and if we know this, then it is also yielded, + * just end the current session */ + mdb.cmd = &endSession; + mdb.session_running = GNUNET_NO; + } + run_mdb_event_loop (); + cleanup_payment (payment_activity); + payment_activity = NULL; } else { - mdb.cmd = &endSession; - mdb.session_running = GNUNET_NO; + start_read_cancel_button (); } - run_mdb_event_loop (); - cleanup_payment (payment_activity); - payment_activity = NULL; - } - else - { - start_read_cancel_button (); } } @@ -1826,10 +1836,11 @@ start_read_cancel_button () struct GNUNET_DISK_FileHandle fh = { cancelButton.cancelbuttonfd }; GNUNET_assert (NULL == cancelbutton_task); - cancelbutton_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - &fh, - &cancel_button_pressed, - NULL); + cancelbutton_task = GNUNET_SCHEDULER_add_read_file ( + GNUNET_TIME_UNIT_FOREVER_REL, + &fh, + &cancel_button_pressed, + NULL); } /** @@ -1952,12 +1963,12 @@ handle_ack () mdb.session_running = GNUNET_NO; mdb.cmd = &endSession; } - if (&readerDisplaySoldOut == mdb.last_cmd) - mdb.cmd = &denyVend; - if (&readerDisplayInternalError == mdb.last_cmd) - mdb.cmd = &denyVend; - if (&readerDisplayBackendNotReachable == mdb.last_cmd) - mdb.cmd = &denyVend; + if (&readerDisplaySoldOut == mdb.last_cmd) + mdb.cmd = &denyVend; + if (&readerDisplayInternalError == mdb.last_cmd) + mdb.cmd = &denyVend; + if (&readerDisplayBackendNotReachable == mdb.last_cmd) + mdb.cmd = &denyVend; mdb.last_cmd = NULL; /* Cause the write-task to be re-scheduled now */ if (NULL != mdb.wtask) @@ -1979,8 +1990,8 @@ handle_command (const char *hex, size_t hex_len) { unsigned int cmd; - unsigned int tmp = 0; - uint32_t chkSum; + unsigned int tmp = 0; + uint32_t chkSum; /* if the received command is 0 or not a multiple of 2 we cannot parse it */ if (0 == hex_len) @@ -1995,7 +2006,7 @@ handle_command (const char *hex, return; } /* convert the received 2 bytes from ASCII to hex */ - if (1 != sscanf (hex, + if (1 != sscanf (hex, "%2X", &cmd)) { @@ -2006,8 +2017,8 @@ handle_command (const char *hex, GNUNET_break_op (0); return; } - - /* parse the first byte (cmd) and the second byte (subcmd) */ + + /* parse the first byte (cmd) and the second byte (subcmd) */ switch (cmd) { case VMC_VEND: @@ -2035,34 +2046,34 @@ handle_command (const char *hex, { case VMC_VEND_REQUEST: { - - /* Calculate the checksum and check it */ - chkSum = cmd; - - for( size_t offset = 1; offset < ((hex_len / 2)); offset++ ){ - chkSum += tmp; - if (1 != sscanf (hex + (2 * offset), - "%2X", - &tmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Received non-HEX input `%.*s'\n", - (int) hex_len, - hex); - GNUNET_break_op (0); - return; - } - } - if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) - { - mdb.cmd = &readerDisplayInternalError; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Received command with wrong checksum `%.*s'\n", - (int) hex_len, - hex); - break; - - } + + /* Calculate the checksum and check it */ + chkSum = cmd; + + for ( size_t offset = 1; offset < ((hex_len / 2)); offset++ ) { + chkSum += tmp; + if (1 != sscanf (hex + (2 * offset), + "%2X", + &tmp)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Received non-HEX input `%.*s'\n", + (int) hex_len, + hex); + GNUNET_break_op (0); + return; + } + } + if ( ((uint8_t) (chkSum & 0xFF)) != tmp ) + { + mdb.cmd = &readerDisplayInternalError; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received command with wrong checksum `%.*s'\n", + (int) hex_len, + hex); + break; + + } unsigned int product; GNUNET_break (GNUNET_YES == mdb.session_running); @@ -2186,7 +2197,7 @@ handle_command (const char *hex, break; } case VMC_CONF: - { + { unsigned int subcmd; if (4 > hex_len) @@ -2209,11 +2220,11 @@ handle_command (const char *hex, { case VMC_READER_CONF: { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received request for configuration via MDB\n"); - mdb.cmd = &readerConfigData; - break; - + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received request for configuration via MDB\n"); + mdb.cmd = &readerConfigData; + break; + } case VMC_SETUP_MAX_MIN_PRICES: { @@ -2234,12 +2245,12 @@ handle_command (const char *hex, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received POLL from MDB (ignored)\n"); break; - case VMC_CMD_RESET: - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received RESET from MDB (ignored)\n"); - break; - } + case VMC_CMD_RESET: + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received RESET from MDB (ignored)\n"); + break; + } case VMC_READER: { unsigned int subcmd; @@ -2269,17 +2280,17 @@ handle_command (const char *hex, payment_activity = NULL; } for (unsigned int i = 0; i < products_length; i++) - { - if ( (sold_out_enabled) && - (0 != strcmp (products[i].description, - "empty")) && - (GNUNET_YES == products[i].sold_out) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Resetting sold out state of product %s\n", - products[i].description); - products[i].sold_out = GNUNET_NO; - } + { + if ( (sold_out_enabled) && + (0 != strcmp (products[i].description, + "empty")) && + (GNUNET_YES == products[i].sold_out) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Resetting sold out state of product %s\n", + products[i].description); + products[i].sold_out = GNUNET_NO; + } } break; case VMC_READER_ENABLE: @@ -2500,15 +2511,15 @@ read_products (void *cls, } if (sold_out_enabled) { - if(0 == strcmp (tmpProduct.description, - "empty")) + if (0 == strcmp (tmpProduct.description, + "empty")) { tmpProduct.sold_out = GNUNET_YES; } else - { - tmpProduct.sold_out = GNUNET_NO; - } + { + tmpProduct.sold_out = GNUNET_NO; + } } if (GNUNET_OK != TALER_config_get_denom (cls, @@ -3047,24 +3058,25 @@ main (int argc, READER_REVALUE_LIMIT, READER_REVALUE_LIMIT_AMOUNT); - readerNACK = setup_mdb_cmd ("Reader NACK", - READER_NACK, - NULL); + readerNACK = setup_mdb_cmd ("Reader NACK", + READER_NACK, + NULL); - readerDisplaySoldOut = setup_mdb_cmd ("Display Sold Out", - READER_DISPLAY_REQUEST, - READER_DISPLAY_REQUEST_TIME - READER_DISPLAY_SOLD_OUT); - - readerDisplayInternalError = setup_mdb_cmd ("Display Communication Error", - READER_DISPLAY_REQUEST, - READER_DISPLAY_REQUEST_TIME - READER_DISPLAY_INTERNAL_ERROR); - - readerDisplayBackendNotReachable = setup_mdb_cmd ("Display Backend not reachable", - READER_DISPLAY_REQUEST, - READER_DISPLAY_REQUEST_TIME - READER_DISPLAY_BACKEND_NOT_REACHABLE); + readerDisplaySoldOut = setup_mdb_cmd ("Display Sold Out", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_SOLD_OUT); + + readerDisplayInternalError = setup_mdb_cmd ("Display Communication Error", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_INTERNAL_ERROR); + + readerDisplayBackendNotReachable = setup_mdb_cmd ( + "Display Backend not reachable", + READER_DISPLAY_REQUEST, + READER_DISPLAY_REQUEST_TIME + READER_DISPLAY_BACKEND_NOT_REACHABLE); ret = GNUNET_PROGRAM_run (argc, argv, "taler-mdb", -- cgit v1.2.3 From f65ff1dcc78817568ccec591e43f2c436abb2347 Mon Sep 17 00:00:00 2001 From: Boss Marco Date: Thu, 2 Jan 2020 20:18:32 +0100 Subject: comments added --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index fb15fc7..4ddbaab 100644 --- a/src/main.c +++ b/src/main.c @@ -1537,6 +1537,7 @@ launch_payment (struct Product *product) GNUNET_free (pa); return NULL; } + /* Start to read the button on the VM to cancel this payment */ if (0 < cancelButton.cancelbuttonfd) start_read_cancel_button (); return pa; @@ -1759,6 +1760,9 @@ cancel_button_pressed (void *cls) read (cancelButton.cancelbuttonfd, &value, 1); lseek (cancelButton.cancelbuttonfd, 0, SEEK_SET); + /* This point should only be reached when a order is pending, because + * the scheduler read file gets added in the function "launch_payment". + * But anyway safe check, else do nothing */ if (NULL != payment_activity) { if ('1' == value) -- cgit v1.2.3 From 1e464cbc9e230895ad3cee64f83bc4452b12e767 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Jan 2020 20:39:14 +0100 Subject: rename: TALER_config_get_denom->amount --- src/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 4ddbaab..96c26df 100644 --- a/src/main.c +++ b/src/main.c @@ -1944,7 +1944,7 @@ write_mdb_command (void *cls) chkSum += mdb.txBuffer[idx] = mdb.cmd->cmd.bin[idx]; for (size_t idx = 0; idx < mdb.cmd->data.bin_size; idx++) chkSum += mdb.txBuffer[idx + mdb.cmd->cmd.bin_size] = - mdb.cmd->data.bin[idx]; + mdb.cmd->data.bin[idx]; mdb.txBuffer[mdb.cmd->cmd.bin_size + mdb.cmd->data.bin_size] = (uint8_t) (chkSum & 0xFF); } @@ -2526,10 +2526,10 @@ read_products (void *cls, } } if (GNUNET_OK != - TALER_config_get_denom (cls, - section, - "price", - &tmpProduct.price)) + TALER_config_get_amount (cls, + section, + "price", + &tmpProduct.price)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, -- cgit v1.2.3