@@ -54,6 +54,10 @@
 #include "simple_np_uuid.h"
 // #include "devinfoservice.h"
 
+// This is to drive the green led only
+#include <ti/drivers/GPIO.h>
+#include "ti_drivers_config.h"
+
 /*******************************************************************************
  * CONSTANTS
  */
@@ -195,6 +199,105 @@ CONST gattServiceCBs_t SNP_CBs =
   NULL              // Authorization callback function pointer
 };
 
+
+/*********************************************************************
+ * PROFILES and SERVICES for Non-HomeKit (NHK) connections
+ */
+// Simple Profile Service UUID
+#define SIMPLEPROFILE_SERV_UUID             0xFFF0
+#define SIMPLEPROFILE_SERVICE               0x00000001
+#define SIMPLEPROFILE_CHAR1_UUID            0xFFF1
+
+/*********************************************************************
+ * EXTERN VARIABLES for Non-HomeKit (NHK) connections
+ */
+extern bool activeConnectionIsNHK;
+
+/*********************************************************************
+ * LOCAL VARIABLES for Non-HomeKit (NHK) connections
+ */
+// Simple GATT Profile Service UUID: 0xFFF0
+CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
+{
+  LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID)
+};
+
+// Characteristic 1 UUID: 0xFFF1
+CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
+{
+  LO_UINT16(SIMPLEPROFILE_CHAR1_UUID), HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
+};
+
+// Simple Profile Service attribute
+static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
+
+// Simple Profile Characteristic 1 Properties
+static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;
+
+// Characteristic 1 Value
+static uint8 simpleProfileChar1 = 1; // simpleProfileChar1 value will determine the state of the green led
+                                     // simpleProfileChar1 = 1, 3, 5,... > led is off
+                                     // simpleProfileChar1 = 2, 4, 6,... > led is on
+                                     // LED will initially be switched off
+
+// Simple Profile Characteristic 1 User Description
+static uint8 simpleProfileChar1UserDesp[17] = "Characteristic 1";
+
+// Simple Profile Attributes Table
+static gattAttribute_t simpleProfileAttrTbl[4] =
+{
+  // Simple Profile Service
+  {
+    { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
+    GATT_PERMIT_READ,                         /* permissions */
+    0,                                        /* handle */
+    (uint8 *)&simpleProfileService            /* pValue */
+  },
+
+    // Characteristic 1 Declaration
+    {
+      { ATT_BT_UUID_SIZE, characterUUID },
+      GATT_PERMIT_READ,
+      0,
+      &simpleProfileChar1Props
+    },
+
+      // Characteristic Value 1
+      {
+        { ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
+        GATT_PERMIT_READ | GATT_PERMIT_WRITE,
+        0,
+        &simpleProfileChar1
+      },
+
+      // Characteristic 1 User Description
+      {
+        { ATT_BT_UUID_SIZE, charUserDescUUID },
+        GATT_PERMIT_READ,
+        0,
+        simpleProfileChar1UserDesp
+      }
+};
+
+/*********************************************************************
+ * LOCAL FUNCTIONS for Non-HomeKit (NHK) connections
+ */
+static bStatus_t NHK_AddServices(uint32 services);
+static bStatus_t NHK_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue,
+                                           uint16_t len, uint16_t offset, uint8_t method);
+static bStatus_t NHK_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue,
+                                          uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method);
+
+/*********************************************************************
+ * PROFILE CALLBACKS for Non-HomeKit (NHK) connections
+ */
+CONST gattServiceCBs_t simpleProfileCBs =
+{
+  NHK_ReadAttrCB,  // Read callback function pointer
+  NHK_WriteAttrCB, // Write callback function pointer
+  NULL             // Authorization callback function pointer
+};
+
 /*********************************************************************
  * PUBLIC FUNCTIONS
  */
@@ -260,6 +363,9 @@ void SNP_initGATT(void)
   GATTServApp_AddService(GATT_ALL_SERVICES);   // GATT attributes
   // DevInfo_AddService();                        // Device Information Service
 
+  // Non-HK services
+  NHK_AddServices(GATT_ALL_SERVICES);
+
   // Reset GATT session, hard-coded to 0 for first init.
   SNP_resetGATT(0);
 }
@@ -2466,6 +2572,181 @@ uint8_t SNP_sendNotifInd(snpNotifIndReq_t *pReq, int16_t length)
 }
 
 
+/*********************************************************************
+ * STATIC FUNCTIONS for Non-HomeKit (NHK) connections
+ */
+
+/*********************************************************************
+ * @fn          NHK_ReadAttrCB
+ *
+ * @brief       Read an attribute.
+ *
+ * @param       connHandle - connection message was received on
+ * @param       pAttr - pointer to attribute
+ * @param       pValue - pointer to data to be read
+ * @param       pLen - length of data to be read
+ * @param       offset - offset of the first octet to be read
+ * @param       maxLen - maximum length of data to be read
+ * @param       method - type of read message
+ *
+ * @return      SUCCESS, blePending or Failure
+ */
+static bStatus_t NHK_ReadAttrCB(uint16_t connHandle,
+                                gattAttribute_t *pAttr,
+                                uint8_t *pValue, uint16_t *pLen,
+                                uint16_t offset, uint16_t maxLen,
+                                uint8_t method)
+{
+  bStatus_t status = SUCCESS;
+
+  // Make sure it's not a blob operation (no attributes in the profile are long)
+  if ( offset > 0 )
+  {
+    return ( ATT_ERR_ATTR_NOT_LONG );
+  }
+
+  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
+  {
+    // 16-bit UUID
+    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
+    switch ( uuid )
+    {
+
+      // characteristic 1 has read permission
+      case SIMPLEPROFILE_CHAR1_UUID:
+        *pLen = 1;
+        pValue[0] = *pAttr->pValue;
+        break;
+
+      default:
+        // Should never get here! (characteristics 3 and 4 do not have read permissions)
+        *pLen = 0;
+        status = ATT_ERR_ATTR_NOT_FOUND;
+        break;
+    }
+  }
+  else
+  {
+    // 128-bit UUID
+    *pLen = 0;
+    status = ATT_ERR_INVALID_HANDLE;
+  }
+
+  return ( status );
+}
+
+/*********************************************************************
+ * @fn      NHK_WriteAttrCB
+ *
+ * @brief   Validate attribute data prior to a write operation
+ *
+ * @param   connHandle - connection message was received on
+ * @param   pAttr - pointer to attribute
+ * @param   pValue - pointer to data to be written
+ * @param   len - length of data
+ * @param   offset - offset of the first octet to be written
+ * @param   method - type of write message
+ *
+ * @return  SUCCESS, blePending or Failure
+ */
+static bStatus_t NHK_WriteAttrCB(uint16_t connHandle,
+                                 gattAttribute_t *pAttr,
+                                 uint8_t *pValue, uint16_t len,
+                                 uint16_t offset, uint8_t method)
+{
+  bStatus_t status = SUCCESS;
+
+  if ( pAttr->type.len == ATT_BT_UUID_SIZE )
+  {
+    // 16-bit UUID
+    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
+    switch ( uuid )
+    {
+      case SIMPLEPROFILE_CHAR1_UUID:
+
+        //Validate the value
+        // Make sure it's not a blob oper
+        if ( offset == 0 )
+        {
+          if ( len != 1 )
+          {
+            status = ATT_ERR_INVALID_VALUE_SIZE;
+          }
+        }
+        else
+        {
+          status = ATT_ERR_ATTR_NOT_LONG;
+        }
+
+        //Write the value
+        if ( status == SUCCESS )
+        {
+            if(activeConnectionIsNHK == true){
+
+                // The connection has the right to be used to update this char
+                uint8 *pCurValue = (uint8 *)pAttr->pValue;
+                *pCurValue = pValue[0];
+
+                // Here we only use the value transmitted to turn on or off the green LED
+                if(pValue[0] % 2 != 1){
+                    GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_ON);
+                }
+                else{
+                    GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF);
+                }
+
+
+            }
+        }
+
+        break;
+
+
+      default:
+        // Should never get here! (characteristics 2 and 4 do not have write permissions)
+        status = ATT_ERR_ATTR_NOT_FOUND;
+        break;
+    }
+  }
+  else
+  {
+    // 128-bit UUID
+    status = ATT_ERR_INVALID_HANDLE;
+  }
+
+  return ( status );
+}
+
+/*********************************************************************
+ * @fn      NHK_AddServices
+ *
+ * @brief   Initializes the Simple Profile service by registering
+ *          GATT attributes with the GATT server.
+ *
+ * @param   services - services to add. This is a bit map and can
+ *                     contain more than one service.
+ *
+ * @return  Success or Failure
+ */
+static bStatus_t NHK_AddServices( uint32 services )
+{
+  uint8 status;
+
+  if ( services & SIMPLEPROFILE_SERVICE )
+  {
+    // Register GATT attribute list and CBs with GATT Server App
+    status = GATTServApp_RegisterService( simpleProfileAttrTbl,
+                                          GATT_NUM_ATTRS( simpleProfileAttrTbl ),
+                                          GATT_MAX_ENCRYPT_KEY_SIZE,
+                                          &simpleProfileCBs );
+  }
+  else
+  {
+    status = SUCCESS;
+  }
+
+  return ( status );
+}
 
 /*********************************************************************
 *********************************************************************/
