> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/mdb_8h_source.md).

# mdb.h

[Go to the documentation of this file.](/adk-5.0-programmers-guide/readme/files/dir_6eccc81e1a8c1e178b12a3e7244db536/dir_9ac5a55d32dfa781317271fdea6662e8/dir_02ed3189b8c93be56ce53dadfc251ab1/mdb_8h.md)

```cpp
 1 #ifndef MDB_MDB_H_20211111
 2 #define MDB_MDB_H_20211111
 3 
 6 #include <stddef.h>
 7 
 8 #if defined _WIN32 && defined VFI_MDB_EXPORT
 9 # define DllSpec __declspec(dllexport)
 10 #elif defined __GNUC__ && defined VFI_MDB_EXPORT
 11 # define DllSpec __attribute__((visibility ("default")))
 12 #else
 13 # define DllSpec
 14 #endif
 15 
 16 #ifdef __cplusplus
 17 
 18 // C++ interface
 19 
 20 #include <vector>
 21 #include <string>
 22 
 23 namespace vfimdb {
 24 
 26 // these are just the negative value of the corresponding SPROC_Error error code
 27 enum MDB_Error {
 28  MDBE_OK = 0x00,
 29  MDBE_NOT_CONNECTED =-0x01,
 30  MDBE_IO_ERROR =-0x02,
 31  MDBE_PROTOCOL =-0x03,
 32  MDBE_INVALID_TLV =-0x04,
 33  MDBE_RESET =-0x05,
 35  MDBE_ERROR =-0x10,
 36  MDBE_MESSAGE_TOO_LARGE=-0x11,
 37  MDBE_INVALID_COMMAND =-0x12,
 38  MDBE_INVALID_PARAM =-0x13,
 39  MDBE_CANCELLED =-0x14,
 40  MDBE_NO_RESOURCE =-0x15,
 41  MDBE_BUSY =-0x1A,
 42  MDBE_INVALID_SEQUENCE =-0x1C,
 43  MDBE_TIMEOUT =-0x1D,
 44  MDBE_NOT_FOUND =-0x1F,
 45 };
 46 
 47 enum {
 48  MDB_CMD_SIZE = 35,
 49  MDB_CMD_CHK_SIZE = MDB_CMD_SIZE + 1,
 50  MDB_FTL_BYTES_PER_BLOCK = 31,
 51  MDB_FTL_LAST_SESSION_FLAG = 0x02,
 52  MDB_FTL_COMMAND_WAITTIME=2500, // time in ms to wait for OkToSend
 53  MDB_UNKNOWN_MAX_AMOUNT=0xffffffff,
 54  MDB_UNKNOWN_ITEM=0xffff
 55 };
 56 
 58 enum MDBAddress {
 59  MDB_VMC = 0,
 60  MDB_CASHLESS_1 = 0x10,
 61  MDB_GATEWAY = 0x18,
 62  MDB_DISPLAY = 0x20,
 63  MDB_CASHLESS_2 = 0x60,
 64  MDB_AGE_VERIFICATION = 0x68,
 65  MDB_CASHLESS_1_GATEWAY = 0x1810,
 66  MDB_CASHLESS_2_GATEWAY = 0x1860,
 67  MDB_CASHLESS_1_DISPLAY = 0x2010,
 68  MDB_CASHLESS_2_DISPLAY = 0x2060,
 69  MDB_CASHLESS_1_AGE_VERIFICATION = 0x6810,
 70  MDB_CASHLESS_2_AGE_VERIFICATION = 0x6860,
 71  MDB_CASHLESS_1_GATEWAY_AGE_VERIFICATION = 0x681810,
 72  MDB_CASHLESS_2_GATEWAY_AGE_VERIFICATION = 0x681860,
 73  MDB_CASHLESS_1_GATEWAY_DISPLAY = 0x201810,
 74  MDB_CASHLESS_2_GATEWAY_DISPLAY = 0x201860,
 75  MDB_CASHLESS_1_DISPLAY_AGE_VERIFICATION = 0x682010,
 76  MDB_CASHLESS_2_DISPLAY_AGE_VERIFICATION = 0x682060,
 77  MDB_CASHLESS_1_GATEWAY_DISPLAY_AGE_VERIFICATION = 0x68201810,
 78  MDB_CASHLESS_2_GATEWAY_DISPLAY_AGE_VERIFICATION = 0x68201860,
 79 };
 80 
 81 #if 0 // TODO: remove or implement
 82 
 83 enum MDBConfigFlags {
 84  AUTO_ACK=1,
 85  AUTO_RESET=2,
 86 };
 87 #endif
 88 
 90 enum MDBCommand {
 91  MDB_UNKNOWN = -2,
 92  MDB_NO_COMMAND = -1,
 94  // numbering scheme is <command><subcommand>
 95  MDB_RESET = 0x0000,
 96  MDB_SETUP_CONFIG_DATA = 0x0100,
 97  MDB_SETUP_PRICE = 0x0101,
 98  MDB_POLL = 0x0200,
 99  MDB_VEND_REQUEST = 0x0300,
 100  MDB_VEND_CANCEL = 0x0301,
 101  MDB_VEND_SUCCESS = 0x0302,
 102  MDB_VEND_FAILURE = 0x0303,
 103  MDB_SESSION_COMPLETE = 0x0304,
 104  MDB_CASH_SALE = 0x0305,
 105  MDB_NEGATIVE_VEND_REQUEST = 0x0306,
 106  MDB_DISABLE = 0x0400,
 107  MDB_ENABLE = 0x0401,
 108  MDB_CANCEL = 0x0402,
 109  MDB_DATA_ENTRY = 0x0403,
 110  MDB_REVALUE_AMOUNT = 0x0500,
 111  MDB_REVALUE_LIMIT = 0x0501,
 112  MDB_REQUEST_ID = 0x0700,
 113  MDB_DATE_TIME = 0x0703,
 114  MDB_FEATURE_OPTIONS = 0x0704,
 115  MDB_FTL_REQUEST_TO_RECEIVE= 0x07FA,
 116  MDB_FTL_RETRY_DENY = 0x07FB,
 117  MDB_FTL_BLOCK = 0x07FC,
 118  MDB_FTL_OK_TO_SEND = 0x07FD,
 119  MDB_FTL_REQUEST_TO_SEND = 0x07FE,
 120  MDB_EXP_DIAG = 0x07FF,
 122  // numbering scheme is 1<command><subcommand>
 123  MDB_AV_RESET = 0x1000,
 124  MDB_AV_SETUP_CONFDATA = 0x1100,
 125  MDB_AV_IDENT = 0x1700,
 126  MDB_AV_SET_DATE_TIME = 0x1703,
 127  MDB_AV_EXP_DIAG = 0x17ff,
 128 };
 129 
 131 enum MDBClientCapabilities {
 132  MDB_CAP_REFUND = 0x01,
 133  MDB_CAP_MULTIVEND = 0x02,
 134  MDB_CAP_DISPLAY = 0x04,
 135  MDB_CAP_VENDCASHSALE = 0x08,
 136 };
 137 
 139 enum MDBFeatures {
 140  MDB_FEAT_FTL = 0x01,
 141  MDB_FEAT_EXPANDED_CURRENCY = 0x02,
 142  MDB_FEAT_MULTICUR = 0x04,
 143  MDB_FEAT_NEGVEND = 0x08,
 144  MDB_FEAT_DATAENTRY = 0x10,
 145  MDB_FEAT_SELECTIONFIRST = 0x20,
 146 };
 147 
 149 enum MDBState {
 150  MDB_STATE_NONE = 0,
 151  MDB_STATE_INACTIVE = 1,
 152  MDB_STATE_DISABLE = 2,
 153  MDB_STATE_ENABLE = 3,
 154  MDB_STATE_IDLE = 4,
 155  MDB_STATE_VEND = 5,
 156  MDB_STATE_REVALUE = 6,
 157  MDB_STATE_NEGATIVE_VEND = 7,
 158 };
 159 
 161 enum MDBCardOptions {
 162  MDB_CARD_DISPLAY = 0x00,
 163  MDB_CARD_NO_DISPLAY = 0x01,
 164  MDB_CARD_NO_REFUND = 0x00,
 165  MDB_CARD_REFUND = 0x02,
 166  MDB_CARD_NO_REVALUE = 0x00,
 167  MDB_CARD_REVALUE = 0x04,
 168 };
 169 
 170 #if 1
 171 
 172 class DllSpec MDB {
 173 #else
 174 class MDB {
 175 #endif
 176  public:
 177  class MDBPrivate;
 178 
 179  private:
 180  MDBPrivate *d; // PIMPL data pointer
 181 
 182  // prevent copying objects
 183  MDB(const MDB &o);
 184  void operator=(const MDB &o);
 185 
 186  public:
 187 
 196  static MDB &DefaultLink();
 197 
 199  MDB();
 200 
 202  virtual ~MDB();
 203 
 208  MDB_Error connect(const char *name=0);
 209 
 212  void disconnect();
 213 
 216  enum TraceType { SEND_HEADER,SEND_DATA,RECEIVE_HEADER,RECEIVE_DATA };
 217  typedef void (*TraceFunc)(void *data, TraceType dir, const void *buffer, unsigned size);
 218 
 224  void setTrace(TraceFunc t, void *data);
 225 
 226 
 230 
 241  MDB_Error start(MDBAddress address=MDB_CASHLESS_1, bool debug_port=false);
 242 
 246  MDB_Error stop(void);
 247 
 248 #if 0 // TODO: Check if we need this
 249 
 254  MDB_Error suspend(bool disabled);
 255 #endif
 256 
 263  int receive(void *cmd, size_t size);
 264 
 270  MDB_Error receive(std::vector<unsigned char> &cmd);
 271 
 278  int peek(void *cmd, size_t size);
 279 
 285  MDB_Error peek(std::vector<unsigned char> &cmd);
 286 
 295  MDB_Error send(const void *cmd, size_t cmdlen, int timeout=-1, int localAddr=-1);
 296 
 304  MDB_Error send(const std::vector<unsigned char> &cmd, int timeout=-1, int localAddr=-1)
 305  {
 306  return cmd.empty() ? MDBE_INVALID_PARAM : send(cmd.data(),cmd.size(),timeout,localAddr);
 307  }
 308 
 313  MDB_Error getPollTime(int &time);
 314 
 319  MDB_Error wakeVMC(bool wake);
 320 
 321 
 330  MDB_Error configProtocol(unsigned retry_cnt, unsigned interbyte_tout, unsigned response_tout);
 331 
 332 #if 0 // TODO: remove or implement
 333 
 337  MDB_Error setConfig(unsigned flags);
 338 
 343  MDB_Error getConfig(unsigned &flags);
 344 #endif
 345 
 360  static MDBCommand getCommand(const void *cmd, size_t cmdlen);
 361 
 366  static MDBCommand getCommand(const std::vector<unsigned char> &cmd);
 367 
 373  static int getAddress(const void *cmd, size_t cmdlen) {
 374  return cmd==0 || cmdlen==0 ? -1 : ((unsigned char *)cmd)[0] & 0xF8;
 375  }
 376 
 381  static int getAddress(const std::vector<unsigned char> &cmd) {
 382  return cmd.empty() ? -1 : cmd[0] & 0xF8;
 383  }
 384 
 388 
 389 
 398  static MDB_Error getSetupConfigData(const std::vector<unsigned char> &cmd, unsigned &level, unsigned &cols, unsigned &rows, unsigned &disptype);
 399 
 400 
 408  static MDB_Error getSetupPrice(const std::vector<unsigned char> &cmd, unsigned &maximum, unsigned &minimum, unsigned &currencyCode);
 409 
 410 
 417  static MDB_Error getVendRequest(const std::vector<unsigned char> &cmd, unsigned &amount, unsigned &item);
 418 
 424  static MDB_Error getVendSuccess(const std::vector<unsigned char> &cmd, unsigned &item);
 425 
 433  static MDB_Error getCashSale(const std::vector<unsigned char> &cmd, unsigned &amount, unsigned &item, unsigned &currency);
 434 
 441  static MDB_Error getNegativeVendRequest(const std::vector<unsigned char> &cmd, unsigned &amount, unsigned &item);
 442 
 448  static MDB_Error getDataEntry(const std::vector<unsigned char> &cmd, std::string &data);
 449 
 455  static MDB_Error getRevalueAmount(const std::vector<unsigned char> &cmd, unsigned &amount);
 456 
 465  static MDB_Error getRequestID(const std::vector<unsigned char> &cmd, std::string &manufCode, std::string &modelNumber, std::string &serialNumber, unsigned &softwareversion);
 466 
 474  static MDB_Error getDateTime(const std::vector<unsigned char> &cmd, std::string &datetime);
 475 
 481  static MDB_Error getFeatureOptions(const std::vector<unsigned char> &cmd, unsigned &options);
 482 
 492  static MDB_Error getFTLRequestToReceive(const std::vector<unsigned char> &cmd,
 493  unsigned char &remoteAddr, unsigned char &fileID,
 494  unsigned &maxBlocks, unsigned char &control,
 495  unsigned char &localAddr);
 496 
 505  static MDB_Error getFTLRetryDeny(const std::vector<unsigned char> &cmd,
 506  unsigned char &remoteAddr, unsigned char &retryDelay,
 507  unsigned char &localAddr);
 508 
 517  static MDB_Error getFTLBlock(const std::vector<unsigned char> &cmd,
 518  unsigned char &blockNo,
 519  unsigned char data[31], unsigned &len,
 520  unsigned char &localAddr);
 521 
 528  static MDB_Error getFTLOkToSend(const std::vector<unsigned char> &cmd,
 529  unsigned char &remoteAddr, unsigned char &localAddr);
 530 
 540  static MDB_Error getFTLRequestToSend(const std::vector<unsigned char> &cmd,
 541  unsigned char &remoteAddr, unsigned char &fileID,
 542  unsigned &maxBlocks, unsigned char &control,
 543  unsigned char &localAddr);
 544 
 550  static MDB_Error getDiagnostics(const std::vector<unsigned char> &cmd, std::vector<unsigned char> &diag);
 551 
 554 
 565  void setTimeout(int timeout_ms);
 566 
 572  MDB_Error sendJustReset(int localAddr=-1);
 573 
 590  MDB_Error sendConfigData(unsigned clientLevel,
 591  unsigned currencyCode, unsigned scaleFactor,
 592  unsigned decimalPlaces, unsigned maxResponseTime,
 593  unsigned capabilities, int battery,
 594  int localAddr=-1);
 595 
 603  MDB_Error sendDisplayText(const char *text, unsigned duration_ms, int localAddr=-1);
 604 
 610  MDB_Error sendClearDisplay(int localAddr=-1);
 611 
 628  MDB_Error sendBeginSession(unsigned amount,
 629  unsigned paymentMediaId, unsigned paymentType,
 630  unsigned paymentData, unsigned userLanguage,
 631  unsigned currencyCode, unsigned cardOptions,
 632  int localAddr=-1);
 633 
 640  MDB_Error sendCancelSession(int localAddr=-1);
 641 
 651  MDB_Error sendVendApproved(unsigned amount, int localAddr=-1);
 652 
 659  MDB_Error sendVendDenied(int localAddr=-1);
 660 
 668  MDB_Error sendEndSession(int localAddr=-1);
 669 
 675  MDB_Error sendCancelled(int localAddr=-1);
 676 
 687  MDB_Error sendPeripheralId(const char *manufCode, const char *modelNumber,
 688  const char* serialNumber,
 689  unsigned softwareVersion, unsigned optFeatures,
 690  int localAddr=-1);
 691 
 698  MDB_Error sendMalfunctionError(unsigned error, int localAddr=-1);
 699 
 707  MDB_Error sendOutOfSequence(enum MDBState state, int localAddr=-1);
 708 
 716  MDB_Error sendRevalueApproved(int localAddr=-1);
 717 
 724  MDB_Error sendRevalueDenied(int localAddr=-1);
 725 
 734  MDB_Error sendRevalueLimitAmount(unsigned amount, int localAddr=-1);
 735 
 741  MDB_Error sendDateTimeRequest(int localAddr=-1);
 742 
 752  MDB_Error sendSendDataEntryRequest(unsigned expectedLen, bool repeatedReq,
 753  const char *text, unsigned time,
 754  int localAddr=-1);
 755 
 761  MDB_Error sendDataEntryCancel(int localAddr=-1);
 762 
 774  MDB_Error sendFTLRequestToReceive(unsigned char remoteAddr, unsigned char fileID,
 775  unsigned maxBlocks, unsigned char control,
 776  int localAddr=-1);
 777 
 788  MDB_Error sendFTLRetryDeny(unsigned char remoteAddr, unsigned char retryDelay, int localAddr=-1);
 789 
 801  MDB_Error sendFTLBlock(unsigned char remoteAddr, unsigned char blockNo,
 802  const void *data, unsigned len,
 803  int localAddr=-1);
 804 
 813  MDB_Error sendFTLOkToSend(unsigned char remoteAddr, int localAddr=-1);
 814 
 826  MDB_Error sendFTLRequestToSend(unsigned char remoteAddr, unsigned char fileID,
 827  unsigned char blocks, unsigned char control,
 828  int localAddr=-1);
 829 
 837  MDB_Error sendDiagnosticResponse(const void *customData, size_t customData_len, int localAddr=-1);
 838 
 841 #if 0 // TODO: remove or implement
 842 
 848  MDB_Error setOptionalFeatures(unsigned optFeatures, int localAddr=-1);
 849 #endif
 850 
 851 #if 0 // TODO: remove or implement
 852 
 858  MDB_Error sendDravs(unsigned features, int localAddr=-1);
 859 #endif
 860 
 861 #if 0 // TODO: remove or implement
 862 
 866  MDB_Error hasWoken(void);
 867 #endif
 868 
 872 
 885  MDB_Error ftlSendData(unsigned char remoteAddr,
 886  unsigned char fileID,
 887  const std::vector<unsigned char> &data,
 888  int localAddr=-1);
 889 
 903  MDB_Error ftlReplyData(unsigned char remoteAddr,
 904  unsigned char fileID,
 905  const std::vector<unsigned char> &data,
 906  unsigned maxBlocks,
 907  unsigned char control,
 908  int localAddr=-1);
 909 
 922  MDB_Error ftlReceiveData(unsigned char remoteAddr,
 923  unsigned char fileID,
 924  std::vector<unsigned char> &data,
 925  unsigned maxBlocks,
 926  unsigned char control,
 927  int localAddr=-1);
 928 
 939  MDB_Error ftlRequestData(unsigned char remoteAddr,
 940  unsigned char fileID,
 941  std::vector<unsigned char> &data,
 942  unsigned timeout_ms,
 943  int localAddr=-1);
 945 };
 946 
 947 
 948 } // namespace
 949 
 950 extern "C" {
 951 #endif // __cplusplus
 952 
 953 
 954 // C interface - TODO
 955 
 956 
 957 #ifdef __cplusplus
 958 } // extern "C"
 959 #endif
 960 
 961 
 962 
 963 #undef DllSpec
 964 
 965 #endif
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/adk-5.0-programmers-guide/mdb_8h_source.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
