> 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/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8cpp.md).

# main.cpp

[Macros](#define-members) | [Functions](#func-members) | [Variables](#var-members)

`#include <stdio.h>` `#include <stdlib.h>` `#include <string.h>` `#include <map>` `#include <string>` `#include <sys/types.h>` `#include <sys/stat.h>` `#include <fcntl.h>` `#include <unistd.h>` `#include <signal.h>` `#include <dirent.h>` `#include <svcsec.h>` `#include "`[main.h](/adk-5.0-programmers-guide/main_8h_source.md)`"` `#include "`[madk\_pp\_protocol.h](/adk-5.0-programmers-guide/madk__pp__protocol_8h_source.md)`"` `#include "`[emv/E2E\_EMV\_CT\_Serialize.h](/adk-5.0-programmers-guide/_e2_e___e_m_v___c_t___serialize_8h_source.md)`"` `#include "`[emv/E2E\_EMV\_CTLS\_Serialize.h](/adk-5.0-programmers-guide/_e2_e___e_m_v___c_t_l_s___serialize_8h_source.md)`"` `#include "`[emv/EMV\_CT\_Link.h](/adk-5.0-programmers-guide/_e_m_v___c_t___link_8h_source.md)`"` `#include "`[emv/EMV\_CTLS\_Link.h](/adk-5.0-programmers-guide/_e_m_v___c_t_l_s___link_8h_source.md)`"` `#include "`[btlv\_helper.h](/adk-5.0-programmers-guide/btlv__helper_8h_source.md)`"` `#include "epp/counterTop.h"` `#include "epp/epp.h"` `#include "pthread.h"` `#include "emv.h"` `#include "emv_ctls.h"` `#include "card_dt.h"` `#include "cardranges.h"` `#include "`[sys.h](/adk-5.0-programmers-guide/sys_8h_source.md)`"` `#include "`[ped.h](/adk-5.0-programmers-guide/sdi_2src_2ped_8h_source.md)`"` `#include "`[disp.h](/adk-5.0-programmers-guide/disp_8h_source.md)`"` `#include "`[msr.h](/adk-5.0-programmers-guide/msr_8h_source.md)`"` `#include "`[crypt.h](/adk-5.0-programmers-guide/crypt_8h_source.md)`"` `#include "`[sysinfo/sysinfo.h](/adk-5.0-programmers-guide/sysinfo_8h_source.md)`"` `#include "`[sdi\_timer.h](/adk-5.0-programmers-guide/sdi__timer_8h_source.md)`"` `#include "`[ui\_mode.h](/adk-5.0-programmers-guide/ui__mode_8h_source.md)`"` `#include "data.h"` `#include "`[sec.h](/adk-5.0-programmers-guide/sec_8h_source.md)`"` `#include "`[nfc.h](/adk-5.0-programmers-guide/nfc_8h_source.md)`"` `#include "`[prt.h](/adk-5.0-programmers-guide/sdi_2src_2prt_8h_source.md)`"` `#include "`[vcl\_ser.h](/adk-5.0-programmers-guide/vcl__ser_8h_source.md)`"` `#include "vcl_client.h"` `#include "`[hexutil.h](/adk-5.0-programmers-guide/sdi_2src_2hexutil_8h_source.md)`"` `#include "`[\_logf.h](/adk-5.0-programmers-guide/__logf_8h_source.md)`"` `#include "version.h"` `#include "msr/msr.h"` `#include "`[tec/tec.h](/adk-5.0-programmers-guide/tec_8h_source.md)`"` `#include "`[ui.h](/adk-5.0-programmers-guide/ui_8h_source.md)`"` `#include "`[config.h](/adk-5.0-programmers-guide/config_8h_source.md)`"` `#include "config/sdi_sysconfig.h"` `#include "`[sdi\_tags.h](/adk-5.0-programmers-guide/src_2sdi__tags_8h_source.md)`"` `#include "`[loadplugin.h](/adk-5.0-programmers-guide/loadplugin_8h_source.md)`"` `#include "`[pthreadutil.h](/adk-5.0-programmers-guide/pthreadutil_8h_source.md)`"` `#include "`[filesystem.h](/adk-5.0-programmers-guide/filesystem_8h_source.md)`"` `#include "`[sec/libsec.h](/adk-5.0-programmers-guide/libsec_8h_source.md)`"` `#include "csd.h"` `#include "csd-version.h"` `#include "`[sdikeyservice.h](/adk-5.0-programmers-guide/sdikeyservice_8h_source.md)`"` `#include "`[tracefilter.h](/adk-5.0-programmers-guide/tracefilter_8h_source.md)`"` `#include "filterconfig.h"` `#include "emv_common.h"`

|         |                                                                                                              |
| ------- | ------------------------------------------------------------------------------------------------------------ |
| Macros  |                                                                                                              |
| #define | [SET\_RESULT](#ae27eea42be89a6e50555732afafcfb8f)(sw1, sw2)   { rsp\[0] = sw1; rsp\[1] = sw2; rspSize = 2; } |
| #define | [CHECK\_MAXSIZE](#a3d73028d6db233c7834cca0de7ab7792)(maxsize)                                                |

|                |                                                                                                                                    |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Functions      |                                                                                                                                    |
| void           | [sdi\_exit](#aeeb65deaf7e0b30961e4cb56c8105b41) (int status)                                                                       |
| bool           | [pm\_criticalSection](#a2640a9e85a15b5c3a3e800e532939c67) ()                                                                       |
| void           | [pm\_setCriticalSection](#a11c5a1b173cf19d42db73a73a1ad6d90) (bool enable)                                                         |
| void           | [checkLibraryVersion](#adc2d81ce0635e8bfeaae7cb9134309ec) ()                                                                       |
| unsigned short | [check\_mac\_decrypt](#a14410a47bc85fc785f5b90cfaaae8c4c) (unsigned char \*cmd, unsigned \&cmdSize, vector< unsigned char > \&out) |
| void           | [dispatch](#a9dbfee7a8a87cdb842e06759f4f2bb40) (vector< unsigned char > \&cmd)                                                     |
| bool           | [process\_side\_command](#a4892e1b795462119ef4d6fa87c860b90) (unsigned char \*cmd, unsigned size)                                  |
| int            | [main](#a0ddf1224851353fc92bfbff6f499fa97) (int argc, char \*argv\[])                                                              |

|                   |                                                              |
| ----------------- | ------------------------------------------------------------ |
| Variables         |                                                              |
| SDITrxData        | [sdiData](#aaaba1a94d121b39429bb3696a654492b)                |
| LibLogHandle      | [logHandle](#ab8518ee19337dc0debb1f831ada96dd6) = 0          |
| pthread\_mutex\_t | [g\_mutexEppSendReceive](#a8680a87737255cae9f7249240818f118) |

### MacroDefinition Documentation <a href="#macro-definition-documentation" id="macro-definition-documentation"></a>

### CHECK\_MAXSIZE <a href="#a3d73028d6db233c7834cca0de7ab7792" id="a3d73028d6db233c7834cca0de7ab7792"></a>

\#define CHECK\_MAXSIZE

**Value:**

```cpp
  if (size > maxsize) { \
   _LOGF_ERROR("%s(cmd=%p,size=%u): failed, max. message size %lu exceeded", __FUNCTION__, cmd, size, (unsigned long)maxsize); \
   rspSize = 2; \
   if (rsp.size() < rspSize)\
   rsp.resize(rspSize);\
   rsp[0] = 0x64; \
   rsp[1] = 0xFE; \
   break; }
```

### SET\_RESULT <a href="#ae27eea42be89a6e50555732afafcfb8f" id="ae27eea42be89a6e50555732afafcfb8f"></a>

\#define SET\_RESULT

### FunctionDocumentation <a href="#function-documentation" id="function-documentation"></a>

### check\_mac\_decrypt() <a href="#a14410a47bc85fc785f5b90cfaaae8c4c" id="a14410a47bc85fc785f5b90cfaaae8c4c"></a>

unsigned short check\_mac\_decrypt

see [main.h](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md) for details description

### checkLibraryVersion() <a href="#adc2d81ce0635e8bfeaae7cb9134309ec" id="adc2d81ce0635e8bfeaae7cb9134309ec"></a>

void checkLibraryVersion

### dispatch() <a href="#a9dbfee7a8a87cdb842e06759f4f2bb40" id="a9dbfee7a8a87cdb842e06759f4f2bb40"></a>

void dispatch

### main() <a href="#a0ddf1224851353fc92bfbff6f499fa97" id="a0ddf1224851353fc92bfbff6f499fa97"></a>

int main

#### Examples

[crdsync-demo.cpp](/adk-5.0-programmers-guide/readme/examples/crdsync-demo_8cpp-example.md#a1), [demo-sysinfo.cpp](/adk-5.0-programmers-guide/readme/examples/demo-sysinfo_8cpp-example.md#a4), [mac\_demo1.cpp](/adk-5.0-programmers-guide/readme/examples/mac_demo1_8cpp-example.md#a4), [mac\_demo2.cpp](/adk-5.0-programmers-guide/readme/examples/mac_demo2_8cpp-example.md#a4), [mac\_demo3.cpp](/adk-5.0-programmers-guide/readme/examples/mac_demo3_8cpp-example.md#a2), and [pm-demo.cpp](/adk-5.0-programmers-guide/readme/examples/pm-demo_8cpp-example.md#a9).

### pm\_criticalSection() <a href="#a2640a9e85a15b5c3a3e800e532939c67" id="a2640a9e85a15b5c3a3e800e532939c67"></a>

bool pm\_criticalSection

check if SDI has entered critical PM section with [pm\_setCriticalSection()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#a11c5a1b173cf19d42db73a73a1ad6d90).

#### Returns

true if SDI has entered critical PM section, else false.

### pm\_setCriticalSection() <a href="#a11c5a1b173cf19d42db73a73a1ad6d90" id="a11c5a1b173cf19d42db73a73a1ad6d90"></a>

void pm\_setCriticalSection

Enter/leave critical section of power management (PM). If true is passed for parameter *enable*, it invokes [sys\_CriticalSectionEnter()](/adk-5.0-programmers-guide/readme/modules/group___power/namespacevfisyspm.md#ac46060410ba78b557470d51eb9c90feb), in case of false [sys\_CriticalSectionExit()](/adk-5.0-programmers-guide/readme/modules/group___power/namespacevfisyspm.md#a1fe354c573d66613fbae37897509cf04) is called. For more details please refer to documentation of ADKPM.

**Parameters**

\[in] **enable** true to enter critical PM section false to leave critical PM section

### process\_side\_command() <a href="#a4892e1b795462119ef4d6fa87c860b90" id="a4892e1b795462119ef4d6fa87c860b90"></a>

bool process\_side\_command

Function to process a command as a side command, which was triggered by a side connection with protocol type 'C' asynchronously or by an asynchronous command with protocol type 'D'. The function is invoked by SDI connection thread (such as invoking [mADK\_PP\_Prot::set\_command()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#ab390ac45aaaa013d33bcef40d625f142)), thus, these threads are fully decoupled from SDI main thread processing (see function [dispatch()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#afdcd133c96d68afb81d874f88786367e)). Subfunctions invoked by [process\_side\_command()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#a4892e1b795462119ef4d6fa87c860b90) are invoked simultaneously, thus, they must be implemented thread-safe!!! If the command is not supported to be executed as a side command, the function returns false, which means that the command requires execution of [dispatch()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#afdcd133c96d68afb81d874f88786367e) with the SDI main thread. Side commands just have restricted access to SDI function scope and do not support intermediate messages like requests (callbacks) or aborts, they just use internal function [mADK\_PP\_Prot::send()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#a1f13b08d59a38adeb5d755179befa6b8) to reply the command. Therefore, side commands are usually short-term in nature.

{% hint style="info" %}
This function is not allowed to use protocol function like [mADK\_PP\_Prot::receive()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#ab2e55bafa77bcbdbeda4258ecadd5357), [mADK\_PP\_Prot::command()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#a345e47376ab38e76aa77b2bd774b104d), [mADK\_PP\_Prot::request()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#a1630f914c3dbf9ebc62ad6a5c7f9ebd9) or [mADK\_PP\_Prot::recv\_response()](/adk-5.0-programmers-guide/readme/annotated/classm_a_d_k___p_p___prot.md#a0bb666307a7aa15fc7aae63d454e4394). These APIs are only allowed for SDI application threads (main thread and siblings), which process commands received on the main connection (see function [dispatch()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#afdcd133c96d68afb81d874f88786367e)).
{% endhint %}

\*\*Parameters\*\*

\[in] **cmd** pointer to command buffer \[in] **size** size of command buffer

#### Returns

true if command was executed and rsp contains a response, false in case invocation is not allowed by a side command and requires execution of [dispatch()](/adk-5.0-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8h.md#afdcd133c96d68afb81d874f88786367e) with the SDI main thread.

### sdi\_exit() <a href="#aeeb65deaf7e0b30961e4cb56c8105b41" id="aeeb65deaf7e0b30961e4cb56c8105b41"></a>

void sdi\_exit

depending on platform SDI must call exit() or \_exit(). This function ensures to use the correct variant, therefore, it shall be used instead of using functions of stdlib directly.

**Parameters**

\[in] **status** exit code of SDI

### VariableDocumentation <a href="#variable-documentation" id="variable-documentation"></a>

### g\_mutexEppSendReceive <a href="#a8680a87737255cae9f7249240818f118" id="a8680a87737255cae9f7249240818f118"></a>

pthread\_mutex\_t g\_mutexEppSendReceive

### logHandle <a href="#ab8518ee19337dc0debb1f831ada96dd6" id="ab8518ee19337dc0debb1f831ada96dd6"></a>

LibLogHandle logHandle = 0

### sdiData <a href="#aaaba1a94d121b39429bb3696a654492b" id="aaaba1a94d121b39429bb3696a654492b"></a>

SDITrxData sdiData


---

# 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/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/main_8cpp.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.
