madk_pp_protocol.h
Last updated: 07-Apr-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Â }; 82Â enum RequestType 83Â { 84Â Request_None = 0, 85Â Request_EMV = 1, 86Â Request_Ctrl = 2, 87Â Request_Trgr = 3 88Â }; 89Â RequestType req_type; 90Â bool recovery_mode; 91Â bool busy; 92Â bool cancelled; 93Â bool unlock_payment_pending; 96Â void *main_handle; 103Â void *busy_handle; 106Â static mADK_PP_Prot *obj; // singleton 107Â 108Â // disable calling copy constructor and assignment operator 109Â mADK_PP_Prot(const mADK_PP_Prot &); 110Â void operator=(const mADK_PP_Prot &); 111Â #if __cplusplus >= 201103L // since C++11 also forbid usage of move 112Â mADK_PP_Prot(const mADK_PP_Prot&&); 113Â mADK_PP_Prot& operator=(mADK_PP_Prot&&); 114Â #endif 115Â 116Â // disable constructor and force caller to use getInstance() 117Â mADK_PP_Prot(); 120Â virtual ~mADK_PP_Prot(); 121Â 124Â static void *run(void *data); 125Â 132Â static enum CommandType getCommandType(const unsigned char *cmd, unsigned size); 133Â 138Â static bool isCallbackResponse(const enum CommandType cmd); 139Â 147Â bool _poll(int timeout_msec); 148Â 157Â bool _receive(std::vector<unsigned char> &cmd, int timeout_msec); 158Â 165Â bool _send(void *handle, const unsigned char *cmd, unsigned size, char protType, unsigned msgId) const; 166Â 173Â int _get_connection_type(void *handle); 174Â public: 175Â 178Â static mADK_PP_Prot *getInstance(); 179Â 183Â inline struct mADK_PP_Prot_Loader *loader() 184Â { 185Â return lib; 186Â } 187Â 194Â bool poll(int timeout_msec = -1); 195Â 203Â bool receive(std::vector<unsigned char> &cmd, int timeout_msec = -1); 204Â 213Â bool abort(); 214Â 226Â bool send(const unsigned char *cmd, unsigned size); 227Â 229Â inline bool send(const std::vector<unsigned char> &cmd) 230Â { 231Â return send(cmd.size() > 0 ? &cmd[0] : 0, cmd.size()); 232Â } 233Â 245Â bool command(const unsigned char *cmd, unsigned size); 246Â 263Â bool request(const unsigned char *cmd, unsigned size); 264Â 266Â inline bool request(const std::vector<unsigned char> &cmd) 267Â { 268Â return request(cmd.size() > 0 ? &cmd[0] : 0, cmd.size()); 269Â } 270Â 283Â bool recv_response(std::vector<unsigned char> &response, int timeout_msec = -1); 284Â 308Â bool set_busy(bool flag, bool cmd_ctx = true); 309Â 313Â bool loadAcl(); 314Â 316Â enum CMDActiveType 317Â { 318Â CMD_None = 0, 319Â CMD_Active = 1, 320Â CMD_Nested = 2 321Â }; 325Â inline enum CMDActiveType command_active() const 326Â { 327Â if (cmd_active) 328Â { 329Â if (nested_cmd) 330Â { 331Â return CMD_Nested; 332Â } 333Â 334Â return CMD_Active; 335Â } 336Â 337Â return CMD_None; 338Â } 339Â 343Â bool start(); 344Â 348Â void stop(); 349Â 352Â void setRecoveryMode(bool on_off); 353Â 356Â inline enum ProtocolState get_protocol_state() const 357Â { 358Â return prot_state; 359Â } 360Â 366Â inline bool connected() const 367Â { 368Â return !!get_handle(); 369Â } 370Â 375Â inline bool check_abort() const 376Â { 377Â return cancelled; 378Â } 379Â 388Â void set_command(void *handle, char *cmd, int size, char protType, unsigned msgId); 389Â 391Â bool get_status(struct ProtStatus *status) const; 392Â 394Â bool get_connection_info(struct ConnectInfo *info) const; 395Â 397Â void free_connection_info(struct ConnectInfo *info) const; 398Â 400Â void set_com_profile(const char *file) const; 401Â 406Â bool trusted_connection(); 407Â 414Â bool get_tcp_info(struct TcpInfo *info); 415Â 422Â bool get_uds_info(struct UdsInfo *info); 423Â 428Â void *get_handle() const; 429Â 432Â char get_protocol_type() const; 433Â 448Â bool isConnectionThread() const; 449Â 457Â bool isMainConnectionThread() const; 458Â 465Â int select(int comInterfaces, char **ComFileName); 466Â 469Â void reset(); 470Â }; 471Â 474Â class mADK_PP_ProtBusyLock 475Â { 476Â mADK_PP_Prot *m_proto; 477Â bool m_locked; 478Â 479Â // disable copy constructor and assign operator 480Â mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&); 481Â mADK_PP_ProtBusyLock& operator=(const mADK_PP_ProtBusyLock&); 482Â #if __cplusplus >= 201103L // since C++11 also forbid usage of move 483Â mADK_PP_ProtBusyLock(const mADK_PP_ProtBusyLock&&); 484Â mADK_PP_ProtBusyLock& operator=(mADK_PP_ProtBusyLock&&); 485Â #endif 486Â 487Â public: 492Â mADK_PP_ProtBusyLock(bool cmd_ctx = true) 493Â { 494Â m_proto = mADK_PP_Prot::getInstance(); 495Â m_locked = m_proto->set_busy(true, cmd_ctx); 496Â } 498Â virtual ~mADK_PP_ProtBusyLock() 499Â { 500Â unlock(); 501Â } 504Â void unlock() 505Â { 506Â if (m_locked) 507Â { 508Â m_proto->set_busy(false); 509Â m_locked = false; 510Â } 511Â } 514Â bool locked() const 515Â { 516Â return m_locked; 517Â } 518Â }; 519Â 520Â #endif
Rate this article: