taler-xotp_fw

xOTP generator firmware
Log | Files | Refs | Submodules | README

autoPayInterface.h (3565B)


      1 /**
      2  * @file autoPayInterface.h
      3  * @author Adrian STEINER (steia19@bfh.ch)
      4  * @brief Autopay interface to automated payment without user interaction
      5  * @version 0.1
      6  * @date 29-07-2025
      7  *
      8  * @copyright (C) 2025 Adrian STEINER
      9  * This program is free software: you can redistribute it and/or modify
     10  * it under the terms of the GNU General Public License as published by
     11  * the Free Software Foundation, either version 3 of the License, or
     12  * (at your option) any later version.
     13  *
     14  * This program is distributed in the hope that it will be useful,
     15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  * GNU General Public License for more details.
     18  *
     19  * You should have received a copy of the GNU General Public License
     20  * along with this program.  If not, see <https: //www.gnu.org/licenses/>.
     21  *
     22  */
     23 
     24 #ifndef AUTOPAY_INTERFACE_H
     25 #define AUTOPAY_INTERFACE_H
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #include <stdint.h>
     32 #include <xtotpConfig.h>
     33 
     34 /**
     35  * @brief Callback type for power control functions.
     36  */
     37 typedef void (*autoPayPwrCB)(void);
     38 
     39 /**
     40  * @brief Callback type to retrieve received codes.
     41  *
     42  * @param receivedPasscodes Pointer where the received codes will
     43  * be stored. It as the size of @ref XTOTP_AUTOPAY_RECEIVED_PASSKEYS.
     44  * @return uint8_t 0 for nothing received, 1 for received passkeys.
     45  */
     46 typedef uint8_t (*autoPayGetPasscodes)(uint32_t *receivedPasscodes);
     47 
     48 /**
     49  * @brief Callback to check if passcodes are received
     50  *
     51  * @return True if passcodes are received, false otherwise
     52  */
     53 typedef bool (*autoPayArePasscodesReceived)(void);
     54 
     55 /**
     56  * @brief Callback type to send a formatted URL.
     57  *
     58  * @param format Format string (similar to printf).
     59  * @param ... Additional arguments for the format string.
     60  * @return uint8_t Status code (e.g., 0 for success, non-zero for error).
     61  */
     62 typedef uint8_t (*autoPaySendURL)(const char *format, ...);
     63 
     64 /**
     65  * @brief Callback type to check if the URL has been read.
     66  *
     67  * @return True if the URL is read, false otherwise.
     68  */
     69 typedef bool (*autoPayIsURLRead)(void);
     70 
     71 /**
     72  * @brief Structure representing the AutoPay interface.
     73  */
     74 typedef struct {
     75   autoPayPwrCB powerOn;             ///< Callback to power on the module.
     76   autoPayPwrCB powerOff;            ///< Callback to power off the module.
     77   autoPayGetPasscodes getPasscodes; ///< Callback to retrieve received passkeys.
     78   autoPayArePasscodesReceived
     79       arePasscodesReceived;   ///< Callback to ceck if passcodes are received
     80   autoPaySendURL sendURL;     ///< Callback to send a formatted URL.
     81   autoPayIsURLRead isURLRead; ///< Callback to read if URL is read
     82   uint8_t transmitState;      ///< Saves the current transmit state
     83 } autoPayInterface;
     84 
     85 /**
     86  * @brief Initializes the AutoPay interface with the provided callbacks.
     87  *
     88  * @param interfaceHandler Pointer to the AutoPay interface structure to
     89  * initialize.
     90  * @param powerOnCB Callback for powering on the module.
     91  * @param powerOffCB Callback for powering off the module.
     92  * @param getCodesCB Callback for retrieving received codes.
     93  * @param sendURLCB Callback for sending a formatted URL.
     94  * @param isURLReadCB Callback for checking if the url is read
     95  */
     96 uint8_t
     97 autoPay_initInterface(autoPayInterface *interfaceHandler,
     98     autoPayPwrCB powerOnCB,
     99     autoPayPwrCB powerOffCB,
    100     autoPayGetPasscodes getPasscodesCB,
    101     autoPayArePasscodesReceived arePasscodesReceivedCB,
    102     autoPaySendURL sendURLCB,
    103     autoPayIsURLRead isURLReadCB);
    104 
    105 #ifdef __cplusplus
    106 }
    107 #endif
    108 
    109 #endif /* AUTOPAY_INTERFACE_H*/