Skip to main content

Application Development Kit (Version 4.7)


madk_pp_protocol.h

Last updated: 30-Jul-2025
Go to the documentation of this file.
    1 /*****************************************************************************    2  *  Company:     Verifone    3  *  Author:      GSS R&D Germany    4  *  Content:     SDI-Server    5  ****************************************************************************/    6 #ifndef _MADK_PP_PROTOCOL_H_    7 #define _MADK_PP_PROTOCOL_H_    8      9 #include <vector>   10 #include <string>   11 #include <pthread.h>   12     14 struct mADK_PP_Prot_Loader;   16 struct ProtStatus;   17 struct ConnectInfo;   18 struct TcpInfo;   19 struct UdsInfo;   20     23 class mADK_PP_Prot   24 {   25   public:   26     27     enum ProtocolState   28     {   29       PS_Stopped = 0,    30       PS_Running = 1,    31       PS_Aborted = 2     32     };   33     34     enum AbortState   35     {   36       AS_NotAborted = 0,        37       AS_AbortIdle = 1,         38       AS_ConnectionLost = 2     41     };   42     43   private:   44 #ifndef _STM32 // no SDI protocol thread on Titus   45     pthread_t proto_thread;   46 #endif   47     pthread_mutex_t mutex;   48     pthread_cond_t cond;   49     std::vector<unsigned char> cmdbuf;   50     char prot_type;     52     unsigned msg_id;    53     unsigned msg_id_payment;    54     unsigned msg_id_nested;     55     enum ProtocolState prot_state;    56     bool cmd_active;    57     bool nested_cmd;    58     enum AbortState aborted;     59     unsigned cmd_counter;    61     struct mADK_PP_Prot_Loader *lib;    65     enum CommandType   66     {   67       Cmd_Any                   = 0,    68       Cmd_Abort                 = 1,    69       Cmd_LockPayment           = 2,    71       Cmd_ResetLink             = 3,    74       Cmd_Check4Update          = 4,    75       Cmd_ExtButton             = 5,    76       Cmd_EmvCbResponse         = 6,    77       Cmd_CtrlCbResponse        = 7,    78       Cmd_TrgrCbResponse        = 8,    79       Cmd_PaymentNotificationCb = 9,    80       Cmd_RegisterAdkLogCb      = 10    82     };   84     enum RequestType   85     {   86       Request_None = 0,     87       Request_EMV  = 1,     88       Request_Ctrl = 2,     89       Request_Trgr = 3      90     };   91     RequestType req_type;    92     bool recovery_mode;    93     bool busy;    94     bool cancelled;    95     bool unlock_payment_pending;    98     void *main_handle;    105     void *busy_handle;   108 #ifdef _STM32  109     pthread_mutex_t log_mutex;   110     void *log_handle;   113     char log_prot_type;   115     unsigned log_msg_id;   116     std::vector<unsigned char> log_chunk_buf;   124     void registerAdkLogCallback(void *handle, char protType, unsigned msgId, int reg_opts);  129     void unregisterAdkLogCallback(void *handle);  130 #endif  131     static mADK_PP_Prot *obj; // singleton  132    133     // disable calling copy constructor and assignment operator  134     mADK_PP_Prot(const mADK_PP_Prot &);  135     void operator=(const mADK_PP_Prot &);  136 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  137     mADK_PP_Prot(const mADK_PP_Prot&&);  138     mADK_PP_Prot& operator=(mADK_PP_Prot&&);  139 #endif  140    141     // disable constructor and force caller to use getInstance()  142     mADK_PP_Prot();  145     virtual ~mADK_PP_Prot();  146    149     static void *run(void *data);  150    157     static enum CommandType getCommandType(const unsigned char *cmd, unsigned size);  158    163     static bool isCallbackResponse(const enum CommandType cmd);  164    172     bool _poll(int timeout_msec);  173    182     bool _receive(std::vector<unsigned char> &cmd, int timeout_msec);  183    190     bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const;  191    198     int _get_connection_type(void *handle);  199   public:  200    203     static mADK_PP_Prot *getInstance();  204    208     inline struct mADK_PP_Prot_Loader *loader()  209     {  210       return lib;  211     }  212    219     bool poll(int timeout_msec = -1);  220    228     bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1);  229    238     bool abort();  239    251     bool send(const unsigned char *cmd, unsigned size);  252    254     inline bool send(const std::vector<unsigned char> &cmd)  255     {  256       return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  257     }  258    270     bool command(const unsigned char *cmd, unsigned size);  271    288     bool request(const unsigned char *cmd, unsigned size);  289    291     inline bool request(const std::vector<unsigned char> &cmd)  292     {  293       return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size());  294     }  295    308     bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1);  309    333     bool set_busy(bool flag, bool cmd_ctx = true);  334    338     bool loadAcl();  339    341     enum CMDActiveType  342     {  343       CMD_None   = 0,   344       CMD_Active = 1,   345       CMD_Nested = 2    346     };  350     inline enum CMDActiveType command_active() const  351     {  352       if (cmd_active)  353       {  354         if (nested_cmd)  355         {  356           return CMD_Nested;  357         }  358    359         return CMD_Active;  360       }  361    362       return CMD_None;  363     }  364    368     bool start();  369    373     void stop();  374    377     void setRecoveryMode(bool on_off);  378    381     inline enum ProtocolState get_protocol_state() const  382     {  383       return prot_state;  384     }  385    391     inline bool connected() const  392     {  393       return !!get_handle();  394     }  395    400     inline bool check_abort() const  401     {  402       return cancelled;  403     }  404    413     void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId);  414    415 #ifdef _STM32  416    421     void adkLogForwarder(const unsigned char *logdata, int len);  422 #endif  423    425     bool get_status(struct ProtStatus *status) const;  426    428     bool get_connection_info(struct ConnectInfo *info) const;  429    431     void free_connection_info(struct ConnectInfo *info) const;  432    434     void set_com_profile(const char *file) const;  435    440     bool trusted_connection();  441    448     bool get_tcp_info(struct TcpInfo *info);  449    456     bool get_uds_info(struct UdsInfo *info);  457    462     void *get_handle() const;  463    466     char get_protocol_type() const;  467    482     bool isConnectionThread() const;  483    491     bool isMainConnectionThread() const;  492    499     int select(int comInterfaces, char **ComFileName);  500    503     void reset();  504 };  505    508 class mADK_PP_ProtBusyLock  509 {  510     mADK_PP_Prot *m_proto;  511     bool m_locked;  512    513     // disable copy constructor and assign operator  514     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&);  515     mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&);  516 #if __cplusplus >= 201103L // since C++11 also forbid usage of move  517     mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&);  518     mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&);  519 #endif  520    521   public:  526     mADK_PP_ProtBusyLock(bool cmd_ctx = true)  527     {  528       m_proto = mADK_PP_Prot::getInstance();  529       m_locked = m_proto->set_busy(true, cmd_ctx);  530     }  532     virtual ~mADK_PP_ProtBusyLock()  533     {  534       unlock();  535     }  538     void unlock()  539     {  540       if (m_locked)  541       {  542         m_proto->set_busy(false);  543         m_locked = false;  544       }  545     }  548     bool locked() const  549     {  550       return m_locked;  551     }  552 };  553    554 #endif

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo