madk_pp_protocol.h
Last updated: 29-Aug-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Â void *log_handle; 112Â char log_prot_type; 114Â unsigned log_msg_id; 115Â std::vector<unsigned char> log_chunk_buf; 123Â void registerAdkLogCallback(void *handle, char protType, unsigned msgId, int reg_opts); 128Â void unregisterAdkLogCallback(void *handle); 129Â #endif 130Â static mADK_PP_Prot *obj; // singleton 131Â 132Â // disable calling copy constructor and assignment operator 133Â mADK_PP_Prot(const mADK_PP_Prot &); 134Â void operator=(const mADK_PP_Prot &); 135Â #if __cplusplus >= 201103L // since C++11 also forbid usage of move 136Â mADK_PP_Prot(const mADK_PP_Prot&&); 137Â mADK_PP_Prot& operator=(mADK_PP_Prot&&); 138Â #endif 139Â 140Â // disable constructor and force caller to use getInstance() 141Â mADK_PP_Prot(); 144Â virtual ~mADK_PP_Prot(); 145Â 148Â static void *run(void *data); 149Â 156Â static enum CommandType getCommandType(const unsigned char *cmd, unsigned size); 157Â 162Â static bool isCallbackResponse(const enum CommandType cmd); 163Â 171Â bool _poll(int timeout_msec); 172Â 181Â bool _receive(std::vector<unsigned char> &cmd, int timeout_msec); 182Â 189Â bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const; 190Â 197Â int _get_connection_type(void *handle); 198Â public: 199Â 202Â static mADK_PP_Prot *getInstance(); 203Â 207Â inline struct mADK_PP_Prot_Loader *loader() 208Â { 209Â return lib; 210Â } 211Â 218Â bool poll(int timeout_msec = -1); 219Â 227Â bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1); 228Â 237Â bool abort(); 238Â 250Â bool send(const unsigned char *cmd, unsigned size); 251Â 253Â inline bool send(const std::vector<unsigned char> &cmd) 254Â { 255Â return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size()); 256Â } 257Â 269Â bool command(const unsigned char *cmd, unsigned size); 270Â 287Â bool request(const unsigned char *cmd, unsigned size); 288Â 290Â inline bool request(const std::vector<unsigned char> &cmd) 291Â { 292Â return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size()); 293Â } 294Â 307Â bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1); 308Â 332Â bool set_busy(bool flag, bool cmd_ctx = true); 333Â 337Â bool loadAcl(); 338Â 340Â enum CMDActiveType 341Â { 342Â CMD_None = 0, 343Â CMD_Active = 1, 344Â CMD_Nested = 2 345Â }; 349Â inline enum CMDActiveType command_active() const 350Â { 351Â if (cmd_active) 352Â { 353Â if (nested_cmd) 354Â { 355Â return CMD_Nested; 356Â } 357Â 358Â return CMD_Active; 359Â } 360Â 361Â return CMD_None; 362Â } 363Â 367Â bool start(); 368Â 372Â void stop(); 373Â 376Â void setRecoveryMode(bool on_off); 377Â 380Â inline enum ProtocolState get_protocol_state() const 381Â { 382Â return prot_state; 383Â } 384Â 390Â inline bool connected() const 391Â { 392Â return !!get_handle(); 393Â } 394Â 399Â inline bool check_abort() const 400Â { 401Â return cancelled; 402Â } 403Â 412Â void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId); 413Â 414Â #ifdef _STM32 415Â 420Â void adkLogForwarder(const unsigned char *logdata, int len); 421Â #endif 422Â 424Â bool get_status(struct ProtStatus *status) const; 425Â 427Â bool get_connection_info(struct ConnectInfo *info) const; 428Â 430Â void free_connection_info(struct ConnectInfo *info) const; 431Â 433Â void set_com_profile(const char *file) const; 434Â 439Â bool trusted_connection(); 440Â 447Â bool get_tcp_info(struct TcpInfo *info); 448Â 455Â bool get_uds_info(struct UdsInfo *info); 456Â 461Â void *get_handle() const; 462Â 465Â char get_protocol_type() const; 466Â 481Â bool isConnectionThread() const; 482Â 490Â bool isMainConnectionThread() const; 491Â 498Â int select(int comInterfaces, char **ComFileName); 499Â 502Â void reset(); 503Â }; 504Â 507Â class mADK_PP_ProtBusyLock 508Â { 509Â mADK_PP_Prot *m_proto; 510Â bool m_locked; 511Â 512Â // disable copy constructor and assign operator 513Â mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&); 514Â mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&); 515Â #if __cplusplus >= 201103L // since C++11 also forbid usage of move 516Â mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&); 517Â mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&); 518Â #endif 519Â 520Â public: 525Â mADK_PP_ProtBusyLock(bool cmd_ctx = true) 526Â { 527Â m_proto = mADK_PP_Prot::getInstance(); 528Â m_locked = m_proto->set_busy(true, cmd_ctx); 529Â } 531Â virtual ~mADK_PP_ProtBusyLock() 532Â { 533Â unlock(); 534Â } 537Â void unlock() 538Â { 539Â if (m_locked) 540Â { 541Â m_proto->set_busy(false); 542Â m_locked = false; 543Â } 544Â } 547Â bool locked() const 548Â { 549Â return m_locked; 550Â } 551Â }; 552Â 553Â #endif
Rate this article: