Add audio gain set API.

Change-Id: I7dadc9310f1aa880a05dfe057621d753bdbb940c
diff --git a/mbtk/mbtk_lib/src/mbtk_audio.c b/mbtk/mbtk_lib/src/mbtk_audio.c
index 6e54fc9..ff58fe9 100755
--- a/mbtk/mbtk_lib/src/mbtk_audio.c
+++ b/mbtk/mbtk_lib/src/mbtk_audio.c
@@ -42,6 +42,7 @@
 #define AUDIO_UBUS_DSP_SET          	"config_dspgain"
 #define AUDIO_UBUS_LOOPBACK_EN          "loopback_enable"
 #define AUDIO_UBUS_LOOPBACK_DIS         "loopback_disable"
+#define AUDIO_UBUS_AUDIO_GAIN_SET       "audio_gain_set"
 
 // #define DEBUG 1
 
@@ -890,6 +891,64 @@
     }
 }
 
+// TX : 0-10; RX : 11
+#define MBTK_AUDIO_GAIN_NUM 12
+void mbtk_audio_ubus_gain_set(uint8 *gain, int gain_num)
+{
+    int rc = 0;
+    struct ubus_request *req = NULL;
+
+    req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
+    if (req == NULL)
+    {
+        printf("leave %s: lack of memory\n", __FUNCTION__);
+        return;
+    }
+    if(gain_num != MBTK_AUDIO_GAIN_NUM) {
+        printf("gain_num error.\n");
+        return;
+    }
+    memset(req, 0, sizeof(struct ubus_request));
+    blob_buf_init(&audio_cm_b, 0);
+
+    char name[20];
+    int i = 0;
+    // Set TX
+    for(; i < gain_num - 1; i++) {
+        memset(name, 0x0, 20);
+        sprintf(name, "volume_gain_%d", i);
+        blobmsg_add_u8(&audio_cm_b, name, gain[i]);
+    }
+
+    // Set RX
+    blobmsg_add_u8(&audio_cm_b, "volume_gain_rx", gain[i]);
+
+#if 1
+    if ((rc = ubus_invoke_async(mbtk_audio_ubus_db->ctx, mbtk_audio_ubus_db->audioif_request_id, AUDIO_UBUS_AUDIO_GAIN_SET, audio_cm_b.head, req)) != UBUS_STATUS_OK)
+    {
+        free(req);
+        printf("%s, ubus_invoke_async volume set failed: %s\n", __FUNCTION__,  ubus_strerror(rc));
+    }
+    else
+    {
+        printf("%s: ubus_invoke_async success\n", __FUNCTION__);
+        req->complete_cb = mbtk_ubus_complete_cb;
+        ubus_complete_request_async(mbtk_audio_ubus_db->ctx, req);
+    }
+#else
+    if ((rc = ubus_invoke(APP_ctx, APP_audio_request_id, AUDIO_UBUS_AUDIO_GAIN_SET, audio_cm_b.head, NULL, 0, 0)) != UBUS_STATUS_OK)
+    {
+        printf("%s, ubus_invoke_async volume set failed: %s\n", __FUNCTION__, ubus_strerror(rc));
+    }
+    else
+    {
+        printf("%s: ubus_invoke_async success\n", __FUNCTION__);
+    }
+    free(req);
+#endif
+}
+
+
 static void audio_volume_get_data_cb (struct ubus_request *req, int type, struct blob_attr *msg)
 {
     UNUSEDPARAM(req);