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
Rate this article: