diff --git a/epicardium/ble/app/common/app_db.c b/epicardium/ble/app/common/app_db.c
index e4428f50751fd4407b3397c7111381314fd5ff45..775a59f10a980af3dce9407f5080d17b727cf7d5 100644
--- a/epicardium/ble/app/common/app_db.c
+++ b/epicardium/ble/app/common/app_db.c
@@ -24,7 +24,6 @@
  */
 /* clang-format off */
 /* clang-formet turned off for easier diffing against orginal file */
-#include <string.h>
 #include "wsf_types.h"
 #include "wsf_assert.h"
 #include "util/bda.h"
@@ -33,6 +32,10 @@
 #include "app_db.h"
 #include "app_cfg.h"
 
+#include "epicardium.h"
+#include <string.h>
+#include <stdio.h>
+
 /**************************************************************************************************
   Data Types
 **************************************************************************************************/
@@ -96,7 +99,31 @@ static appDbRec_t *pAppDbNewRec = appDb.rec;
 /*************************************************************************************************/
 void AppDbInit(void)
 {
-  return;
+  //return;
+  int fd = epic_file_open("pairings.bin", "r");
+
+  if(fd >= 0) {
+    printf("open ok\n");
+    if(epic_file_read(fd, &appDb, sizeof(appDb)) != sizeof(appDb)) {
+        printf("read fail\n");
+        memset(&appDb, 0, sizeof(appDb));
+    }
+    epic_file_close(fd);
+  }
+}
+
+static void store(void)
+{
+  //return;
+  printf("store\n");
+  int fd = epic_file_open("pairings.bin", "w");
+  if(fd >= 0) {
+    printf("open ok\n");
+    if(epic_file_write(fd, &appDb, sizeof(appDb)) != sizeof(appDb)) {
+        printf("write fail\n");
+    }
+    epic_file_close(fd);
+  }
 }
 
 /*************************************************************************************************/
@@ -111,6 +138,7 @@ void AppDbInit(void)
 /*************************************************************************************************/
 appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
 {
+  printf("AppDbNewRecord(%d, )\n");
   appDbRec_t  *pRec = appDb.rec;
   uint8_t     i;
 
@@ -145,6 +173,7 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
   pRec->peerAddedToRl = FALSE;
   pRec->peerRpao = FALSE;
 
+  store();
   return (appDbHdl_t) pRec;
 }
 
@@ -160,6 +189,7 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
 /*************************************************************************************************/
 appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl)
 {
+  printf("================================AppDbGetNextRecord\n");
   appDbRec_t  *pRec;
 
   /* if first record is requested */
@@ -209,6 +239,7 @@ appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl)
 void AppDbDeleteRecord(appDbHdl_t hdl)
 {
   ((appDbRec_t *) hdl)->inUse = FALSE;
+  store();
 }
 
 /*************************************************************************************************/
@@ -226,6 +257,7 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask)
 {
   ((appDbRec_t *) hdl)->valid = TRUE;
   ((appDbRec_t *) hdl)->keyValidMask = keyMask;
+  store();
 }
 
 /*************************************************************************************************/
@@ -315,6 +347,7 @@ void AppDbDeleteAllRecords(void)
   {
     pRec->inUse = FALSE;
   }
+  store();
 }
 
 /*************************************************************************************************/
@@ -461,6 +494,7 @@ void AppDbSetKey(appDbHdl_t hdl, dmSecKeyIndEvt_t *pKey)
     default:
       break;
   }
+  store();
 }
 
 /*************************************************************************************************/
@@ -493,6 +527,7 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value)
   WSF_ASSERT(idx < APP_DB_NUM_CCCD);
 
   ((appDbRec_t *) hdl)->cccTbl[idx] = value;
+  store();
 }
 
 /*************************************************************************************************/
@@ -522,6 +557,7 @@ uint8_t AppDbGetDiscStatus(appDbHdl_t hdl)
 void AppDbSetDiscStatus(appDbHdl_t hdl, uint8_t status)
 {
   ((appDbRec_t *) hdl)->discStatus = status;
+  store();
 }
 
 /*************************************************************************************************/
@@ -550,7 +586,9 @@ uint16_t *AppDbGetHdlList(appDbHdl_t hdl)
 /*************************************************************************************************/
 void AppDbSetHdlList(appDbHdl_t hdl, uint16_t *pHdlList)
 {
+  printf("================================AppDbSetHdlList\n");
   memcpy(((appDbRec_t *) hdl)->hdlList, pHdlList, sizeof(((appDbRec_t *) hdl)->hdlList));
+  store();
 }
 
 /*************************************************************************************************/
