[Feature] add GA346 baseline version

Change-Id: Ic62933698569507dcf98240cdf5d9931ae34348f
diff --git a/src/apps/atom-base/progs/property/libprop/prop_api.c b/src/apps/atom-base/progs/property/libprop/prop_api.c
new file mode 100644
index 0000000..7fa2b08
--- /dev/null
+++ b/src/apps/atom-base/progs/property/libprop/prop_api.c
@@ -0,0 +1,182 @@
+/* Copyright Statement:
+
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+ * the prior written permission of MediaTek inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of MediaTek Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+
+ * MediaTek Inc. (C) 2015. All rights reserved.
+
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
+ * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+ * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cutils/properties.h"
+#include "request.h"
+#include "prop_debug.h"
+
+/*******************************************************************************/
+/* LIBSNCFG functions for Android Property Mechanism                           */
+/*******************************************************************************/
+int _property_check(const char *key, const char *value)
+{
+    if (key == 0) {
+		 PROP_DEBUG_PRINT(PROP_DEBUG_ERROR, "[PropSet] key==0 return directly\n");
+		 return -1;
+	}
+
+    if (strlen(key) >= PROPERTY_KEY_MAX) {
+		PROP_DEBUG_PRINT(PROP_DEBUG_ERROR, "[PropSet] key=%s size:%zd >= max:%d\n",
+				                            key, strlen(key), PROPERTY_KEY_MAX);
+		 return -1;
+	}
+
+    if (strlen(value) >= PROPERTY_VALUE_MAX) {
+		PROP_DEBUG_PRINT(PROP_DEBUG_ERROR, "[PropSet] value=%s size:%zd >= max:%d\n",
+				                            value, strlen(value), PROPERTY_VALUE_MAX);
+		return -1;
+	}
+	
+    return  0;
+}
+
+int property_get(const char *key, char *value, const char *default_value)
+{
+	struct  sncfg_request request;
+    int     ret_len = 1;
+
+    /*check validaty*/
+    if ((key == 0) || (value == 0)) {
+		 PROP_DEBUG_PRINT(PROP_DEBUG_ERROR, "[PropSet] key==0 return directly\n");
+		 return -1;
+	}
+
+	if (strlen(key) >= PROPERTY_KEY_MAX) {
+		PROP_DEBUG_PRINT(PROP_DEBUG_ERROR, "[PropSet] key=%s size:%zd >= max:%d\n",
+											key, strlen(key), PROPERTY_KEY_MAX);
+		 return -1;
+	}
+
+    /*send socket to get the value*/
+	bzero(&request, sizeof(struct sncfg_request));
+	request.magic = SNCFG_REQUEST_MAGIC;
+	request.type = SNCFG_REQUEST_TYPE_PROP_GET;
+	request.key = (char *)key;
+	if (request_for_sncfg(&request) < 0) {
+        ret_len = 0;        
+	} else if (NULL == request.value) {
+        ret_len = 0;
+    }
+
+    /*
+    *  1. normal case: use db's value.
+    *  2. other case: use default value.
+    */
+    if (ret_len>0) {
+        ret_len = strlen(request.value);
+        if (ret_len >= PROPERTY_VALUE_MAX)  {
+            ret_len = PROPERTY_VALUE_MAX - 1;
+        }
+        strncpy(value, request.value, ret_len);
+        value[ret_len] = '\0';
+    } else {
+        if (default_value) {
+            ret_len = strlen(default_value);
+            if (ret_len >= PROPERTY_VALUE_MAX) {
+                ret_len = PROPERTY_VALUE_MAX - 1;
+            }
+            memcpy(value, default_value, ret_len);
+            value[ret_len] = '\0';
+        } else {
+            value[0] = '\0';
+        }
+    }
+
+	return  ret_len;	
+}
+
+int property_set(const char *key, const char *in_value)
+{
+	struct 	sncfg_request request;
+	char	*value = "";
+
+	if (in_value != NULL)
+		value = in_value;
+	
+    if (_property_check(key, value) < 0) {
+        return  -1;
+    }
+
+	bzero(&request, sizeof(struct sncfg_request));
+	request.magic = SNCFG_REQUEST_MAGIC;
+	request.type = SNCFG_REQUEST_TYPE_PROP_SET;
+	request.key = (char *)key;
+	request.value = (char *)value;
+	if (request_for_sncfg(&request) < 0) {
+		return -1;
+	}
+	
+	return 0;
+}
+
+int property_reload(void)
+{
+	struct sncfg_request request;
+	
+	bzero(&request, sizeof(struct sncfg_request));
+	
+	request.magic = SNCFG_REQUEST_MAGIC;
+	request.type = SNCFG_REQUEST_TYPE_PROP_RELOAD;	
+	if (request_for_sncfg(&request) < 0) {
+		return -1;
+	}
+	
+	return 0;		
+}
+
+int property_debug(char *key, char *in_value)
+{
+	struct sncfg_request request;
+	char	*value = "";
+
+	if (in_value != NULL)
+		value = in_value;
+
+    if (_property_check(key, value) < 0) {
+        return  -1;
+    }
+    
+	bzero(&request, sizeof(struct sncfg_request));
+	request.magic = SNCFG_REQUEST_MAGIC;
+	request.type = SNCFG_REQUEST_TYPE_PROP_DEBUG;
+	request.key = key;
+	request.value = value;
+	if (request_for_sncfg(&request) < 0) {
+		return -1;
+	}
+
+	return 0;	
+}