--- C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_without_long_range.c	Tue Feb 11 16:12:11 2020
+++ C:\ti\simplelink_cc2640r2_sdk_3_40_00_10\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral_SIMPLE.c	Wed Feb 12 13:02:31 2020
@@ -154,17 +154,6 @@
 // Size of string-converted device address ("0xXXXXXXXXXXXX")
 #define SP_ADDR_STR_SIZE     15
 
-// For storing the active connections
-#define SP_RSSI_TRACK_CHNLS        1            // Max possible channels can be GAP_BONDINGS_MAX
-#define SP_MAX_RSSI_STORE_DEPTH    5
-#define SP_INVALID_HANDLE          0xFFFF
-#define RSSI_2M_THRSHLD           -30
-#define RSSI_1M_THRSHLD           -40
-#define RSSI_S2_THRSHLD           -50
-#define RSSI_S8_THRSHLD           -60
-#define SP_PHY_NONE                LL_PHY_NONE  // No PHY set
-#define AUTO_PHY_UPDATE            0xFF
-
 // Spin if the expression is not true
 #define SIMPLEPERIPHERAL_ASSERT(expr) if (!(expr)) simple_peripheral_spin();
 
@@ -232,14 +221,6 @@
   uint16_t              connHandle;                        // Connection Handle
   spClockEventData_t*   pParamUpdateEventData;
   Clock_Struct*         pUpdateClock;                      // pointer to clock struct