@@ -593,6 +631,7 @@ void AppDbSetDevName(uint8_t len, char *pStr)
   len = (len <= sizeof(appDb.devName)) ? len : sizeof(appDb.devName);
 
   memcpy(appDb.devName, pStr, len);
+  store();
 }
 
 /*************************************************************************************************/
@@ -622,6 +661,7 @@ bool_t AppDbGetPeerAddrRes(appDbHdl_t hdl)
 void AppDbSetPeerAddrRes(appDbHdl_t hdl, uint8_t addrRes)
 {
   ((appDbRec_t *)hdl)->peerAddrRes = addrRes;
+  store();
 }
 
 /*************************************************************************************************/
@@ -651,6 +691,7 @@ uint32_t AppDbGetPeerSignCounter(appDbHdl_t hdl)
 void AppDbSetPeerSignCounter(appDbHdl_t hdl, uint32_t signCounter)
 {
   ((appDbRec_t *)hdl)->peerSignCounter = signCounter;
+  store();
 }
 
 /*************************************************************************************************/
@@ -680,6 +721,7 @@ bool_t AppDbGetPeerAddedToRl(appDbHdl_t hdl)
 void AppDbSetPeerAddedToRl(appDbHdl_t hdl, bool_t peerAddedToRl)
 {
   ((appDbRec_t *)hdl)->peerAddedToRl = peerAddedToRl;
+  store();
 }
 
 /*************************************************************************************************/
@@ -709,5 +751,6 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl)
 void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao)
 {
   ((appDbRec_t *)hdl)->peerRpao = peerRpao;
+  store();
 }
 /* clang-format on */
diff --git a/epicardium/ble/app/common/app_ui.c b/epicardium/ble/app/common/app_ui.c
index 089e9dbbe615dc3787fec1a03712985b91537050..64d494fbffe962ec5f261366da662a221582d89c 100644
--- a/epicardium/ble/app/common/app_ui.c
+++ b/epicardium/ble/app/common/app_ui.c
@@ -21,6 +21,7 @@
 #include "wsf_os.h"
 #include "wsf_trace.h"
 #include "app_ui.h"
+#include "stdio.h"
 
 /* card10:
  * copied from: lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/common/app_ui.c
@@ -176,6 +177,7 @@ void AppUiAction(uint8_t event)
 void AppUiDisplayPasskey(uint32_t passkey)
 {
   APP_TRACE_INFO1(">>> Passkey: %d <<<", passkey);
+  printf("foo bar=======================\n");
 }
 
 /*************************************************************************************************/
@@ -190,6 +192,7 @@ void AppUiDisplayPasskey(uint32_t passkey)
 void AppUiDisplayConfirmValue(uint32_t confirm)
 {
   APP_TRACE_INFO1(">>> Confirm Value: %d <<<", confirm);
+  printf("foo=======================\n");
 }
 
 /*************************************************************************************************/
diff --git a/epicardium/ble/ble.c b/epicardium/ble/ble.c
index 9a2da1942627e02ca57bbdf518464c59ec3e37b4..83faf565ed91682ca0ae708f013ac4c1a96d7071 100644
--- a/epicardium/ble/ble.c
+++ b/epicardium/ble/ble.c
@@ -158,6 +158,10 @@ static void scheduleTimer(void)
 	vTimerCallback(NULL);
 	time_to_next_expire = WsfTimerNextExpiration(&timerRunning);
 
+    if(time_to_next_expire == 0 ) {
+        time_to_next_expire = 1;
+    }
+
 	if (timerRunning) {
 		//printf("time_to_next_expire = %d\n", time_to_next_expire);
 		//printf("change period\n");
diff --git a/epicardium/ble/ble_main.c b/epicardium/ble/ble_main.c
index 4c0971e7b4964781f473b6d0ba1e461f3fd99561..7715f3ecdb9ea88210fd774a435e31bb487cedc8 100644
--- a/epicardium/ble/ble_main.c
+++ b/epicardium/ble/ble_main.c
@@ -69,7 +69,7 @@ typedef union
 /*! configurable parameters for advertising */
 static const appAdvCfg_t bleAdvCfg =
 {
-  {60000,     0,     0},                  /*! Advertising durations in ms */
+  {00000,     0,     0},                  /*! Advertising durations in ms */
   {500/0.625,     4000/0.625,     0}                   /*! Advertising intervals in 0.625 ms units */
 };
 
@@ -113,11 +113,11 @@ static const basCfg_t bleBasCfg =
 static const smpCfg_t bleSmpCfg =
 {
   3000,                                   /*! 'Repeated attempts' timeout in msec */
-  SMP_IO_NO_IN_NO_OUT,                    /*! I/O Capability */
+  SMP_IO_DISP_YES_NO,                     /*! I/O Capability */
   7,                                      /*! Minimum encryption key length */
   16,                                     /*! Maximum encryption key length */
   3,                                      /*! Attempts to trigger 'repeated attempts' timeout */
-  0,                                      /*! Device authentication requirements */
+  DM_AUTH_MITM_FLAG,                      /*! Device authentication requirements */
 };
 
 /**************************************************************************************************
@@ -151,7 +151,7 @@ static const uint8_t bleScanDataDisc[] =
   /*! device name */
   7,                                      /*! length */
   DM_ADV_TYPE_LOCAL_NAME,                 /*! AD type */
-  'c','a','r','d','1','0'
+  'c','a','R','d','1','0'
 };
 
 /**************************************************************************************************
@@ -399,6 +399,7 @@ static void bleProcMsg(bleMsg_t *pMsg)
       break;
 
     case DM_SEC_ECC_KEY_IND:
+      printf("DM_SEC_ECC_KEY_IND\n");
       DmSecSetEccKey(&pMsg->dm.eccMsg.data.key);
       break;
 
diff --git a/epicardium/ble/uart.c b/epicardium/ble/uart.c
index d902e3426f1adb4a5e92538beb897a2e2bcc2ef5..415dbb34aee28643b0b81a48db4bde90ab607752 100644
--- a/epicardium/ble/uart.c
+++ b/epicardium/ble/uart.c
@@ -33,6 +33,7 @@ enum { UART_SVC_HDL = UART_START_HDL, /*!< \brief UART service declaration */
 static const uint8_t UARTSvc[] = {0x9E,0xCA,0xDC,0x24,0x0E,0xE5,0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x01,0x00,0x40,0x6E};
 
 static const uint8_t uartRxCh[] = {ATT_PROP_WRITE, UINT16_TO_BYTES(UART_RX_HDL), 0x9E,0xCA,0xDC,0x24,0x0E,0xE5,0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x02,0x00,0x40,0x6E};
+//static const uint8_t uartRxCh[] = {ATT_PROP_AUTHENTICATED, UINT16_TO_BYTES(UART_RX_HDL), 0x9E,0xCA,0xDC,0x24,0x0E,0xE5,0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x02,0x00,0x40,0x6E};
 const uint8_t attUartRxChUuid[] = {0x9E,0xCA,0xDC,0x24,0x0E,0xE5, 0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x02,0x00,0x40,0x6E};
 
 static const uint8_t uartTxCh[] = {ATT_PROP_READ | ATT_PROP_NOTIFY, UINT16_TO_BYTES(UART_TX_HDL), 0x9E,0xCA,0xDC,0x24,0x0E,0xE5,0xA9,0xE0,0x93,0xF3,0xA3,0xB5,0x03,0x00,0x40,0x6E};
@@ -60,7 +61,8 @@ static void *SvcUARTAddGroupDyn(void)
 		/* UART rx value */
 		// XXX: not sure if max value of 128 is fine...
 		AttsDynAddAttr( pSHdl, attUartRxChUuid, NULL, 0, 128,
-			ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN, ATTS_PERMIT_WRITE);
+			ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN,
+            ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | ATTS_PERMIT_WRITE_AUTH);
 
 		/* UART tx characteristic */
 		AttsDynAddAttrConst( pSHdl, attChUuid, uartTxCh, sizeof(uartTxCh),
diff --git a/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/dm/dm_adv_leg.c b/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/dm/dm_adv_leg.c
index ae45fc603b70c60ce72d85220c24abf3538992ec..25af8e12f60750e018c3819b34910527f0fca7af 100644
--- a/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/dm/dm_adv_leg.c
+++ b/lib/sdk/Libraries/BTLE/stack/ble-host/sources/stack/dm/dm_adv_leg.c
@@ -169,15 +169,18 @@ void dmAdvActStart(dmAdvMsg_t *pMsg)
 
    if (dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT] == DM_ADV_STATE_IDLE)
   {
+  printf("AAA\n");
     /* if doing directed advertising ignore the request */
     if ((dmAdvCb.advType[DM_ADV_HANDLE_DEFAULT] == DM_ADV_CONN_DIRECT) ||
         (dmAdvCb.advType[DM_ADV_HANDLE_DEFAULT] == DM_ADV_CONN_DIRECT_LO_DUTY))
     {
+  printf("BBB\n");
       DM_TRACE_WARN0("dmAdvActStart during directed advertising!");
       return;
     }
 
     /* start advertising */
+    printf("AA\n");
     dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT] = DM_ADV_STATE_STARTING;
     dmAdvCb.advDuration[DM_ADV_HANDLE_DEFAULT] = pMsg->apiStart.duration[DM_ADV_HANDLE_DEFAULT];
     HciLeSetAdvEnableCmd(TRUE);