-  int8_t                rssiArr[SP_MAX_RSSI_STORE_DEPTH];
-  uint8_t               rssiCntr;
-  int8_t                rssiAvg;
-  bool                  phyCngRq;                          // Set to true if PHY change request is in progress
-  uint8_t               currPhy;
-  uint8_t               rqPhy;
-  uint8_t               phyRqFailCnt;                      // PHY change request count
-  bool                  isAutoPHYEnable;                   // Flag to indicate auto phy change
 } spConnRec_t;
 
 /*********************************************************************
@@ -286,12 +267,6 @@
 
 // Per-handle connection info
 static spConnRec_t connList[MAX_NUM_BLE_CONNS];
-
-// Current connection handle as chosen by menu
-static uint16_t menuConnHandle = CONNHANDLE_INVALID;
-
-// List to store connection handles for set phy command status's
-static List_List setPhyCommStatList;
 
 // List to store connection handles for queued param updates
 static List_List paramUpdateList;
@@ -392,21 +367,11 @@
 static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData);
 static void SimplePeripheral_charValueChangeCB(uint8_t paramId);
 static status_t SimplePeripheral_enqueueMsg(uint8_t event, void *pData);
-static void SimplePeripheral_processCmdCompleteEvt(hciEvt_CmdComplete_t *pMsg);
-static void SimplePeripheral_initPHYRSSIArray(void);
-static void SimplePeripheral_updatePHYStat(uint16_t eventCode, uint8_t *pMsg);
 static uint8_t SimplePeripheral_addConn(uint16_t connHandle);
 static uint8_t SimplePeripheral_getConnIndex(uint16_t connHandle);
 static uint8_t SimplePeripheral_removeConn(uint16_t connHandle);
 static void SimplePeripheral_processParamUpdate(uint16_t connHandle);
-static status_t SimplePeripheral_startAutoPhyChange(uint16_t connHandle);
-static status_t SimplePeripheral_stopAutoPhyChange(uint16_t connHandle);
-static status_t SimplePeripheral_setPhy(uint16_t connHandle, uint8_t allPhys,
-                                        uint8_t txPhy, uint8_t rxPhy,
-                                        uint16_t phyOpts);
 static uint8_t SimplePeripheral_clearConnListEntry(uint16_t connHandle);
-static void SimplePeripheral_connEvtCB(Gap_ConnEventRpt_t *pReport);
-static void SimplePeripheral_processConnEvt(Gap_ConnEventRpt_t *pReport);
 #ifdef PTM_MODE
 void simple_peripheral_handleNPIRxInterceptEvent(uint8_t *pMsg);      // Declaration
 static void simple_peripheral_sendToNPI(uint8_t *buf, uint16_t len);  // Declaration
@@ -658,10 +623,6 @@
 
   //Initialize GAP layer for Peripheral role and register to receive GAP events
   GAP_DeviceInit(GAP_PROFILE_PERIPHERAL, selfEntity, addrMode, NULL);
-
-  // Initialize array to store connection handle and RSSI values
-  SimplePeripheral_initPHYRSSIArray();
-
 }
 
 /*********************************************************************
@@ -767,48 +728,10 @@
       // Process HCI message
       switch(pMsg->status)
       {
-        case HCI_COMMAND_COMPLETE_EVENT_CODE:
-        // Process HCI Command Complete Events here
-        {
-          SimplePeripheral_processCmdCompleteEvt((hciEvt_CmdComplete_t *) pMsg);
-          break;
-        }
 
         case HCI_BLE_HARDWARE_ERROR_EVENT_CODE:
           AssertHandler(HAL_ASSERT_CAUSE_HARDWARE_ERROR,0);
           break;
-
-        // HCI Commands Events
-        case HCI_COMMAND_STATUS_EVENT_CODE:
-        {
-          hciEvt_CommandStatus_t *pMyMsg = (hciEvt_CommandStatus_t *)pMsg;
-          switch ( pMyMsg->cmdOpcode )
-          {
-            case HCI_LE_SET_PHY:
-            {
-              SimplePeripheral_updatePHYStat(HCI_LE_SET_PHY, (uint8_t *)pMsg);
-              break;
-            }
-
-            default:
-              break;
-          }
-          break;
-        }
-
-        // LE Events
-        case HCI_LE_EVENT_CODE:
-        {
-          hciEvt_BLEPhyUpdateComplete_t *pPUC =
-            (hciEvt_BLEPhyUpdateComplete_t*) pMsg;
-
-          // A Phy Update Has Completed or Failed
-          if (pPUC->BLEEventCode == HCI_BLE_PHY_UPDATE_COMPLETE_EVENT)
-          {
-            SimplePeripheral_updatePHYStat(HCI_BLE_PHY_UPDATE_COMPLETE_EVENT, (uint8_t *)pMsg);
-          }
-          break;
-        }
 
         default:
           break;
@@ -932,10 +855,6 @@
       dealloc = FALSE;
       break;
     }
-
-    case SP_CONN_EVT:
-      SimplePeripheral_processConnEvt((Gap_ConnEventRpt_t *)(pMsg->pData));
-      break;
 
     default:
       // Do nothing.
@@ -1045,7 +964,7 @@
 
       if (pPkt->hdr.status == SUCCESS)
       {
-        // Add connection to list and start RSSI
+        // Add connection to list
         SimplePeripheral_addConn(pPkt->connectionHandle);
 
         // Start Periodic Clock.
@@ -1067,7 +986,7 @@
 
       uint8_t numActive = linkDB_NumActive();
 
-      // Remove the connection from the list and disable RSSI if needed
+      // Remove the connection from the list
       SimplePeripheral_removeConn(pPkt->connectionHandle);
 
       // If no active connections
@@ -1283,56 +1202,6 @@
 }
 
 /*********************************************************************
- * @fn      SimplePeripheral_doSetConnPhy
- *
- * @brief   Set PHY preference.
- *
- * @param   index - 0: 1M PHY
- *                  1: 2M PHY
- *                  2: 1M + 2M PHY
- *                  3: CODED PHY (Long range)
- *                  4: 1M + 2M + CODED PHY
- *
- * @return  always true
- */
-bool SimplePeripheral_doSetConnPhy(uint8 index)
-{
-  bool status = TRUE;
-
-  static uint8_t phy[] = {
-    HCI_PHY_1_MBPS, HCI_PHY_2_MBPS, HCI_PHY_1_MBPS | HCI_PHY_2_MBPS,
-    HCI_PHY_CODED, HCI_PHY_1_MBPS | HCI_PHY_2_MBPS | HCI_PHY_CODED,
-    AUTO_PHY_UPDATE
-  };
-
-  uint8_t connIndex = SimplePeripheral_getConnIndex(menuConnHandle);
-  if (connIndex >= MAX_NUM_BLE_CONNS)
-  {
-    return FALSE;
-  }
-
-
-  // Set Phy Preference on the current connection. Apply the same value
-  // for RX and TX.
-  // If auto PHY update is not selected and if auto PHY update is enabled, then
-  // stop auto PHY update
-  // Note PHYs are already enabled by default in build_config.opt in stack project.
-  if(phy[index] != AUTO_PHY_UPDATE)
-  {
-    // Cancel RSSI reading  and auto phy changing
-    SimplePeripheral_stopAutoPhyChange(connList[connIndex].connHandle);
-
-    SimplePeripheral_setPhy(menuConnHandle, 0, phy[index], phy[index], 0);
-  }
-  else
-  {
-    // Start RSSI read for auto PHY update (if it is disabled)
-    SimplePeripheral_startAutoPhyChange(menuConnHandle);
-  }
-
-  return status;
-}
-/*********************************************************************
  * @fn      SimplePeripheral_advCallback
  *
  * @brief   GapAdv module callback
@@ -1505,48 +1374,6 @@
                          B_APP_DEFAULT_PASSCODE);
 #endif
 }
-
-/*********************************************************************
- * @fn      SimplePeripheral_connEvtCB
- *
- * @brief   Connection event callback.
- *
- * @param pReport pointer to connection event report
- */
-static void SimplePeripheral_connEvtCB(Gap_ConnEventRpt_t *pReport)
-{
-  // Enqueue the event for processing in the app context.
-  if(SimplePeripheral_enqueueMsg(SP_CONN_EVT, pReport) != SUCCESS)
-  {
-    ICall_free(pReport);
-  }
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_processConnEvt
- *
- * @brief   Process connection event.
- *
- * @param pReport pointer to connection event report
- */
-static void SimplePeripheral_processConnEvt(Gap_ConnEventRpt_t *pReport)
-{
-  // Get index from handle
-  uint8_t connIndex = SimplePeripheral_getConnIndex(pReport->handle);
-
-  if (connIndex >= MAX_NUM_BLE_CONNS)
-  {
-    return;
-  }
-
-  // If auto phy change is enabled
-  if (connList[connIndex].isAutoPHYEnable == TRUE)
-  {
-    // Read the RSSI
-    HCI_ReadRssiCmd(pReport->handle);
-  }
-}
-
 
 /*********************************************************************
  * @fn      SimplePeripheral_enqueueMsg
@@ -1640,9 +1467,6 @@
         status = bleMemAllocError;
       }
 
-      // Set default PHY to 1M
-      connList[i].currPhy = HCI_PHY_1_MBPS;
-
       break;
     }
   }
@@ -1703,14 +1527,6 @@
     if((connIndex == i) || (connHandle == CONNHANDLE_ALL))
     {
       connList[i].connHandle = CONNHANDLE_INVALID;
-      connList[i].currPhy = 0;
-      connList[i].phyCngRq = 0;
-      connList[i].phyRqFailCnt = 0;
-      connList[i].rqPhy = 0;
-      memset(connList[i].rssiArr, 0, SP_MAX_RSSI_STORE_DEPTH);
-      connList[i].rssiAvg = 0;
-      connList[i].rssiCntr = 0;
-      connList[i].isAutoPHYEnable = FALSE;
     }
   }
 
@@ -1773,8 +1589,6 @@
     }
     // Clear pending update requests from paramUpdateList
     SimplePeripheral_clearPendingParamUpdate(connHandle);
-    // Stop Auto PHY Change
-    SimplePeripheral_stopAutoPhyChange(connHandle);
     // Clear Connection List Entry
     SimplePeripheral_clearConnListEntry(connHandle);
   }
@@ -1833,325 +1647,6 @@
       List_put(&paramUpdateList, (List_Elem *)connHandleEntry);
     }
   }
-}
-
-/*********************************************************************
- * @fn      SimpleCentral_processCmdCompleteEvt
- *
- * @brief   Process an incoming OSAL HCI Command Complete Event.
- *
- * @param   pMsg - message to process
- *
- * @return  none
- */
-static void SimplePeripheral_processCmdCompleteEvt(hciEvt_CmdComplete_t *pMsg)
-{
-  uint8_t status = pMsg->pReturnParam[0];
-
-  //Find which command this command complete is for
-  switch (pMsg->cmdOpcode)
-  {
-    case HCI_READ_RSSI:
-    {
-      int8 rssi = (int8)pMsg->pReturnParam[3];  
-
-      // Display RSSI value, if RSSI is higher than threshold, change to faster PHY
-      if (status == SUCCESS)
-      {
-        uint16_t handle = BUILD_UINT16(pMsg->pReturnParam[1], pMsg->pReturnParam[2]);
-
-        uint8_t index = SimplePeripheral_getConnIndex(handle);
-        SIMPLEPERIPHERAL_ASSERT(index < MAX_NUM_BLE_CONNS);
-
-        if (rssi != LL_RSSI_NOT_AVAILABLE)
-        {
-          connList[index].rssiArr[connList[index].rssiCntr++] = rssi;
-          connList[index].rssiCntr %= SP_MAX_RSSI_STORE_DEPTH;
-
-          int16_t sum_rssi = 0;
-          for(uint8_t cnt=0; cnt<SP_MAX_RSSI_STORE_DEPTH; cnt++)
-          {
-            sum_rssi += connList[index].rssiArr[cnt];
-          }
-          connList[index].rssiAvg = (uint32_t)(sum_rssi/SP_MAX_RSSI_STORE_DEPTH);
-
-          uint8_t phyRq = SP_PHY_NONE;
-          uint8_t phyRqS = SP_PHY_NONE;
-          uint8_t phyOpt = LL_PHY_OPT_NONE;
-
-          if(connList[index].phyCngRq == FALSE)
-          {
-            if((connList[index].rssiAvg >= RSSI_2M_THRSHLD) &&
-            (connList[index].currPhy != HCI_PHY_2_MBPS) &&
-                 (connList[index].currPhy != SP_PHY_NONE))
-            {
-              // try to go to higher data rate
-              phyRqS = phyRq = HCI_PHY_2_MBPS;
-            }
-            else if((connList[index].rssiAvg < RSSI_2M_THRSHLD) &&
-                    (connList[index].rssiAvg >= RSSI_1M_THRSHLD) &&
-                    (connList[index].currPhy != HCI_PHY_1_MBPS) &&
-                    (connList[index].currPhy != SP_PHY_NONE))
-            {
-              // try to go to legacy regular data rate
-              phyRqS = phyRq = HCI_PHY_1_MBPS;
-            }
-            else if((connList[index].rssiAvg >= RSSI_S2_THRSHLD) &&
-                    (connList[index].rssiAvg < RSSI_1M_THRSHLD) &&
-                    (connList[index].currPhy != SP_PHY_NONE))
-            {
-              // try to go to lower data rate S=2(500kb/s)
-              phyRqS = HCI_PHY_CODED;
-              phyOpt = LL_PHY_OPT_S2;
-              phyRq = BLE5_CODED_S2_PHY;
-            }
-            else if(connList[index].rssiAvg < RSSI_S2_THRSHLD )
-            {
-              // try to go to lowest data rate S=8(125kb/s)
-              phyRqS = HCI_PHY_CODED;
-              phyOpt = LL_PHY_OPT_S8;
-              phyRq = BLE5_CODED_S8_PHY;
-            }
-            if((phyRq != SP_PHY_NONE) &&
-               // First check if the request for this phy change is already not honored then don't request for change
-               (((connList[index].rqPhy == phyRq) &&
-                 (connList[index].phyRqFailCnt < 2)) ||
-                 (connList[index].rqPhy != phyRq)))
-            {
-              //Initiate PHY change based on RSSI
-              SimplePeripheral_setPhy(connList[index].connHandle, 0,
-                                      phyRqS, phyRqS, phyOpt);
-              connList[index].phyCngRq = TRUE;
-
-              // If it a request for different phy than failed request, reset the count
-              if(connList[index].rqPhy != phyRq)
-              {
-                // then reset the request phy counter and requested phy
-                connList[index].phyRqFailCnt = 0;
-              }
-
-              if(phyOpt == LL_PHY_OPT_NONE)
-              {
-                connList[index].rqPhy = phyRq;
-              }
-              else if(phyOpt == LL_PHY_OPT_S2)
-              {
-                connList[index].rqPhy = BLE5_CODED_S2_PHY;
-              }
-              else
-              {
-                connList[index].rqPhy = BLE5_CODED_S8_PHY;
-              }
-
-            } // end of if ((phyRq != SP_PHY_NONE) && ...
-          } // end of if (connList[index].phyCngRq == FALSE)
-        } // end of if (rssi != LL_RSSI_NOT_AVAILABLE)
-
-    } // end of if (status == SUCCESS)
-      break;
-    }
-
-    case HCI_LE_READ_PHY:
-    {
-      break;
-    }
-
-    default:
-      break;
-  } // end of switch (pMsg->cmdOpcode)
-}
-
-/*********************************************************************
-* @fn      SimplePeripheral_initPHYRSSIArray
-*
-* @brief   Initializes the array of structure/s to store data related
-*          RSSI based auto PHy change
-*
-* @param   connHandle - the connection handle
-*
-* @param   addr - pointer to device address
-*
-* @return  index of connection handle
-*/
-static void SimplePeripheral_initPHYRSSIArray(void)
-{
-  //Initialize array to store connection handle and RSSI values
-  memset(connList, 0, sizeof(connList));
-  for (uint8_t index = 0; index < MAX_NUM_BLE_CONNS; index++)
-  {
-    connList[index].connHandle = SP_INVALID_HANDLE;
-  }
-}
-/*********************************************************************
-      // Set default PHY to 1M
- * @fn      SimplePeripheral_startAutoPhyChange
- *
- * @brief   Start periodic RSSI reads on a link.
- *
- * @param   connHandle - connection handle of link
- * @param   devAddr - device address
- *
- * @return  SUCCESS: Terminate started
- *          bleIncorrectMode: No link
- *          bleNoResources: No resources
- */
-static status_t SimplePeripheral_startAutoPhyChange(uint16_t connHandle)
-{
-  status_t status = FAILURE;
-
-  // Get connection index from handle
-  uint8_t connIndex = SimplePeripheral_getConnIndex(connHandle);
-  SIMPLEPERIPHERAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS);
-
-  // Start Connection Event notice for RSSI calculation
-  status = Gap_RegisterConnEventCb(SimplePeripheral_connEvtCB, GAP_CB_REGISTER, connHandle);
-
-  // Flag in connection info if successful
-  if (status == SUCCESS)
-  {
-    connList[connIndex].isAutoPHYEnable = TRUE;
-  }
-
-  return status;
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_stopAutoPhyChange
- *
- * @brief   Cancel periodic RSSI reads on a link.
- *
- * @param   connHandle - connection handle of link
- *
- * @return  SUCCESS: Operation successful
- *          bleIncorrectMode: No link
- */
-static status_t SimplePeripheral_stopAutoPhyChange(uint16_t connHandle)
-{
-  // Get connection index from handle
-  uint8_t connIndex = SimplePeripheral_getConnIndex(connHandle);
-  SIMPLEPERIPHERAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS);
-
-  // Stop connection event notice
-  Gap_RegisterConnEventCb(NULL, GAP_CB_UNREGISTER, connHandle);
-
-  // Also update the phychange request status for active RSSI tracking connection
-  connList[connIndex].phyCngRq = FALSE;
-  connList[connIndex].isAutoPHYEnable = FALSE;
-
-  return SUCCESS;
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_setPhy
- *
- * @brief   Call the HCI set phy API and and add the handle to a
- *          list to match it to an incoming command status event
- */
-static status_t SimplePeripheral_setPhy(uint16_t connHandle, uint8_t allPhys,
-                                        uint8_t txPhy, uint8_t rxPhy,
-                                        uint16_t phyOpts)
-{
-  // Allocate list entry to store handle for command status
-  spConnHandleEntry_t *connHandleEntry = ICall_malloc(sizeof(spConnHandleEntry_t));
-
-  if (connHandleEntry)
-  {
-    connHandleEntry->connHandle = connHandle;
-
-    // Add entry to the phy command status list
-    List_put(&setPhyCommStatList, (List_Elem *)connHandleEntry);
-
-    // Send PHY Update
-    HCI_LE_SetPhyCmd(connHandle, allPhys, txPhy, rxPhy, phyOpts);
-  }
-
-  return SUCCESS;
-}
-
-/*********************************************************************
-* @fn      SimplePeripheral_updatePHYStat
-*
-* @brief   Update the auto phy update state machine
-*
-* @param   connHandle - the connection handle
-*
-* @return  None
-*/
-static void SimplePeripheral_updatePHYStat(uint16_t eventCode, uint8_t *pMsg)
-{
-  uint8_t connIndex;
-
-  switch (eventCode)
-  {
-    case HCI_LE_SET_PHY:
-    {
-      // Get connection handle from list
-      spConnHandleEntry_t *connHandleEntry =
-                           (spConnHandleEntry_t *)List_get(&setPhyCommStatList);
-
-      if (connHandleEntry)
-      {
-        // Get index from connection handle
-        connIndex = SimplePeripheral_getConnIndex(connHandleEntry->connHandle);
-
-        ICall_free(connHandleEntry);
-
-        // Is this connection still valid?
-        if (connIndex < MAX_NUM_BLE_CONNS)
-        {
-          hciEvt_CommandStatus_t *pMyMsg = (hciEvt_CommandStatus_t *)pMsg;
-
-          if (pMyMsg->cmdStatus == HCI_ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE)
-          {
-            // Update the phychange request status for active RSSI tracking connection
-            connList[connIndex].phyCngRq = FALSE;
-            connList[connIndex].phyRqFailCnt++;
-          }
-        }
-      }
-      break;
-    }
-
-    // LE Event - a Phy update has completed or failed
-    case HCI_BLE_PHY_UPDATE_COMPLETE_EVENT:
-    {
-      hciEvt_BLEPhyUpdateComplete_t *pPUC =
-                                     (hciEvt_BLEPhyUpdateComplete_t*) pMsg;
-
-      if(pPUC)
-      {
-        // Get index from connection handle
-        connIndex = SimplePeripheral_getConnIndex(pPUC->connHandle);
-
-        // Is this connection still valid?
-        if (connIndex < MAX_NUM_BLE_CONNS)
-        {
-          // Update the phychange request status for active RSSI tracking connection
-          connList[connIndex].phyCngRq = FALSE;
-
-          if (pPUC->status == SUCCESS)
-          {
-            connList[connIndex].currPhy = pPUC->rxPhy;
-          }
-          if(pPUC->rxPhy != connList[connIndex].rqPhy)
-          {
-            connList[connIndex].phyRqFailCnt++;
-          }
-          else
-          {
-            // Reset the request phy counter and requested phy
-            connList[connIndex].phyRqFailCnt = 0;
-            connList[connIndex].rqPhy = 0;
-          }
-        }
-      }
-
-      break;
-    }
-
-    default:
-      break;
-  } // end of switch (eventCode)
 }
 
 #ifdef PTM_MODE