@@ -327,21 +330,27 @@ void dmAdvHciHandler(hciEvt_t *pEvent)
     switch (dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT])
     {
     case DM_ADV_STATE_STARTING:
+    printf("DM_ADV_STATE_STARTING and NOT ");
     case DM_ADV_STATE_STARTING_DIRECTED:
+    printf("DM_ADV_STATE_STARTING_DIRECTED\n");
       if (pEvent->hdr.status == HCI_SUCCESS)
       {
+      printf("A\n");
         if (dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT] == DM_ADV_STATE_STARTING)
         {
+      printf("B\n");
           /* start advertising timer if applicable */
           if (dmAdvCb.advDuration[DM_ADV_HANDLE_DEFAULT] > 0)
           {
             dmAdvCb.advTimer.msg.event = DM_ADV_MSG_TIMEOUT;
+            printf("start advertising timer %u\n", dmAdvCb.advDuration[DM_ADV_HANDLE_DEFAULT]);
             WsfTimerStartMs(&dmAdvCb.advTimer, dmAdvCb.advDuration[DM_ADV_HANDLE_DEFAULT]);
           }
 
           /* Application callbacks only sent in undirected state */
           if (dmLegAdvCb.advType != DM_ADV_CONN_DIRECT_LO_DUTY)
           {
+      printf("C\n");
             cbackEvent = DM_ADV_START_IND;
           }
         }
@@ -355,6 +364,7 @@ void dmAdvHciHandler(hciEvt_t *pEvent)
       }
       else
       {
+      printf("D\n");
         dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT] = DM_ADV_STATE_IDLE;
       }
       break;
@@ -422,6 +432,7 @@ void dmAdvHciHandler(hciEvt_t *pEvent)
 /*************************************************************************************************/
 void dmAdvMsgHandler(wsfMsgHdr_t *pMsg)
 {
+  printf("dmAdvMsgHandler %d\n", DM_MSG_MASK(pMsg->event));
   /* execute action function */
   (*dmAdvAct[DM_MSG_MASK(pMsg->event)])((dmAdvMsg_t *)pMsg);
 }
@@ -449,6 +460,7 @@ void dmAdvStartDirected(uint8_t advType, uint16_t duration, uint8_t addrType, ui
     HciLeSetAdvEnableCmd(TRUE);
 
     /* store advertising info */
+    printf("BB\n");
     dmAdvCb.advState[DM_ADV_HANDLE_DEFAULT] = (advType == DM_ADV_CONN_DIRECT) ? \
                                               DM_ADV_STATE_STARTING_DIRECTED : DM_ADV_STATE_STARTING;
 
diff --git a/lib/sdk/Libraries/BTLE/stack/platform/max32665/wsf_os.c b/lib/sdk/Libraries/BTLE/stack/platform/max32665/wsf_os.c
index 62012a7d4bb84a58ac72aff1bd1eff0c3047ff8b..09ae691d3df84237620165f268751e7971a02eec 100644
--- a/lib/sdk/Libraries/BTLE/stack/platform/max32665/wsf_os.c
+++ b/lib/sdk/Libraries/BTLE/stack/platform/max32665/wsf_os.c
@@ -255,6 +255,7 @@ void wsfOsDispatcher(void)
     /* handle msg queue */
     while ((pMsg = WsfMsgDeq(&pTask->msgQueue, &handlerId)) != NULL)
     {
+      //printf("q\n");
       WSF_ASSERT(handlerId < WSF_MAX_HANDLERS);
       WSF_OS_SET_ACTIVE_HANDLER_ID(handlerId);
       (*pTask->handler[handlerId])(0, pMsg);
@@ -267,6 +268,7 @@ void wsfOsDispatcher(void)
     /* service timers */
     while ((pTimer = WsfTimerServiceExpired(0)) != NULL)
     {
+      //printf("t\n");
       WSF_ASSERT(pTimer->handlerId < WSF_MAX_HANDLERS);
       WSF_OS_SET_ACTIVE_HANDLER_ID(pTimer->handlerId);
       (*pTask->handler[pTimer->handlerId])(0, &pTimer->msg);
@@ -280,6 +282,7 @@ void wsfOsDispatcher(void)
     {
       if ((pTask->handlerEventMask[i] != 0) && (pTask->handler[i] != NULL))
       {
+        //printf("h\n");
         WSF_CS_ENTER(cs);
         eventMask = pTask->handlerEventMask[i];
         pTask->handlerEventMask[i] = 0;